From 074668336e1eea1998b13b185b08abd9459831b9 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Mon, 5 Aug 2013 16:43:22 +0200 Subject: [PATCH] Handle menu-related buttons inside Menu class --- src/gmenu2x.cpp | 50 ++++++++++++++++--------------------------------- src/menu.cpp | 28 +++++++++++++++++++++++++++ src/menu.h | 23 ++++++++++++++++------- 3 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 0776d88..a90e1eb 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -686,40 +686,22 @@ void GMenu2X::main() { menu->handleTS(); } - switch (input.waitForPressedButton()) { - case InputManager::ACCEPT: - if (menu->selLink() != NULL) menu->selLink()->run(); - break; - case InputManager::CANCEL: - helpDisplayed=true; - break; - case InputManager::SETTINGS: - options(); - break; - case InputManager::MENU: - contextMenu(); - break; - case InputManager::UP: - menu->linkUp(); - break; - case InputManager::DOWN: - menu->linkDown(); - break; - case InputManager::LEFT: - menu->linkLeft(); - break; - case InputManager::RIGHT: - menu->linkRight(); - break; - case InputManager::ALTLEFT: - menu->decSectionIndex(); - break; - case InputManager::ALTRIGHT: - menu->incSectionIndex(); - break; - default: - break; - } + InputManager::Button button = input.waitForPressedButton(); + if (!menu->handleButtonPress(button)) { + switch (button) { + case InputManager::CANCEL: + helpDisplayed=true; + break; + case InputManager::SETTINGS: + options(); + break; + case InputManager::MENU: + contextMenu(); + break; + default: + break; + } + } } } diff --git a/src/menu.cpp b/src/menu.cpp index 7d8a3d5..134a62e 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -207,6 +207,34 @@ void Menu::paint(Surface &s) { } } +bool Menu::handleButtonPress(InputManager::Button button) { + switch (button) { + case InputManager::ACCEPT: + if (selLink() != NULL) selLink()->run(); + return true; + case InputManager::UP: + linkUp(); + return true; + case InputManager::DOWN: + linkDown(); + return true; + case InputManager::LEFT: + linkLeft(); + return true; + case InputManager::RIGHT: + linkRight(); + return true; + case InputManager::ALTLEFT: + decSectionIndex(); + return true; + case InputManager::ALTRIGHT: + incSectionIndex(); + return true; + default: + return false; + } +} + void Menu::handleTS() { ConfIntHash &skinConfInt = gmenu2x->skinConfInt; const int topBarHeight = skinConfInt["topBarHeight"]; diff --git a/src/menu.h b/src/menu.h index bb0cd1a..b6cedbc 100644 --- a/src/menu.h +++ b/src/menu.h @@ -21,8 +21,9 @@ #ifndef MENU_H #define MENU_H -#include "link.h" #include "delegate.h" +#include "inputmanager.h" +#include "link.h" #include #include @@ -74,6 +75,13 @@ private: // Load all the links on the given section directory. void readLinksOfSection(std::string path, std::vector &linkfiles); + void decSectionIndex(); + void incSectionIndex(); + void linkLeft(); + void linkRight(); + void linkUp(); + void linkDown(); + public: Menu(GMenu2X *gmenu2x, Touchscreen &ts); ~Menu(); @@ -88,8 +96,6 @@ public: int selSectionIndex(); const std::string &selSection(); - void decSectionIndex(); - void incSectionIndex(); void setSectionIndex(int i); bool addActionLink(uint section, const std::string &title, @@ -102,16 +108,19 @@ public: void skinUpdated(); void paint(Surface &s); + + /** + * Handles the pressing of the give button. + * Returns true iff the event was consumed. + */ + bool handleButtonPress(InputManager::Button button); + void handleTS(); bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex); int selLinkIndex(); Link *selLink(); LinkApp *selLinkApp(); - void linkLeft(); - void linkRight(); - void linkUp(); - void linkDown(); void setLinkIndex(int i); const std::vector &getSections() { return sections; }