1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-02 18:47:19 +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,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;
}
}
}
}

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

View File

@ -21,8 +21,9 @@
#ifndef MENU_H
#define MENU_H
#include "link.h"
#include "delegate.h"
#include "inputmanager.h"
#include "link.h"
#include <string>
#include <vector>
@ -74,6 +75,13 @@ private:
// Load all the links on the given section directory.
void readLinksOfSection(std::string path, std::vector<std::string> &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<std::string> &getSections() { return sections; }