mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 09:59:41 +02:00
Put main loop painting code in separate methods
Also declare the relevant variables with a reduced scope, where possible.
This commit is contained in:
parent
f8dc4c7bb8
commit
cbe7735f73
138
src/gmenu2x.cpp
138
src/gmenu2x.cpp
@ -231,6 +231,7 @@ GMenu2X::GMenu2X()
|
||||
bg = NULL;
|
||||
font = NULL;
|
||||
menu = NULL;
|
||||
btnContextMenu = nullptr;
|
||||
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
||||
initMenu();
|
||||
|
||||
@ -277,6 +278,7 @@ GMenu2X::~GMenu2X() {
|
||||
quit();
|
||||
|
||||
delete menu;
|
||||
delete btnContextMenu;
|
||||
delete font;
|
||||
delete monitor;
|
||||
}
|
||||
@ -388,6 +390,10 @@ void GMenu2X::initMenu() {
|
||||
menu->setSectionIndex(confInt["section"]);
|
||||
menu->setLinkIndex(confInt["link"]);
|
||||
|
||||
btnContextMenu = new IconButton(this, ts, "skin:imgs/menu.png");
|
||||
btnContextMenu->setPosition(resX - 38, bottomBarIconY);
|
||||
btnContextMenu->setAction(BIND(&GMenu2X::contextMenu));
|
||||
|
||||
menu->loadIcons();
|
||||
|
||||
//DEBUG
|
||||
@ -593,44 +599,13 @@ void GMenu2X::writeTmp(int selelem, const string &selectordir) {
|
||||
}
|
||||
}
|
||||
|
||||
void GMenu2X::main() {
|
||||
uint linksPerPage = linkColumns*linkRows;
|
||||
int linkSpacingX = (resX-10 - linkColumns*skinConfInt["linkWidth"])/linkColumns;
|
||||
int linkSpacingY = (resY-35 - skinConfInt["topBarHeight"] - linkRows*skinConfInt["linkHeight"])/linkRows;
|
||||
uint sectionLinkPadding = (skinConfInt["topBarHeight"] - 32 - font->getHeight()) / 3;
|
||||
|
||||
bool quit = false;
|
||||
int x,y;
|
||||
int helpBoxHeight = 154;
|
||||
uint i;
|
||||
long tickBattery = -60000, tickNow;
|
||||
string batteryIcon = "imgs/battery/0.png";
|
||||
stringstream ss;
|
||||
uint sectionsCoordX = 24;
|
||||
SDL_Rect re = {0,0,0,0};
|
||||
bool helpDisplayed = false;
|
||||
#ifdef WITH_DEBUG
|
||||
//framerate
|
||||
long tickFPS = SDL_GetTicks();
|
||||
int drawn_frames = 0;
|
||||
string fps = "";
|
||||
#endif
|
||||
|
||||
IconButton btnContextMenu(this, ts, "skin:imgs/menu.png");
|
||||
btnContextMenu.setPosition(resX-38, bottomBarIconY);
|
||||
btnContextMenu.setAction(BIND(&GMenu2X::contextMenu));
|
||||
|
||||
if (!fileExists(CARD_ROOT))
|
||||
CARD_ROOT = "";
|
||||
|
||||
while (!quit) {
|
||||
tickNow = SDL_GetTicks();
|
||||
|
||||
void GMenu2X::paint() {
|
||||
//Background
|
||||
sc["bgmain"]->blit(s,0,0);
|
||||
|
||||
//Sections
|
||||
sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2;
|
||||
uint sectionLinkPadding = (skinConfInt["topBarHeight"] - 32 - font->getHeight()) / 3;
|
||||
uint sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2;
|
||||
if (menu->firstDispSection()>0)
|
||||
sc.skinRes("imgs/l_enabled.png")->blit(s,0,0);
|
||||
else
|
||||
@ -639,9 +614,9 @@ void GMenu2X::main() {
|
||||
sc.skinRes("imgs/r_enabled.png")->blit(s,resX-10,0);
|
||||
else
|
||||
sc.skinRes("imgs/r_disabled.png")->blit(s,resX-10,0);
|
||||
for (i=menu->firstDispSection(); i<menu->getSections().size() && i<menu->firstDispSection()+linkColumns; i++) {
|
||||
for (uint i = menu->firstDispSection(); i < menu->getSections().size() && i < menu->firstDispSection() + linkColumns; i++) {
|
||||
string sectionIcon = "skin:sections/"+menu->getSections()[i]+".png";
|
||||
x = (i-menu->firstDispSection())*skinConfInt["linkWidth"]+sectionsCoordX;
|
||||
int x = (i-menu->firstDispSection())*skinConfInt["linkWidth"]+sectionsCoordX;
|
||||
if (menu->selSectionIndex()==(int)i)
|
||||
s->box(x, 0, skinConfInt["linkWidth"],
|
||||
skinConfInt["topBarHeight"], skinConfColors[COLOR_SELECTION_BG]);
|
||||
@ -654,10 +629,13 @@ void GMenu2X::main() {
|
||||
}
|
||||
|
||||
//Links
|
||||
for (i=menu->firstDispRow()*linkColumns; i<(menu->firstDispRow()*linkColumns)+linksPerPage && i<menu->sectionLinks()->size(); i++) {
|
||||
uint linksPerPage = linkColumns * linkRows;
|
||||
int linkSpacingX = (resX-10 - linkColumns*skinConfInt["linkWidth"])/linkColumns;
|
||||
int linkSpacingY = (resY-35 - skinConfInt["topBarHeight"] - linkRows*skinConfInt["linkHeight"])/linkRows;
|
||||
for (uint i = menu->firstDispRow() * linkColumns; i < menu->firstDispRow() * linkColumns + linksPerPage && i < menu->sectionLinks()->size(); i++) {
|
||||
int ir = i-menu->firstDispRow()*linkColumns;
|
||||
x = (ir%linkColumns)*(skinConfInt["linkWidth"]+linkSpacingX)+6;
|
||||
y = ir/linkColumns*(skinConfInt["linkHeight"]+linkSpacingY)+skinConfInt["topBarHeight"]+2;
|
||||
int x = (ir%linkColumns)*(skinConfInt["linkWidth"]+linkSpacingX)+6;
|
||||
int y = ir/linkColumns*(skinConfInt["linkHeight"]+linkSpacingY)+skinConfInt["topBarHeight"]+2;
|
||||
menu->sectionLinks()->at(i)->setPosition(x,y);
|
||||
|
||||
if (i == (uint)menu->selLinkIndex())
|
||||
@ -682,30 +660,20 @@ void GMenu2X::main() {
|
||||
}
|
||||
|
||||
if (ts.available()) {
|
||||
btnContextMenu.paint();
|
||||
}
|
||||
//check battery status every 60 seconds
|
||||
if (tickNow-tickBattery >= 60000) {
|
||||
tickBattery = tickNow;
|
||||
unsigned short battlevel = getBatteryLevel();
|
||||
if (battlevel>5) {
|
||||
batteryIcon = "imgs/battery/ac.png";
|
||||
} else {
|
||||
ss.clear();
|
||||
ss << battlevel;
|
||||
ss >> batteryIcon;
|
||||
batteryIcon = "imgs/battery/"+batteryIcon+".png";
|
||||
}
|
||||
btnContextMenu->paint();
|
||||
}
|
||||
|
||||
sc.skinRes(batteryIcon)->blit( s, resX-19, bottomBarIconY );
|
||||
//s->write( font, tr[batstr.c_str()], 20, 170 );
|
||||
//On Screen Help
|
||||
|
||||
s->write(font, Clock::getInstance()->getTime(),
|
||||
halfX, bottomBarTextY,
|
||||
Font::HAlignCenter, Font::VAlignMiddle);
|
||||
}
|
||||
|
||||
if (helpDisplayed) {
|
||||
void GMenu2X::paintHelp() {
|
||||
//On Screen Help
|
||||
int helpBoxHeight = 154;
|
||||
s->box(10,50,300,helpBoxHeight+4, skinConfColors[COLOR_MESSAGE_BOX_BG]);
|
||||
s->rectangle( 12,52,296,helpBoxHeight,
|
||||
skinConfColors[COLOR_MESSAGE_BOX_BORDER] );
|
||||
@ -717,36 +685,57 @@ void GMenu2X::main() {
|
||||
s->write( font, tr["SELECT: Show contextual menu"], 20, 155 );
|
||||
s->write( font, tr["START: Show options menu"], 20, 170 );
|
||||
#endif
|
||||
}
|
||||
|
||||
void GMenu2X::main() {
|
||||
|
||||
batteryIcon = "imgs/battery/0.png";
|
||||
long tickBattery = -60000;
|
||||
|
||||
if (!fileExists(CARD_ROOT))
|
||||
CARD_ROOT = "";
|
||||
|
||||
bool helpDisplayed = false;
|
||||
|
||||
bool quit = false;
|
||||
while (!quit) {
|
||||
//check battery status every 60 seconds
|
||||
long tickNow = SDL_GetTicks();
|
||||
if (tickNow - tickBattery >= 60000) {
|
||||
tickBattery = tickNow;
|
||||
unsigned short battlevel = getBatteryLevel();
|
||||
if (battlevel>5) {
|
||||
batteryIcon = "imgs/battery/ac.png";
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss << "imgs/battery/" << battlevel << ".png";
|
||||
ss >> batteryIcon;
|
||||
}
|
||||
}
|
||||
|
||||
paint();
|
||||
if (helpDisplayed) {
|
||||
paintHelp();
|
||||
s->flip();
|
||||
while (input.waitForPressedButton() != InputManager::CANCEL) {}
|
||||
helpDisplayed=false;
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef WITH_DEBUG
|
||||
//framerate
|
||||
drawn_frames++;
|
||||
if (tickNow-tickFPS>=1000) {
|
||||
ss.clear();
|
||||
ss << drawn_frames*(tickNow-tickFPS+1)/1000;
|
||||
ss >> fps;
|
||||
tickFPS = tickNow;
|
||||
drawn_frames = 0;
|
||||
}
|
||||
s->write(font, fps + " FPS", resX - 1, 1, Font::HAlignRight);
|
||||
#endif
|
||||
|
||||
s->flip();
|
||||
|
||||
//touchscreen
|
||||
if (ts.available()) {
|
||||
ts.poll();
|
||||
btnContextMenu.handleTS();
|
||||
re.x = 0; re.y = 0; re.h = skinConfInt["topBarHeight"]; re.w = resX;
|
||||
btnContextMenu->handleTS();
|
||||
const int topBarHeight = skinConfInt["topBarHeight"];
|
||||
SDL_Rect re = {
|
||||
0, 0,
|
||||
static_cast<Uint16>(resX), static_cast<Uint16>(topBarHeight)
|
||||
};
|
||||
if (ts.pressed() && ts.inRect(re)) {
|
||||
re.w = skinConfInt["linkWidth"];
|
||||
sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2;
|
||||
for (i=menu->firstDispSection(); !ts.handled() && i<menu->getSections().size() && i<menu->firstDispSection()+linkColumns; i++) {
|
||||
uint sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2;
|
||||
for (uint i=menu->firstDispSection(); !ts.handled() && i<menu->getSections().size() && i<menu->firstDispSection()+linkColumns; i++) {
|
||||
re.x = (i-menu->firstDispSection())*re.w+sectionsCoordX;
|
||||
|
||||
if (ts.inRect(re)) {
|
||||
@ -756,7 +745,8 @@ void GMenu2X::main() {
|
||||
}
|
||||
}
|
||||
|
||||
i=menu->firstDispRow()*linkColumns;
|
||||
uint linksPerPage = linkColumns*linkRows;
|
||||
uint i=menu->firstDispRow()*linkColumns;
|
||||
while ( i<(menu->firstDispRow()*linkColumns)+linksPerPage && i<menu->sectionLinks()->size()) {
|
||||
if (menu->sectionLinks()->at(i)->isPressed())
|
||||
menu->setLinkIndex(i);
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
class Button;
|
||||
class Font;
|
||||
class IconButton;
|
||||
class MediaMonitor;
|
||||
class Menu;
|
||||
class Surface;
|
||||
@ -66,6 +67,7 @@ private:
|
||||
Touchscreen ts;
|
||||
Menu *menu;
|
||||
MediaMonitor *monitor;
|
||||
std::string batteryIcon;
|
||||
|
||||
/*!
|
||||
Retrieves the free disk space on the sd
|
||||
@ -120,6 +122,9 @@ private:
|
||||
void initFont();
|
||||
void initMenu();
|
||||
|
||||
void paint();
|
||||
void paintHelp();
|
||||
|
||||
void showManual();
|
||||
|
||||
public:
|
||||
@ -152,6 +157,7 @@ public:
|
||||
Translator tr;
|
||||
Surface *s, *bg;
|
||||
Font *font;
|
||||
IconButton *btnContextMenu;
|
||||
|
||||
//Status functions
|
||||
void main();
|
||||
|
Loading…
Reference in New Issue
Block a user