diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index 5e564eb..1d3a5ba 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -73,34 +73,34 @@ bool BrowseDialog::exec() return result; } -BrowseDialog::Action BrowseDialog::getAction(bevent_t *event) +BrowseDialog::Action BrowseDialog::getAction(InputManager::ButtonEvent *event) { BrowseDialog::Action action; switch(event->button) { - case MENU: + case InputManager::MENU: action = BrowseDialog::ACT_CLOSE; break; - case UP: + case InputManager::UP: action = BrowseDialog::ACT_UP; break; - case DOWN: + case InputManager::DOWN: action = BrowseDialog::ACT_DOWN; break; - case ALTLEFT: + case InputManager::ALTLEFT: action = BrowseDialog::ACT_SCROLLUP; break; - case ALTRIGHT: + case InputManager::ALTRIGHT: action = BrowseDialog::ACT_SCROLLDOWN; break; - case LEFT: - case CANCEL: + case InputManager::LEFT: + case InputManager::CANCEL: action = BrowseDialog::ACT_GOUP; break; - case ACCEPT: + case InputManager::ACCEPT: action = BrowseDialog::ACT_SELECT; break; - case SETTINGS: + case InputManager::SETTINGS: action = BrowseDialog::ACT_CONFIRM; break; default: @@ -114,16 +114,11 @@ BrowseDialog::Action BrowseDialog::getAction(bevent_t *event) void BrowseDialog::handleInput() { BrowseDialog::Action action; - bevent_t event; + InputManager::ButtonEvent event; - do { - gmenu2x->input.waitForEvent(&event); - } while (event.state != PRESSED); - - /* - while(!gmenu2x->input.update()) - usleep(LOOP_DELAY); - */ + do { + gmenu2x->input.waitForEvent(&event); + } while (event.state != InputManager::PRESSED); if (ts_pressed && !gmenu2x->ts.pressed()) { action = BrowseDialog::ACT_SELECT; @@ -192,7 +187,7 @@ void BrowseDialog::directoryUp() if (p == path.size() - 1) p = path.rfind("/", p - 1); - + if (p == string::npos || path.compare(0, 1, "/") != 0 || path.length() < 2) { quit(); } else { diff --git a/src/browsedialog.h b/src/browsedialog.h index d26db57..b8a65aa 100644 --- a/src/browsedialog.h +++ b/src/browsedialog.h @@ -76,7 +76,7 @@ private: ButtonBox buttonBox; - Action getAction(bevent_t *event); + Action getAction(InputManager::ButtonEvent *event); void handleInput(); void paint(); diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index db4df23..35c1eff 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -649,9 +649,9 @@ void GMenu2X::viewLog() { td.exec(); MessageBox mb(this, tr["Do you want to delete the log file?"], "icons/ebook.png"); - mb.setButton(ACCEPT, tr["Yes"]); - mb.setButton(CANCEL, tr["No"]); - if (mb.exec() == ACCEPT) { + mb.setButton(InputManager::ACCEPT, tr["Yes"]); + mb.setButton(InputManager::CANCEL, tr["No"]); + if (mb.exec() == InputManager::ACCEPT) { ledOn(); unlink(logfile.c_str()); sync(); @@ -1089,7 +1089,7 @@ void GMenu2X::main() { if (fwType=="open2x") s->write( font, tr["X: Toggle speaker mode"], 20, 185 ); #endif s->flip(); - while (input.waitForPressedButton() != CANCEL) {} + while (input.waitForPressedButton() != InputManager::CANCEL) {} helpDisplayed=false; continue; } @@ -1138,35 +1138,35 @@ void GMenu2X::main() { } switch (input.waitForPressedButton()) { - case ACCEPT: + case InputManager::ACCEPT: if (menu->selLink() != NULL) menu->selLink()->run(); break; - case CANCEL: + case InputManager::CANCEL: helpDisplayed=true; break; - case SETTINGS: + case InputManager::SETTINGS: options(); break; - case MENU: + case InputManager::MENU: contextMenu(); break; - case UP: + case InputManager::UP: menu->linkUp(); break; - case DOWN: + case InputManager::DOWN: menu->linkDown(); break; - case LEFT: + case InputManager::LEFT: menu->linkLeft(); break; - case RIGHT: + case InputManager::RIGHT: menu->linkRight(); break; - case ALTLEFT: + case InputManager::ALTLEFT: menu->decSectionIndex(); offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; break; - case ALTRIGHT: + case InputManager::ALTRIGHT: menu->incSectionIndex(); offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; break; @@ -1563,7 +1563,7 @@ void GMenu2X::contextMenu() { bg.box(box.x, box.y, box.w, box.h, skinConfColors["messageBoxBg"]); bg.rectangle( box.x+2, box.y+2, box.w-4, box.h-4, skinConfColors["messageBoxBorder"] );*/ - bevent_t event; + InputManager::ButtonEvent event; while (!close) { tickNow = SDL_GetTicks(); @@ -1613,22 +1613,22 @@ void GMenu2X::contextMenu() { if (fadeAlpha < 200) { - if (!input.pollEvent(&event) || event.state != PRESSED) continue; + if (!input.pollEvent(&event) || event.state != InputManager::PRESSED) continue; } else { event.button = input.waitForPressedButton(); } switch(event.button) { - case MENU: + case InputManager::MENU: close = true; break; - case UP: + case InputManager::UP: sel = max(0, sel-1); break; - case DOWN: + case InputManager::DOWN: sel = min((int)voices.size()-1, sel+1); break; - case ACCEPT: + case InputManager::ACCEPT: voices[sel].action(); close = true; break; @@ -1753,9 +1753,9 @@ void GMenu2X::editLink() { void GMenu2X::deleteLink() { if (menu->selLinkApp()!=NULL) { MessageBox mb(this, tr.translate("Deleting $1",menu->selLink()->getTitle().c_str(),NULL)+"\n"+tr["Are you sure?"], menu->selLink()->getIconPath()); - mb.setButton(ACCEPT, tr["Yes"]); - mb.setButton(CANCEL, tr["No"]); - if (mb.exec() == ACCEPT) { + mb.setButton(InputManager::ACCEPT, tr["Yes"]); + mb.setButton(InputManager::CANCEL, tr["No"]); + if (mb.exec() == InputManager::ACCEPT) { ledOn(); menu->deleteSelectedLink(); sync(); @@ -1818,9 +1818,9 @@ void GMenu2X::renameSection() { void GMenu2X::deleteSection() { MessageBox mb(this,tr["You will lose all the links in this section."]+"\n"+tr["Are you sure?"]); - mb.setButton(ACCEPT, tr["Yes"]); - mb.setButton(CANCEL, tr["No"]); - if (mb.exec() == ACCEPT) { + mb.setButton(InputManager::ACCEPT, tr["Yes"]); + mb.setButton(InputManager::CANCEL, tr["No"]); + if (mb.exec() == InputManager::ACCEPT) { ledOn(); if (rmtree(getHome() + "/sections/" + menu->selSection())) { menu->deleteSelectedSection(); @@ -1922,22 +1922,12 @@ void GMenu2X::scanner() { ledOff(); #endif - buttontype_t button; + InputManager::Button button; do { button = input.waitForPressedButton(); - } while ((button != SETTINGS) - && (button != ACCEPT) - && (button != CANCEL)); - - /* - bevent_t event; - do { - input.getEvent(&event, true); - } while ((event.state != PRESSED) || - ( (event.button != SETTINGS) - && (event.button != ACCEPT) - && (event.button != CLEAR))); - */ + } while ((button != InputManager::SETTINGS) + && (button != InputManager::ACCEPT) + && (button != InputManager::CANCEL)); } void GMenu2X::scanPath(string path, vector *files) { diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index 5ecd2ff..d1ca81f 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -161,33 +161,33 @@ bool InputDialog::exec() { gmenu2x->s->flip(); switch (inputMgr.waitForPressedButton()) { - case SETTINGS: + case InputManager::SETTINGS: ok = false; close = true; break; - case UP: + case InputManager::UP: selRow--; break; - case DOWN: + case InputManager::DOWN: selRow++; if (selRow==(int)kb->size()) selCol = selCol<8 ? 0 : 1; break; - case LEFT: + case InputManager::LEFT: selCol--; break; - case RIGHT: + case InputManager::RIGHT: selCol++; break; - case ACCEPT: + case InputManager::ACCEPT: confirm(); break; - case CANCEL: + case InputManager::CANCEL: changeKeys(); break; - case ALTLEFT: + case InputManager::ALTLEFT: backspace(); break; - case ALTRIGHT: + case InputManager::ALTRIGHT: space(); break; default: diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 7b9e5ba..4190c65 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -66,7 +66,7 @@ bool InputManager::readConfFile(const string &conffile) { string line, name, source; string::size_type pos; - buttontype_t button; + Button button; while(getline(inf, line, '\n')) { pos = line.find("="); @@ -95,42 +95,42 @@ bool InputManager::readConfFile(const string &conffile) { source = trim(line.substr(0,pos)); line = trim(line.substr(pos+1, line.length())); - if (source == "keyboard") ButtonMap[button].source = KEYBOARD; - else if (source == "joystick") ButtonMap[button].source = JOYSTICK; + if (source == "keyboard") buttonMap[button].source = KEYBOARD; + else if (source == "joystick") buttonMap[button].source = JOYSTICK; else return false; - ButtonMap[button].code = atoi(line.c_str()); + buttonMap[button].code = atoi(line.c_str()); } inf.close(); return true; } -buttontype_t InputManager::waitForPressedButton() { +InputManager::Button InputManager::waitForPressedButton() { return waitForButton(PRESSED); } -buttontype_t InputManager::waitForReleasedButton() { +InputManager::Button InputManager::waitForReleasedButton() { return waitForButton(RELEASED); } -buttontype_t InputManager::waitForButton(enum state_e state) { - bevent_t event; +InputManager::Button InputManager::waitForButton(ButtonState state) { + ButtonEvent event; do { waitForEvent(&event); } while (event.state != state); return event.button; } -void InputManager::waitForEvent(bevent_t *event) { +void InputManager::waitForEvent(ButtonEvent *event) { getEvent(event, true); } -bool InputManager::pollEvent(bevent_t *event) { +bool InputManager::pollEvent(ButtonEvent *event) { return getEvent(event, false); } -bool InputManager::getEvent(bevent_t *bevent, bool wait) { +bool InputManager::getEvent(ButtonEvent *bevent, bool wait) { //TODO: when an event is processed, program a new event //in some time, and when it occurs, do a key repeat @@ -145,7 +145,7 @@ bool InputManager::getEvent(bevent_t *bevent, bool wait) { } } - enum source_type_e source; + ButtonSource source; switch(event.type) { case SDL_KEYDOWN: bevent->state = PRESSED; @@ -168,18 +168,18 @@ bool InputManager::getEvent(bevent_t *bevent, bool wait) { } if (source == KEYBOARD) { - for (int i=0; ibutton = (buttontype_t)i; + for (int i = 0; i < BUTTON_TYPE_SIZE; i++) { + if (buttonMap[i].source == KEYBOARD + && (unsigned int)event.key.keysym.sym == buttonMap[i].code) { + bevent->button = static_cast