From 71f4391cdad8323922053e97b403d24c85ed7eb5 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Fri, 9 Aug 2013 19:09:57 +0200 Subject: [PATCH] Moved all code for opening the context menu into the Menu class All of the entries in the context menu affect sections and links, so the context menu should be considered part of the main menu, not of the global / background context. --- src/background.cpp | 3 --- src/gmenu2x.cpp | 40 +++++++--------------------------------- src/gmenu2x.h | 7 ++----- src/menu.cpp | 28 ++++++++++++++++++++++++++++ src/menu.h | 5 ++++- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/background.cpp b/src/background.cpp index a8e94d4..05e41af 100644 --- a/src/background.cpp +++ b/src/background.cpp @@ -33,9 +33,6 @@ bool Background::handleButtonPress(InputManager::Button button) { case InputManager::SETTINGS: gmenu2x.showSettings(); return true; - case InputManager::MENU: - gmenu2x.contextMenu(); - return true; default: return false; } diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index aee96c2..61afb42 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -231,7 +231,6 @@ GMenu2X::GMenu2X() bg = NULL; font = NULL; - btnContextMenu = nullptr; setSkin(confStr["skin"], !fileExists(confStr["wallpaper"])); layers.insert(layers.begin(), make_shared(*this)); initMenu(); @@ -276,7 +275,6 @@ GMenu2X::~GMenu2X() { delete PowerSaver::getInstance(); quit(); - delete btnContextMenu; delete font; delete monitor; } @@ -390,13 +388,6 @@ 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)); - - //DEBUG - //menu->addLink( CARD_ROOT, "sample.pxml", "applications" ); - layers.push_back(menu); } @@ -599,40 +590,21 @@ void GMenu2X::writeTmp(int selelem, const string &selectordir) { } } -void GMenu2X::paint() { - for (auto layer : layers) { - layer->paint(*s); - } - - LinkApp *linkApp = menu->selLinkApp(); - if (linkApp) { -#ifdef ENABLE_CPUFREQ - s->write(font, linkApp->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle); -#endif - //Manual indicator - if (!linkApp->getManual().empty()) - sc.skinRes("imgs/manual.png")->blit(s, manualX, bottomBarIconY); - } - - if (ts.available()) { - btnContextMenu->paint(); - } -} - void GMenu2X::main() { if (!fileExists(CARD_ROOT)) CARD_ROOT = ""; bool quit = false; while (!quit) { - - paint(); + // Paint layers. + for (auto layer : layers) { + layer->paint(*s); + } s->flip(); - //touchscreen + // Handle touchscreen events. if (ts.available()) { ts.poll(); - btnContextMenu->handleTS(); for (auto it = layers.rbegin(); it != layers.rend(); ++it) { if ((*it)->handleTouchscreen(ts)) { break; @@ -640,6 +612,7 @@ void GMenu2X::main() { } } + // Handle other input events. InputManager::Button button = input.waitForPressedButton(); for (auto it = layers.rbegin(); it != layers.rend(); ++it) { if ((*it)->handleButtonPress(button)) { @@ -647,6 +620,7 @@ void GMenu2X::main() { } } + // Remove dismissed layers from the stack. for (auto it = layers.begin(); it != layers.end(); ) { auto layer = *it; if (layer->wasDismissed()) { diff --git a/src/gmenu2x.h b/src/gmenu2x.h index f808261..83b0bfa 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -78,8 +78,6 @@ private: @return String containing a human readable representation of the free disk space */ std::string getDiskFree(const char *path); - unsigned short cpuX; //!< Offset for displaying cpu clock information - unsigned short manualX; //!< Offset for displaying the manual indicator in the taskbar #ifdef ENABLE_CPUFREQ unsigned cpuFreqMin; //!< Minimum CPU frequency unsigned cpuFreqMax; //!< Maximum theoretical CPU frequency @@ -121,8 +119,6 @@ private: void initFont(); void initMenu(); - void paint(); - void showManual(); public: @@ -139,6 +135,8 @@ public: */ uint resX, resY, halfX, halfY; uint bottomBarIconY, bottomBarTextY; + unsigned short cpuX; //!< Offset for displaying cpu clock information + unsigned short manualX; //!< Offset for displaying the manual indicator in the taskbar InputManager input; @@ -155,7 +153,6 @@ public: Translator tr; Surface *s, *bg; Font *font; - IconButton *btnContextMenu; //Status functions void main(); diff --git a/src/menu.cpp b/src/menu.cpp index ab450fd..0e71cac 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -38,12 +38,15 @@ #include "filelister.h" #include "utilities.h" #include "debug.h" +#include "iconbutton.h" using namespace std; + Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts) : gmenu2x(gmenu2x) , ts(ts) + , btnContextMenu(new IconButton(gmenu2x, ts, "skin:imgs/menu.png")) { readSections(GMENU2X_SYSTEM_DIR "/sections"); readSections(GMenu2X::getHome() + "/sections"); @@ -73,6 +76,9 @@ Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts) #endif orderLinks(); + + btnContextMenu->setPosition(gmenu2x->resX - 38, gmenu2x->bottomBarIconY); + btnContextMenu->setAction(std::bind(&GMenu2X::contextMenu, gmenu2x)); } Menu::~Menu() { @@ -205,6 +211,23 @@ void Menu::paint(Surface &s) { width / 2, height - bottomBarHeight + 2, Font::HAlignCenter, Font::VAlignBottom); } + + LinkApp *linkApp = selLinkApp(); + if (linkApp) { +#ifdef ENABLE_CPUFREQ + s.write(&font, linkApp->clockStr(gmenu2x->confInt["maxClock"]), + gmenu2x->cpuX, gmenu2x->bottomBarTextY, + Font::HAlignLeft, Font::VAlignMiddle); +#endif + //Manual indicator + if (!linkApp->getManual().empty()) + sc.skinRes("imgs/manual.png")->blit( + &s, gmenu2x->manualX, gmenu2x->bottomBarIconY); + } + + if (ts.available()) { + btnContextMenu->paint(); + } } bool Menu::handleButtonPress(InputManager::Button button) { @@ -230,12 +253,17 @@ bool Menu::handleButtonPress(InputManager::Button button) { case InputManager::ALTRIGHT: incSectionIndex(); return true; + case InputManager::MENU: + gmenu2x->contextMenu(); + return true; default: return false; } } bool Menu::handleTouchscreen(Touchscreen &ts) { + btnContextMenu->handleTS(); + ConfIntHash &skinConfInt = gmenu2x->skinConfInt; const int topBarHeight = skinConfInt["topBarHeight"]; const int screenWidth = gmenu2x->resX; diff --git a/src/menu.h b/src/menu.h index f434c55..f580688 100644 --- a/src/menu.h +++ b/src/menu.h @@ -25,11 +25,13 @@ #include "layer.h" #include "link.h" +#include #include #include -class LinkApp; class GMenu2X; +class IconButton; +class LinkApp; class Monitor; @@ -42,6 +44,7 @@ class Menu : public Layer { private: GMenu2X *gmenu2x; Touchscreen &ts; + std::unique_ptr btnContextMenu; int iSection, iLink; uint iFirstDispRow; std::vector sections;