1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-07 14:38:34 +03:00

Handle menu-related buttons inside Menu class

This commit is contained in:
Maarten ter Huurne 2013-08-05 16:43:22 +02:00
parent d588b97b34
commit 074668336e
3 changed files with 60 additions and 41 deletions

View File

@ -686,10 +686,9 @@ void GMenu2X::main() {
menu->handleTS(); menu->handleTS();
} }
switch (input.waitForPressedButton()) { InputManager::Button button = input.waitForPressedButton();
case InputManager::ACCEPT: if (!menu->handleButtonPress(button)) {
if (menu->selLink() != NULL) menu->selLink()->run(); switch (button) {
break;
case InputManager::CANCEL: case InputManager::CANCEL:
helpDisplayed=true; helpDisplayed=true;
break; break;
@ -699,28 +698,11 @@ void GMenu2X::main() {
case InputManager::MENU: case InputManager::MENU:
contextMenu(); contextMenu();
break; 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: default:
break; break;
} }
} }
}
} }
void GMenu2X::explorer() { void GMenu2X::explorer() {

View File

@ -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() { void Menu::handleTS() {
ConfIntHash &skinConfInt = gmenu2x->skinConfInt; ConfIntHash &skinConfInt = gmenu2x->skinConfInt;
const int topBarHeight = skinConfInt["topBarHeight"]; const int topBarHeight = skinConfInt["topBarHeight"];

View File

@ -21,8 +21,9 @@
#ifndef MENU_H #ifndef MENU_H
#define MENU_H #define MENU_H
#include "link.h"
#include "delegate.h" #include "delegate.h"
#include "inputmanager.h"
#include "link.h"
#include <string> #include <string>
#include <vector> #include <vector>
@ -74,6 +75,13 @@ private:
// Load all the links on the given section directory. // Load all the links on the given section directory.
void readLinksOfSection(std::string path, std::vector<std::string> &linkfiles); void readLinksOfSection(std::string path, std::vector<std::string> &linkfiles);
void decSectionIndex();
void incSectionIndex();
void linkLeft();
void linkRight();
void linkUp();
void linkDown();
public: public:
Menu(GMenu2X *gmenu2x, Touchscreen &ts); Menu(GMenu2X *gmenu2x, Touchscreen &ts);
~Menu(); ~Menu();
@ -88,8 +96,6 @@ public:
int selSectionIndex(); int selSectionIndex();
const std::string &selSection(); const std::string &selSection();
void decSectionIndex();
void incSectionIndex();
void setSectionIndex(int i); void setSectionIndex(int i);
bool addActionLink(uint section, const std::string &title, bool addActionLink(uint section, const std::string &title,
@ -102,16 +108,19 @@ public:
void skinUpdated(); void skinUpdated();
void paint(Surface &s); 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(); void handleTS();
bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex); bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
int selLinkIndex(); int selLinkIndex();
Link *selLink(); Link *selLink();
LinkApp *selLinkApp(); LinkApp *selLinkApp();
void linkLeft();
void linkRight();
void linkUp();
void linkDown();
void setLinkIndex(int i); void setLinkIndex(int i);
const std::vector<std::string> &getSections() { return sections; } const std::vector<std::string> &getSections() { return sections; }