1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-27 01:10:37 +02:00

BrowseDialog: simplify code using InputManager::waitForPressedButton().

This commit is contained in:
Maarten ter Huurne 2011-10-23 09:11:06 +02:00
parent 315bf0a180
commit ccf55e5d61
2 changed files with 26 additions and 43 deletions

View File

@ -73,58 +73,41 @@ bool BrowseDialog::exec()
return result; return result;
} }
BrowseDialog::Action BrowseDialog::getAction(InputManager::ButtonEvent *event) BrowseDialog::Action BrowseDialog::getAction(InputManager::Button button)
{ {
BrowseDialog::Action action; switch (button) {
switch(event->button) {
case InputManager::MENU: case InputManager::MENU:
action = BrowseDialog::ACT_CLOSE; return BrowseDialog::ACT_CLOSE;
break;
case InputManager::UP: case InputManager::UP:
action = BrowseDialog::ACT_UP; return BrowseDialog::ACT_UP;
break;
case InputManager::DOWN: case InputManager::DOWN:
action = BrowseDialog::ACT_DOWN; return BrowseDialog::ACT_DOWN;
break;
case InputManager::ALTLEFT: case InputManager::ALTLEFT:
action = BrowseDialog::ACT_SCROLLUP; return BrowseDialog::ACT_SCROLLUP;
break;
case InputManager::ALTRIGHT: case InputManager::ALTRIGHT:
action = BrowseDialog::ACT_SCROLLDOWN; return BrowseDialog::ACT_SCROLLDOWN;
break;
case InputManager::LEFT: case InputManager::LEFT:
case InputManager::CANCEL: case InputManager::CANCEL:
action = BrowseDialog::ACT_GOUP; return BrowseDialog::ACT_GOUP;
break;
case InputManager::ACCEPT: case InputManager::ACCEPT:
action = BrowseDialog::ACT_SELECT; return BrowseDialog::ACT_SELECT;
break;
case InputManager::SETTINGS: case InputManager::SETTINGS:
action = BrowseDialog::ACT_CONFIRM; return BrowseDialog::ACT_CONFIRM;
break;
default: default:
action = BrowseDialog::ACT_NONE; return BrowseDialog::ACT_NONE;
break;
} }
return action;
} }
void BrowseDialog::handleInput() void BrowseDialog::handleInput()
{ {
InputManager::Button button = gmenu2x->input.waitForPressedButton();
BrowseDialog::Action action; BrowseDialog::Action action;
InputManager::ButtonEvent event;
do {
gmenu2x->input.waitForEvent(&event);
} while (event.state != InputManager::PRESSED);
if (ts_pressed && !gmenu2x->ts.pressed()) { if (ts_pressed && !gmenu2x->ts.pressed()) {
action = BrowseDialog::ACT_SELECT; action = BrowseDialog::ACT_SELECT;
ts_pressed = false; ts_pressed = false;
} else { } else {
action = getAction(&event); action = getAction(button);
} }
if (gmenu2x->ts.initialized() && gmenu2x->ts.pressed() && !gmenu2x->ts.inRect(touchRect)) ts_pressed = false; if (gmenu2x->ts.initialized() && gmenu2x->ts.pressed() && !gmenu2x->ts.inRect(touchRect)) ts_pressed = false;

View File

@ -76,7 +76,7 @@ private:
ButtonBox buttonBox; ButtonBox buttonBox;
Action getAction(InputManager::ButtonEvent *event); Action getAction(InputManager::Button button);
void handleInput(); void handleInput();
void paint(); void paint();