mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 20:25:54 +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
234
src/gmenu2x.cpp
234
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,160 +599,143 @@ void GMenu2X::writeTmp(int selelem, const string &selectordir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMenu2X::main() {
|
void GMenu2X::paint() {
|
||||||
uint linksPerPage = linkColumns*linkRows;
|
//Background
|
||||||
|
sc["bgmain"]->blit(s,0,0);
|
||||||
|
|
||||||
|
//Sections
|
||||||
|
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
|
||||||
|
sc.skinRes("imgs/l_disabled.png")->blit(s,0,0);
|
||||||
|
if (menu->firstDispSection()+linkColumns<menu->getSections().size())
|
||||||
|
sc.skinRes("imgs/r_enabled.png")->blit(s,resX-10,0);
|
||||||
|
else
|
||||||
|
sc.skinRes("imgs/r_disabled.png")->blit(s,resX-10,0);
|
||||||
|
for (uint i = menu->firstDispSection(); i < menu->getSections().size() && i < menu->firstDispSection() + linkColumns; i++) {
|
||||||
|
string sectionIcon = "skin:sections/"+menu->getSections()[i]+".png";
|
||||||
|
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]);
|
||||||
|
x += skinConfInt["linkWidth"]/2;
|
||||||
|
if (sc.exists(sectionIcon))
|
||||||
|
sc[sectionIcon]->blit(s,x-16,sectionLinkPadding,32,32);
|
||||||
|
else
|
||||||
|
sc.skinRes("icons/section.png")->blit(s,x-16,sectionLinkPadding);
|
||||||
|
s->write( font, menu->getSections()[i], x, skinConfInt["topBarHeight"]-sectionLinkPadding, Font::HAlignCenter, Font::VAlignBottom );
|
||||||
|
}
|
||||||
|
|
||||||
|
//Links
|
||||||
|
uint linksPerPage = linkColumns * linkRows;
|
||||||
int linkSpacingX = (resX-10 - linkColumns*skinConfInt["linkWidth"])/linkColumns;
|
int linkSpacingX = (resX-10 - linkColumns*skinConfInt["linkWidth"])/linkColumns;
|
||||||
int linkSpacingY = (resY-35 - skinConfInt["topBarHeight"] - linkRows*skinConfInt["linkHeight"])/linkRows;
|
int linkSpacingY = (resY-35 - skinConfInt["topBarHeight"] - linkRows*skinConfInt["linkHeight"])/linkRows;
|
||||||
uint sectionLinkPadding = (skinConfInt["topBarHeight"] - 32 - font->getHeight()) / 3;
|
for (uint i = menu->firstDispRow() * linkColumns; i < menu->firstDispRow() * linkColumns + linksPerPage && i < menu->sectionLinks()->size(); i++) {
|
||||||
|
int ir = i-menu->firstDispRow()*linkColumns;
|
||||||
|
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);
|
||||||
|
|
||||||
bool quit = false;
|
if (i == (uint)menu->selLinkIndex())
|
||||||
int x,y;
|
menu->sectionLinks()->at(i)->paintHover();
|
||||||
int helpBoxHeight = 154;
|
|
||||||
uint i;
|
menu->sectionLinks()->at(i)->paint();
|
||||||
long tickBattery = -60000, tickNow;
|
}
|
||||||
string batteryIcon = "imgs/battery/0.png";
|
s->clearClipRect();
|
||||||
stringstream ss;
|
|
||||||
uint sectionsCoordX = 24;
|
drawScrollBar(linkRows,menu->sectionLinks()->size()/linkColumns + ((menu->sectionLinks()->size()%linkColumns==0) ? 0 : 1),menu->firstDispRow(),43,resY-81);
|
||||||
SDL_Rect re = {0,0,0,0};
|
|
||||||
bool helpDisplayed = false;
|
if (menu->selLink()!=NULL) {
|
||||||
#ifdef WITH_DEBUG
|
s->write ( font, menu->selLink()->getDescription(), halfX, resY-19, Font::HAlignCenter, Font::VAlignBottom );
|
||||||
//framerate
|
if (menu->selLinkApp()!=NULL) {
|
||||||
long tickFPS = SDL_GetTicks();
|
#ifdef ENABLE_CPUFREQ
|
||||||
int drawn_frames = 0;
|
s->write ( font, menu->selLinkApp()->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle );
|
||||||
string fps = "";
|
|
||||||
#endif
|
#endif
|
||||||
|
//Manual indicator
|
||||||
|
if (!menu->selLinkApp()->getManual().empty())
|
||||||
|
sc.skinRes("imgs/manual.png")->blit(s,manualX,bottomBarIconY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IconButton btnContextMenu(this, ts, "skin:imgs/menu.png");
|
if (ts.available()) {
|
||||||
btnContextMenu.setPosition(resX-38, bottomBarIconY);
|
btnContextMenu->paint();
|
||||||
btnContextMenu.setAction(BIND(&GMenu2X::contextMenu));
|
}
|
||||||
|
|
||||||
|
sc.skinRes(batteryIcon)->blit( s, resX-19, bottomBarIconY );
|
||||||
|
//s->write( font, tr[batstr.c_str()], 20, 170 );
|
||||||
|
|
||||||
|
s->write(font, Clock::getInstance()->getTime(),
|
||||||
|
halfX, bottomBarTextY,
|
||||||
|
Font::HAlignCenter, Font::VAlignMiddle);
|
||||||
|
}
|
||||||
|
|
||||||
|
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] );
|
||||||
|
s->write( font, tr["CONTROLS"], 20, 60 );
|
||||||
|
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
|
||||||
|
s->write( font, tr["A: Launch link / Confirm action"], 20, 80 );
|
||||||
|
s->write( font, tr["B: Show this help menu"], 20, 95 );
|
||||||
|
s->write( font, tr["L, R: Change section"], 20, 110 );
|
||||||
|
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))
|
if (!fileExists(CARD_ROOT))
|
||||||
CARD_ROOT = "";
|
CARD_ROOT = "";
|
||||||
|
|
||||||
|
bool helpDisplayed = false;
|
||||||
|
|
||||||
|
bool quit = false;
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
tickNow = SDL_GetTicks();
|
|
||||||
|
|
||||||
//Background
|
|
||||||
sc["bgmain"]->blit(s,0,0);
|
|
||||||
|
|
||||||
//Sections
|
|
||||||
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
|
|
||||||
sc.skinRes("imgs/l_disabled.png")->blit(s,0,0);
|
|
||||||
if (menu->firstDispSection()+linkColumns<menu->getSections().size())
|
|
||||||
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++) {
|
|
||||||
string sectionIcon = "skin:sections/"+menu->getSections()[i]+".png";
|
|
||||||
x = (i-menu->firstDispSection())*skinConfInt["linkWidth"]+sectionsCoordX;
|
|
||||||
if (menu->selSectionIndex()==(int)i)
|
|
||||||
s->box(x, 0, skinConfInt["linkWidth"],
|
|
||||||
skinConfInt["topBarHeight"], skinConfColors[COLOR_SELECTION_BG]);
|
|
||||||
x += skinConfInt["linkWidth"]/2;
|
|
||||||
if (sc.exists(sectionIcon))
|
|
||||||
sc[sectionIcon]->blit(s,x-16,sectionLinkPadding,32,32);
|
|
||||||
else
|
|
||||||
sc.skinRes("icons/section.png")->blit(s,x-16,sectionLinkPadding);
|
|
||||||
s->write( font, menu->getSections()[i], x, skinConfInt["topBarHeight"]-sectionLinkPadding, Font::HAlignCenter, Font::VAlignBottom );
|
|
||||||
}
|
|
||||||
|
|
||||||
//Links
|
|
||||||
for (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;
|
|
||||||
menu->sectionLinks()->at(i)->setPosition(x,y);
|
|
||||||
|
|
||||||
if (i==(uint)menu->selLinkIndex())
|
|
||||||
menu->sectionLinks()->at(i)->paintHover();
|
|
||||||
|
|
||||||
menu->sectionLinks()->at(i)->paint();
|
|
||||||
}
|
|
||||||
s->clearClipRect();
|
|
||||||
|
|
||||||
drawScrollBar(linkRows,menu->sectionLinks()->size()/linkColumns + ((menu->sectionLinks()->size()%linkColumns==0) ? 0 : 1),menu->firstDispRow(),43,resY-81);
|
|
||||||
|
|
||||||
if (menu->selLink()!=NULL) {
|
|
||||||
s->write ( font, menu->selLink()->getDescription(), halfX, resY-19, Font::HAlignCenter, Font::VAlignBottom );
|
|
||||||
if (menu->selLinkApp()!=NULL) {
|
|
||||||
#ifdef ENABLE_CPUFREQ
|
|
||||||
s->write ( font, menu->selLinkApp()->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle );
|
|
||||||
#endif
|
|
||||||
//Manual indicator
|
|
||||||
if (!menu->selLinkApp()->getManual().empty())
|
|
||||||
sc.skinRes("imgs/manual.png")->blit(s,manualX,bottomBarIconY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ts.available()) {
|
|
||||||
btnContextMenu.paint();
|
|
||||||
}
|
|
||||||
//check battery status every 60 seconds
|
//check battery status every 60 seconds
|
||||||
if (tickNow-tickBattery >= 60000) {
|
long tickNow = SDL_GetTicks();
|
||||||
|
if (tickNow - tickBattery >= 60000) {
|
||||||
tickBattery = tickNow;
|
tickBattery = tickNow;
|
||||||
unsigned short battlevel = getBatteryLevel();
|
unsigned short battlevel = getBatteryLevel();
|
||||||
if (battlevel>5) {
|
if (battlevel>5) {
|
||||||
batteryIcon = "imgs/battery/ac.png";
|
batteryIcon = "imgs/battery/ac.png";
|
||||||
} else {
|
} else {
|
||||||
ss.clear();
|
stringstream ss;
|
||||||
ss << battlevel;
|
ss << "imgs/battery/" << battlevel << ".png";
|
||||||
ss >> batteryIcon;
|
ss >> batteryIcon;
|
||||||
batteryIcon = "imgs/battery/"+batteryIcon+".png";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
|
|
||||||
|
paint();
|
||||||
if (helpDisplayed) {
|
if (helpDisplayed) {
|
||||||
s->box(10,50,300,helpBoxHeight+4, skinConfColors[COLOR_MESSAGE_BOX_BG]);
|
paintHelp();
|
||||||
s->rectangle( 12,52,296,helpBoxHeight,
|
|
||||||
skinConfColors[COLOR_MESSAGE_BOX_BORDER] );
|
|
||||||
s->write( font, tr["CONTROLS"], 20, 60 );
|
|
||||||
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
|
|
||||||
s->write( font, tr["A: Launch link / Confirm action"], 20, 80 );
|
|
||||||
s->write( font, tr["B: Show this help menu"], 20, 95 );
|
|
||||||
s->write( font, tr["L, R: Change section"], 20, 110 );
|
|
||||||
s->write( font, tr["SELECT: Show contextual menu"], 20, 155 );
|
|
||||||
s->write( font, tr["START: Show options menu"], 20, 170 );
|
|
||||||
#endif
|
|
||||||
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