mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 11:48:26 +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;
|
bg = NULL;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
menu = NULL;
|
menu = NULL;
|
||||||
|
btnContextMenu = nullptr;
|
||||||
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
||||||
initMenu();
|
initMenu();
|
||||||
|
|
||||||
@ -277,6 +278,7 @@ GMenu2X::~GMenu2X() {
|
|||||||
quit();
|
quit();
|
||||||
|
|
||||||
delete menu;
|
delete menu;
|
||||||
|
delete btnContextMenu;
|
||||||
delete font;
|
delete font;
|
||||||
delete monitor;
|
delete monitor;
|
||||||
}
|
}
|
||||||
@ -388,6 +390,10 @@ void GMenu2X::initMenu() {
|
|||||||
menu->setSectionIndex(confInt["section"]);
|
menu->setSectionIndex(confInt["section"]);
|
||||||
menu->setLinkIndex(confInt["link"]);
|
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();
|
menu->loadIcons();
|
||||||
|
|
||||||
//DEBUG
|
//DEBUG
|
||||||
@ -593,44 +599,13 @@ void GMenu2X::writeTmp(int selelem, const string &selectordir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMenu2X::main() {
|
void GMenu2X::paint() {
|
||||||
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();
|
|
||||||
|
|
||||||
//Background
|
//Background
|
||||||
sc["bgmain"]->blit(s,0,0);
|
sc["bgmain"]->blit(s,0,0);
|
||||||
|
|
||||||
//Sections
|
//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)
|
if (menu->firstDispSection()>0)
|
||||||
sc.skinRes("imgs/l_enabled.png")->blit(s,0,0);
|
sc.skinRes("imgs/l_enabled.png")->blit(s,0,0);
|
||||||
else
|
else
|
||||||
@ -639,9 +614,9 @@ void GMenu2X::main() {
|
|||||||
sc.skinRes("imgs/r_enabled.png")->blit(s,resX-10,0);
|
sc.skinRes("imgs/r_enabled.png")->blit(s,resX-10,0);
|
||||||
else
|
else
|
||||||
sc.skinRes("imgs/r_disabled.png")->blit(s,resX-10,0);
|
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";
|
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)
|
if (menu->selSectionIndex()==(int)i)
|
||||||
s->box(x, 0, skinConfInt["linkWidth"],
|
s->box(x, 0, skinConfInt["linkWidth"],
|
||||||
skinConfInt["topBarHeight"], skinConfColors[COLOR_SELECTION_BG]);
|
skinConfInt["topBarHeight"], skinConfColors[COLOR_SELECTION_BG]);
|
||||||
@ -654,10 +629,13 @@ void GMenu2X::main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Links
|
//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;
|
int ir = i-menu->firstDispRow()*linkColumns;
|
||||||
x = (ir%linkColumns)*(skinConfInt["linkWidth"]+linkSpacingX)+6;
|
int x = (ir%linkColumns)*(skinConfInt["linkWidth"]+linkSpacingX)+6;
|
||||||
y = ir/linkColumns*(skinConfInt["linkHeight"]+linkSpacingY)+skinConfInt["topBarHeight"]+2;
|
int y = ir/linkColumns*(skinConfInt["linkHeight"]+linkSpacingY)+skinConfInt["topBarHeight"]+2;
|
||||||
menu->sectionLinks()->at(i)->setPosition(x,y);
|
menu->sectionLinks()->at(i)->setPosition(x,y);
|
||||||
|
|
||||||
if (i == (uint)menu->selLinkIndex())
|
if (i == (uint)menu->selLinkIndex())
|
||||||
@ -682,30 +660,20 @@ void GMenu2X::main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ts.available()) {
|
if (ts.available()) {
|
||||||
btnContextMenu.paint();
|
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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.skinRes(batteryIcon)->blit( s, resX-19, bottomBarIconY );
|
sc.skinRes(batteryIcon)->blit( s, resX-19, bottomBarIconY );
|
||||||
//s->write( font, tr[batstr.c_str()], 20, 170 );
|
//s->write( font, tr[batstr.c_str()], 20, 170 );
|
||||||
//On Screen Help
|
|
||||||
|
|
||||||
s->write(font, Clock::getInstance()->getTime(),
|
s->write(font, Clock::getInstance()->getTime(),
|
||||||
halfX, bottomBarTextY,
|
halfX, bottomBarTextY,
|
||||||
Font::HAlignCenter, Font::VAlignMiddle);
|
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->box(10,50,300,helpBoxHeight+4, skinConfColors[COLOR_MESSAGE_BOX_BG]);
|
||||||
s->rectangle( 12,52,296,helpBoxHeight,
|
s->rectangle( 12,52,296,helpBoxHeight,
|
||||||
skinConfColors[COLOR_MESSAGE_BOX_BORDER] );
|
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["SELECT: Show contextual menu"], 20, 155 );
|
||||||
s->write( font, tr["START: Show options menu"], 20, 170 );
|
s->write( font, tr["START: Show options menu"], 20, 170 );
|
||||||
#endif
|
#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();
|
s->flip();
|
||||||
while (input.waitForPressedButton() != InputManager::CANCEL) {}
|
while (input.waitForPressedButton() != InputManager::CANCEL) {}
|
||||||
helpDisplayed=false;
|
helpDisplayed=false;
|
||||||
continue;
|
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();
|
s->flip();
|
||||||
|
|
||||||
//touchscreen
|
//touchscreen
|
||||||
if (ts.available()) {
|
if (ts.available()) {
|
||||||
ts.poll();
|
ts.poll();
|
||||||
btnContextMenu.handleTS();
|
btnContextMenu->handleTS();
|
||||||
re.x = 0; re.y = 0; re.h = skinConfInt["topBarHeight"]; re.w = resX;
|
const int topBarHeight = skinConfInt["topBarHeight"];
|
||||||
|
SDL_Rect re = {
|
||||||
|
0, 0,
|
||||||
|
static_cast<Uint16>(resX), static_cast<Uint16>(topBarHeight)
|
||||||
|
};
|
||||||
if (ts.pressed() && ts.inRect(re)) {
|
if (ts.pressed() && ts.inRect(re)) {
|
||||||
re.w = skinConfInt["linkWidth"];
|
re.w = skinConfInt["linkWidth"];
|
||||||
sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2;
|
uint 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++) {
|
for (uint i=menu->firstDispSection(); !ts.handled() && i<menu->getSections().size() && i<menu->firstDispSection()+linkColumns; i++) {
|
||||||
re.x = (i-menu->firstDispSection())*re.w+sectionsCoordX;
|
re.x = (i-menu->firstDispSection())*re.w+sectionsCoordX;
|
||||||
|
|
||||||
if (ts.inRect(re)) {
|
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()) {
|
while ( i<(menu->firstDispRow()*linkColumns)+linksPerPage && i<menu->sectionLinks()->size()) {
|
||||||
if (menu->sectionLinks()->at(i)->isPressed())
|
if (menu->sectionLinks()->at(i)->isPressed())
|
||||||
menu->setLinkIndex(i);
|
menu->setLinkIndex(i);
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
class Button;
|
class Button;
|
||||||
class Font;
|
class Font;
|
||||||
|
class IconButton;
|
||||||
class MediaMonitor;
|
class MediaMonitor;
|
||||||
class Menu;
|
class Menu;
|
||||||
class Surface;
|
class Surface;
|
||||||
@ -66,6 +67,7 @@ private:
|
|||||||
Touchscreen ts;
|
Touchscreen ts;
|
||||||
Menu *menu;
|
Menu *menu;
|
||||||
MediaMonitor *monitor;
|
MediaMonitor *monitor;
|
||||||
|
std::string batteryIcon;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Retrieves the free disk space on the sd
|
Retrieves the free disk space on the sd
|
||||||
@ -120,6 +122,9 @@ private:
|
|||||||
void initFont();
|
void initFont();
|
||||||
void initMenu();
|
void initMenu();
|
||||||
|
|
||||||
|
void paint();
|
||||||
|
void paintHelp();
|
||||||
|
|
||||||
void showManual();
|
void showManual();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -152,6 +157,7 @@ public:
|
|||||||
Translator tr;
|
Translator tr;
|
||||||
Surface *s, *bg;
|
Surface *s, *bg;
|
||||||
Font *font;
|
Font *font;
|
||||||
|
IconButton *btnContextMenu;
|
||||||
|
|
||||||
//Status functions
|
//Status functions
|
||||||
void main();
|
void main();
|
||||||
|
Loading…
Reference in New Issue
Block a user