diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index 1bf74da..539733e 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -68,26 +68,40 @@ bool BrowseDialog::exec() return result; } -BrowseDialog::Action BrowseDialog::getAction() +BrowseDialog::Action BrowseDialog::getAction(bevent_t *event) { - BrowseDialog::Action action = BrowseDialog::ACT_NONE; + BrowseDialog::Action action; - if (gmenu2x->input[ACTION_SELECT]) - action = BrowseDialog::ACT_CLOSE; - else if (gmenu2x->input[ACTION_UP]) - action = BrowseDialog::ACT_UP; - else if (gmenu2x->input[ACTION_L]) - action = BrowseDialog::ACT_SCROLLUP; - else if (gmenu2x->input[ACTION_DOWN]) - action = BrowseDialog::ACT_DOWN; - else if (gmenu2x->input[ACTION_R]) - action = BrowseDialog::ACT_SCROLLDOWN; - else if (gmenu2x->input[ACTION_X] || gmenu2x->input[ACTION_LEFT]) - action = BrowseDialog::ACT_GOUP; - else if (gmenu2x->input[ACTION_B]) - action = BrowseDialog::ACT_SELECT; - else if (gmenu2x->input[ACTION_START]) - action = BrowseDialog::ACT_CONFIRM; + switch(event->button) { + case MENU: + action = BrowseDialog::ACT_CLOSE; + break; + case UP: + action = BrowseDialog::ACT_UP; + break; + case DOWN: + action = BrowseDialog::ACT_DOWN; + break; + case ALTLEFT: + action = BrowseDialog::ACT_SCROLLUP; + break; + case ALTRIGHT: + action = BrowseDialog::ACT_SCROLLDOWN; + break; + case LEFT: + case CLEAR: + action = BrowseDialog::ACT_GOUP; + break; + case ACCEPT: + action = BrowseDialog::ACT_SELECT; + break; + case SETTINGS: + action = BrowseDialog::ACT_CONFIRM; + break; + default: + action = BrowseDialog::ACT_NONE; + break; + } return action; } @@ -95,14 +109,22 @@ BrowseDialog::Action BrowseDialog::getAction() void BrowseDialog::handleInput() { BrowseDialog::Action action; + bevent_t event; - gmenu2x->input.update(); + do { + gmenu2x->input.waitForEvent(&event); + } while (event.state != PRESSED); + + /* + while(!gmenu2x->input.update()) + usleep(LOOP_DELAY); + */ if (ts_pressed && !gmenu2x->ts.pressed()) { action = BrowseDialog::ACT_SELECT; ts_pressed = false; } else { - action = getAction(); + action = getAction(&event); } if (gmenu2x->f200 && gmenu2x->ts.pressed() && !gmenu2x->ts.inRect(touchRect)) ts_pressed = false; diff --git a/src/browsedialog.h b/src/browsedialog.h index 91a91f6..2d71897 100644 --- a/src/browsedialog.h +++ b/src/browsedialog.h @@ -26,6 +26,7 @@ #include "gmenu2x.h" #include "buttonbox.h" #include "dialog.h" +#include "inputmanager.h" class FileLister; @@ -75,7 +76,7 @@ private: ButtonBox buttonBox; - Action getAction(); + Action getAction(bevent_t *event); void handleInput(); void paint(); diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 6b35880..f84fffe 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -522,9 +522,9 @@ void GMenu2X::viewLog() { td.exec(); MessageBox mb(this, tr["Do you want to delete the log file?"], "icons/ebook.png"); - mb.setButton(ACTION_B, tr["Yes"]); - mb.setButton(ACTION_X, tr["No"]); - if (mb.exec() == ACTION_B) { + mb.setButton(ACCEPT, tr["Yes"]); + mb.setButton(CLEAR, tr["No"]); + if (mb.exec() == ACCEPT) { ledOn(); unlink(logfile.c_str()); sync(); @@ -865,11 +865,13 @@ void GMenu2X::main() { drawScrollBar(linkRows,menu->sectionLinks()->size()/linkColumns + ((menu->sectionLinks()->size()%linkColumns==0) ? 0 : 1),menu->firstDispRow(),43,resY-81); + /* switch(volumeMode) { case VOLUME_MODE_MUTE: sc.skinRes("imgs/mute.png")->blit(s,279,bottomBarIconY); break; case VOLUME_MODE_PHONES: sc.skinRes("imgs/phones.png")->blit(s,279,bottomBarIconY); break; default: sc.skinRes("imgs/volume.png")->blit(s,279,bottomBarIconY); break; } + */ if (menu->selLink()!=NULL) { s->write ( font, menu->selLink()->getDescription(), halfX, resY-19, SFontHAlignCenter, SFontVAlignBottom ); @@ -902,8 +904,6 @@ void GMenu2X::main() { //s->write( font, tr[batstr.c_str()], 20, 170 ); //On Screen Help - if(input[ACTION_A] ) - helpDisplayed = ! helpDisplayed; if (helpDisplayed) { s->box(10,50,300,143, skinConfColors[COLOR_MESSAGE_BOX_BG]); @@ -965,13 +965,55 @@ void GMenu2X::main() { } //#ifdef TARGET_GP2X + + switch (input.waitForPressedButton()) { + case ACCEPT: + if (menu->selLink() != NULL) menu->selLink()->run(); + break; + case CANCEL: + helpDisplayed = ! helpDisplayed; + break; + case SETTINGS: + options(); + break; + case MENU: + contextMenu(); + break; + case UP: + menu->linkUp(); + break; + case DOWN: + menu->linkDown(); + break; + case LEFT: + menu->linkLeft(); + break; + case RIGHT: + menu->linkRight(); + break; + case MANUAL: + menu->selLinkApp()->showManual(); + break; + case ALTLEFT: + menu->decSectionIndex(); + offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; + break; + case ALTRIGHT: + menu->incSectionIndex(); + offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; + break; + default: + break; + } + + /* while (!input.update()) usleep(LOOP_DELAY); - if ( input[ACTION_B] && menu->selLink()!=NULL ) menu->selLink()->run(); - else if ( input[ACTION_START] ) options(); - else if ( input[ACTION_SELECT] ) contextMenu(); + if ( input[ACCEPT] && menu->selLink()!=NULL ) menu->selLink()->run(); + else if ( input[SETTINGS] ) options(); + else if ( input[MENU] ) contextMenu(); // VOLUME SCALE MODIFIER - else if ( fwType=="open2x" && input[ACTION_X] ) { + else if ( fwType=="open2x" && input[CLEAR] ) { volumeMode = constrain(volumeMode-1, -VOLUME_MODE_MUTE-1, VOLUME_MODE_NORMAL); if(volumeMode < VOLUME_MODE_MUTE) volumeMode = VOLUME_MODE_NORMAL; @@ -983,42 +1025,43 @@ void GMenu2X::main() { setVolume(confInt["globalVolume"]); } // LINK NAVIGATION - else if ( input[ACTION_LEFT ] ) menu->linkLeft(); - else if ( input[ACTION_RIGHT] ) menu->linkRight(); - else if ( input[ACTION_UP ] ) menu->linkUp(); - else if ( input[ACTION_DOWN ] ) menu->linkDown(); + else if ( input[ALTLEFTEFT ] ) menu->linkLeft(); + else if ( input[ALTRIGHTIGHT] ) menu->linkRight(); + else if ( input[UP ] ) menu->linkUp(); + else if ( input[DOWN ] ) menu->linkDown(); // SELLINKAPP SELECTED else if (menu->selLinkApp()!=NULL) { - if ( input[ACTION_Y] ) menu->selLinkApp()->showManual(); - else if ( input.isActive(ACTION_A) ) { + if ( input[MANUAL] ) menu->selLinkApp()->showManual(); + else if ( input.isActive(CANCEL) ) { // VOLUME - if ( input[ACTION_VOLDOWN] && !input.isActive(ACTION_VOLUP) ) + if ( input[VOLDOWN] && !input.isActive(VOLUP) ) menu->selLinkApp()->setVolume( constrain(menu->selLinkApp()->volume()-1,0,100) ); - if ( input[ACTION_VOLUP] && !input.isActive(ACTION_VOLDOWN) ) + if ( input[VOLUP] && !input.isActive(VOLDOWN) ) menu->selLinkApp()->setVolume( constrain(menu->selLinkApp()->volume()+1,0,100) );; - if ( input.isActive(ACTION_VOLUP) && input.isActive(ACTION_VOLDOWN) ) menu->selLinkApp()->setVolume(-1); + if ( input.isActive(VOLUP) && input.isActive(VOLDOWN) ) menu->selLinkApp()->setVolume(-1); } else { // CLOCK - if ( input[ACTION_VOLDOWN] && !input.isActive(ACTION_VOLUP) ) + if ( input[VOLDOWN] && !input.isActive(VOLUP) ) menu->selLinkApp()->setClock( constrain(menu->selLinkApp()->clock()-1,200,confInt["maxClock"]) ); - if ( input[ACTION_VOLUP] && !input.isActive(ACTION_VOLDOWN) ) + if ( input[VOLUP] && !input.isActive(VOLDOWN) ) menu->selLinkApp()->setClock( constrain(menu->selLinkApp()->clock()+1,200,confInt["maxClock"]) ); - if ( input.isActive(ACTION_VOLUP) && input.isActive(ACTION_VOLDOWN) ) menu->selLinkApp()->setClock(336); + if ( input.isActive(VOLUP) && input.isActive(VOLDOWN) ) menu->selLinkApp()->setClock(336); } } - if ( input.isActive(ACTION_A) ) { - if (input.isActive(ACTION_L) && input.isActive(ACTION_R)) + if ( input.isActive(CANCEL) ) { + if (input.isActive(ALTLEFT) && input.isActive(ALTRIGHT)) saveScreenshot(); } else { // SECTIONS - if ( input[ACTION_L ] ) { + if ( input[ALTLEFT ] ) { menu->decSectionIndex(); offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; - } else if ( input[ACTION_R ] ) { + } else if ( input[ALTRIGHT ] ) { menu->incSectionIndex(); offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; } } + */ } } @@ -1213,6 +1256,7 @@ void GMenu2X::setSkin(const string &skin, bool setWallpaper) { initFont(); } +/* void GMenu2X::activateSdUsb() { if (usbnet) { MessageBox mb(this,tr["Operation not permitted."]+"\n"+tr["You should disable Usb Networking to do this."]); @@ -1220,7 +1264,7 @@ void GMenu2X::activateSdUsb() { } else { system("scripts/usbon.sh sd"); MessageBox mb(this,tr["USB Enabled (SD)"],"icons/usb.png"); - mb.setButton(ACTION_B, tr["Turn off"]); + mb.setButton(ACCEPT, tr["Turn off"]); mb.exec(); system("scripts/usboff.sh sd"); } @@ -1233,7 +1277,7 @@ void GMenu2X::activateNandUsb() { } else { system("scripts/usbon.sh nand"); MessageBox mb(this,tr["USB Enabled (Nand)"],"icons/usb.png"); - mb.setButton(ACTION_B, tr["Turn off"]); + mb.setButton(ACCEPT, tr["Turn off"]); mb.exec(); system("scripts/usboff.sh nand"); } @@ -1246,12 +1290,12 @@ void GMenu2X::activateRootUsb() { } else { system("scripts/usbon.sh root"); MessageBox mb(this,tr["USB Enabled (Root)"],"icons/usb.png"); - mb.setButton(ACTION_B, tr["Turn off"]); + mb.setButton(ACCEPT, tr["Turn off"]); mb.exec(); system("scripts/usboff.sh root"); } } - +*/ void GMenu2X::contextMenu() { vector voices; { @@ -1307,6 +1351,8 @@ void GMenu2X::contextMenu() { bg.box(0, 0, resX, resY, 0,0,0,150); 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; while (!close) { tickNow = SDL_GetTicks(); @@ -1354,11 +1400,30 @@ void GMenu2X::contextMenu() { } } - input.update(); - if ( input[ACTION_SELECT] ) close = true; - if ( input[ACTION_UP ] ) sel = max(0, sel-1); - if ( input[ACTION_DOWN ] ) sel = min((int)voices.size()-1, sel+1); - if ( input[ACTION_B] ) { voices[sel].action(); close = true; } + + if (fadeAlpha < 200) { + if (!input.pollEvent(&event) || event.state != PRESSED) continue; + } else { + event.button = input.waitForPressedButton(); + } + + switch(event.button) { + case MENU: + close = true; + break; + case UP: + sel = max(0, sel-1); + break; + case DOWN: + sel = min((int)voices.size()-1, sel+1); + break; + case ACCEPT: + voices[sel].action(); + close = true; + break; + default: + break; + } } } @@ -1499,9 +1564,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(ACTION_B, tr["Yes"]); - mb.setButton(ACTION_X, tr["No"]); - if (mb.exec() == ACTION_B) { + mb.setButton(ACCEPT, tr["Yes"]); + mb.setButton(CLEAR, tr["No"]); + if (mb.exec() == ACCEPT) { ledOn(); menu->deleteSelectedLink(); sync(); @@ -1561,9 +1626,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(ACTION_B, tr["Yes"]); - mb.setButton(ACTION_X, tr["No"]); - if (mb.exec() == ACTION_B) { + mb.setButton(ACCEPT, tr["Yes"]); + mb.setButton(CLEAR, tr["No"]); + if (mb.exec() == ACCEPT) { ledOn(); if (rmtree(path+"sections/"+menu->selSection())) { menu->deleteSelectedSection(); @@ -1655,12 +1720,22 @@ void GMenu2X::scanner() { ledOff(); #endif - bool close = false; - while (!close) { - input.update(); - if (input[ACTION_START] || input[ACTION_B] || input[ACTION_X]) close = true; - usleep(30000); - } + buttontype_t button; + do { + button = input.waitForPressedButton(); + } while ((button != SETTINGS) + && (button != ACCEPT) + && (button != CLEAR)); + + /* + bevent_t event; + do { + input.getEvent(&event, true); + } while ((event.state != PRESSED) || + ( (event.button != SETTINGS) + && (event.button != ACCEPT) + && (event.button != CLEAR))); + */ } void GMenu2X::scanPath(string path, vector *files) { @@ -1754,18 +1829,20 @@ unsigned short GMenu2X::getBatteryLevel() { } void GMenu2X::setInputSpeed() { + /* input.setInterval(150); - input.setInterval(30, ACTION_VOLDOWN); - input.setInterval(30, ACTION_VOLUP ); - input.setInterval(30, ACTION_A ); - input.setInterval(500, ACTION_START ); - input.setInterval(500, ACTION_SELECT ); - input.setInterval(300, ACTION_X ); - input.setInterval(300, ACTION_Y ); - input.setInterval(1000,ACTION_B ); + input.setInterval(30, VOLDOWN); + input.setInterval(30, VOLUP ); + input.setInterval(30, CANCEL ); + input.setInterval(500, SETTINGS ); + input.setInterval(500, MENU ); + input.setInterval(300, CLEAR ); + input.setInterval(300, MANUAL ); + input.setInterval(1000,ACCEPT ); //joy.setInterval(1000,ACTION_CLICK ); - input.setInterval(300, ACTION_L ); - input.setInterval(300, ACTION_R ); + input.setInterval(300, ALTLEFT ); + input.setInterval(300, ALTRIGHT ); + */ SDL_EnableKeyRepeat(1,150); } diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index aa580b7..e74aca6 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -164,6 +164,43 @@ bool InputDialog::exec() { action = drawVirtualKeyboard(); gmenu2x->s->flip(); + switch (inputMgr.waitForPressedButton()) { + case SETTINGS: + ok = false; + close = true; + break; + case UP: + selRow--; + break; + case DOWN: + selRow++; + if (selRow==(int)kb->size()) selCol = selCol<8 ? 0 : 1; + break; + case LEFT: + selCol--; + break; + case RIGHT: + selCol++; + break; + case ACCEPT: + confirm(); + break; + case MANUAL: + changeKeys(); + break; + case CLEAR: + case ALTLEFT: + backspace(); + break; + case ALTRIGHT: + space(); + break; + default: + break; + } + + + /* inputMgr.update(); if ( inputMgr[ACTION_START] ) action = ID_ACTION_CLOSE; if ( inputMgr[ACTION_UP ] ) action = ID_ACTION_UP; @@ -198,6 +235,7 @@ bool InputDialog::exec() { case ID_ACTION_KB_CHANGE: changeKeys(); break; case ID_ACTION_SELECT: confirm(); break; } +*/ } return ok; diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 21be83a..a5c5a63 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -18,186 +18,167 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include -#include - +#include "debug.h" #include "inputmanager.h" #include "utilities.h" -#include "debug.h" -using namespace std; +#include +#include -InputManager::InputManager() {} - -InputManager::~InputManager() { - for (uint x=0; x values; - - while (getline(inf, line, '\n')) { - pos = line.find("="); - name = trim(line.substr(0,pos)); - value = trim(line.substr(pos+1,line.length())); - int action = -1; - - if (name=="up") action = ACTION_UP; - else if (name=="down") action = ACTION_DOWN; - else if (name=="left") action = ACTION_LEFT; - else if (name=="right") action = ACTION_RIGHT; - else if (name=="a") action = ACTION_A; - else if (name=="b") action = ACTION_B; - else if (name=="x") action = ACTION_X; - else if (name=="y") action = ACTION_Y; - else if (name=="l") action = ACTION_L; - else if (name=="r") action = ACTION_R; - else if (name=="start") action = ACTION_START; - else if (name=="select") action = ACTION_SELECT; - else if (name=="volup") action = ACTION_VOLUP; - else if (name=="voldown") action = ACTION_VOLDOWN; - - if (action >= 0) { - split(values, value, ","); - if (values.size() >= 2) { - - if (values[0] == "joystickbutton" && values.size()==3) { - InputMap map; - map.type = InputManager::MAPPING_TYPE_BUTTON; - map.num = atoi(values[1].c_str()); - map.value = atoi(values[2].c_str()); - map.treshold = 0; - mappings[action].push_back(map); - } else if (values[0] == "joystickaxys" && values.size()==4) { - InputMap map; - map.type = InputManager::MAPPING_TYPE_AXYS; - map.num = atoi(values[1].c_str()); - map.value = atoi(values[2].c_str()); - map.treshold = atoi(values[3].c_str()); - mappings[action].push_back(map); - } else if (values[0] == "keyboard") { - InputMap map; - map.type = InputManager::MAPPING_TYPE_KEYPRESS; - map.value = atoi(values[1].c_str()); - mappings[action].push_back(map); - } - - } - } - } - inf.close(); - } - } + if (!readConfFile(conffile)) + ERROR("InputManager initialization from config file failed.\n"); } -void InputManager::setActionsCount(int count) { - actions.clear(); - actionTick.clear(); - interval.clear(); - for (int x=0; xinterval[x]) { - actions[x] = true; - actionTick[x] = tick; - anyactions = true; - } - } else { - actionTick[x] = 0; - } - } - return anyactions; +InputManager::~InputManager() { + if (SDL_NumJoysticks > 0) + SDL_JoystickClose(joystick); } -int InputManager::count() { - return actions.size(); + +void InputManager::initJoystick() { + if (SDL_NumJoysticks > 0) + joystick = SDL_JoystickOpen(0); } -void InputManager::setInterval(int ms, int action) { - if (action<0) - for (uint x=0; x=actions.size()) return false; - return actions[action]; + +buttontype_t InputManager::waitForPressedButton() { + return waitForButton(PRESSED); } -bool InputManager::isActive(int action) { - MappingList mapList = mappings[action]; - for (MappingList::const_iterator it = mapList.begin(); it !=mapList.end(); ++it) { - InputMap map = *it; - switch (map.type) { - case InputManager::MAPPING_TYPE_BUTTON: - if (map.num < joysticks.size() && SDL_JoystickGetButton(joysticks[map.num], map.value)) - return true; - break; - case InputManager::MAPPING_TYPE_AXYS: - if (map.num < joysticks.size()) { - int axyspos = SDL_JoystickGetAxis(joysticks[map.num], map.value); - if (map.treshold<0 && axyspos < map.treshold) return true; - if (map.treshold>0 && axyspos > map.treshold) return true; - } - break; - case InputManager::MAPPING_TYPE_KEYPRESS: - for (uint ex=0; exstate = RELEASED; + if (!SDL_PollEvent(&event)) return false; + } + + enum source_type_e source; + + switch(event.type) { + case SDL_KEYDOWN: + bevent->state = PRESSED; + source = KEYBOARD; + break; + case SDL_KEYUP: + bevent->state = RELEASED; + source = KEYBOARD; + break; + case SDL_JOYBUTTONDOWN: + bevent->state = PRESSED; + source = JOYSTICK; + break; + case SDL_JOYBUTTONUP: + bevent->state = RELEASED; + source = JOYSTICK; + break; + default: + return false; + break; + } + + if (source == KEYBOARD) { + for (int i=0; ibutton = (buttontype_t)i; + break; + } + } else { + for (int i=0; ibutton = (buttontype_t)i; + break; + } + } + + return true; } diff --git a/src/inputmanager.h b/src/inputmanager.h index 0ea35c8..2a99451 100644 --- a/src/inputmanager.h +++ b/src/inputmanager.h @@ -17,73 +17,57 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef INPUTMANAGER_H -#define INPUTMANAGER_H +#ifndef NEWINPUT_H +#define NEWINPUT_H -#define ACTION_UP 0 -#define ACTION_DOWN 1 -#define ACTION_LEFT 2 -#define ACTION_RIGHT 3 -#define ACTION_A 4 -#define ACTION_B 5 -#define ACTION_X 6 -#define ACTION_Y 7 -#define ACTION_L 8 -#define ACTION_R 9 -#define ACTION_START 10 -#define ACTION_SELECT 11 -#define ACTION_VOLUP 12 -#define ACTION_VOLDOWN 13 +#include +#include -#include -#include -#include -#include +using namespace std; -using std::vector; -using std::string; +typedef enum buttontype_e { + UP, DOWN, LEFT, RIGHT, + ACCEPT, CANCEL, + CLEAR, MANUAL, + ALTLEFT, ALTRIGHT, + MENU, SETTINGS, + VOLUP, VOLDOWN, + POWER, LOCK +} buttontype_t; +#define BUTTONTYPE_T_SIZE 16 + +enum source_type_e {KEYBOARD, JOYSTICK}; +enum state_e {PRESSED, RELEASED}; typedef struct { - int type; - uint num; - int value; - int treshold; -} InputMap; + source_type_e source; + Uint32 code; +} input_t; + +typedef struct { + buttontype_t button; + state_e state; +} bevent_t; -typedef vector MappingList; -typedef vector SDLEventList; -/** -Manages all input peripherals -@author Massimiliano Torromeo -*/ class InputManager { private: - InputMap getInputMapping(int action); - vector actionTick; - vector interval; - SDLEventList events; + input_t ButtonMap[BUTTONTYPE_T_SIZE]; - vector joysticks; - vector actions; - vector mappings; + bool readConfFile(const string &conffile); + void initJoystick(); + bool getEvent(bevent_t *bevent, bool wait); + buttontype_t waitForButton(enum state_e state); public: - static const int MAPPING_TYPE_UNDEFINED = -1; - static const int MAPPING_TYPE_BUTTON = 0; - static const int MAPPING_TYPE_AXYS = 1; - static const int MAPPING_TYPE_KEYPRESS = 2; + InputManager(); + ~InputManager(); - InputManager(); - ~InputManager(); - void init(const string &conffile = "input.conf"); - - bool update(); - int count(); - void setActionsCount(int count); - void setInterval(int ms, int action = -1); - bool operator[](int action); - bool isActive(int action); + void init(const string &conffile); + void waitForEvent(bevent_t *event); + buttontype_t waitForPressedButton(); + buttontype_t waitForReleasedButton(); + bool pollEvent(bevent_t *event); }; #endif diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 6b5f847..78fb890 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -333,11 +333,28 @@ void LinkApp::showManual() { repaint = false; } - inputMgr.update(); - if ( inputMgr[ACTION_Y] || inputMgr[ACTION_X] || inputMgr[ACTION_START] ) close = true; - if ( inputMgr[ACTION_LEFT] && page>0 ) { page--; repaint=true; } - if ( inputMgr[ACTION_RIGHT] && page 0) { + page--; + repaint = true; + } + break; + case RIGHT: + if (page < pagecount-1) { + page++; + repaint=true; + } + break; + default: + break; + } + } return; } diff --git a/src/menusetting.h b/src/menusetting.h index ceb8b54..30ae88b 100644 --- a/src/menusetting.h +++ b/src/menusetting.h @@ -21,6 +21,7 @@ #define MENUSETTING_H #include "buttonbox.h" +#include "inputmanager.h" #include @@ -46,7 +47,7 @@ public: virtual void draw(int y); virtual void handleTS(); - virtual void manageInput() = 0; + virtual void manageInput(bevent_t *event) = 0; virtual void adjustInput(); virtual void drawSelected(int y); virtual bool edited() = 0; diff --git a/src/menusettingbool.cpp b/src/menusettingbool.cpp index d25f527..5d2fdff 100644 --- a/src/menusettingbool.cpp +++ b/src/menusettingbool.cpp @@ -64,10 +64,10 @@ void MenuSettingBool::draw(int y) gmenu2x->s->write( gmenu2x->font, strvalue, 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); } -void MenuSettingBool::manageInput() +void MenuSettingBool::manageInput(bevent_t *event) { - if (gmenu2x->input[ACTION_B]) - toggle(); + if (event->button == ACCEPT && event->state == PRESSED) + toggle(); } void MenuSettingBool::toggle() diff --git a/src/menusettingbool.h b/src/menusettingbool.h index 65738d1..967242e 100644 --- a/src/menusettingbool.h +++ b/src/menusettingbool.h @@ -21,6 +21,7 @@ #define MENUSETTINGBOOL_H #include "menusetting.h" +#include "inputmanager.h" class GMenu2X; @@ -44,7 +45,7 @@ public: virtual ~MenuSettingBool() {} virtual void draw(int y); - virtual void manageInput(); + virtual void manageInput(bevent_t *event); virtual bool edited(); void setValue(int value); diff --git a/src/menusettingint.cpp b/src/menusettingint.cpp index b7faad7..005532c 100644 --- a/src/menusettingint.cpp +++ b/src/menusettingint.cpp @@ -65,12 +65,18 @@ void MenuSettingInt::draw(int y) gmenu2x->s->write( gmenu2x->font, strvalue, 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); } -void MenuSettingInt::manageInput() +void MenuSettingInt::manageInput(bevent_t *event) { - if (gmenu2x->input[ACTION_LEFT ] || gmenu2x->input[ACTION_X]) - dec(); - if (gmenu2x->input[ACTION_RIGHT] || gmenu2x->input[ACTION_Y]) - inc(); + switch (event->button) { + case LEFT: + dec(); + break; + case RIGHT: + inc(); + break; + default: + break; + } } void MenuSettingInt::inc() @@ -100,8 +106,8 @@ int MenuSettingInt::value() void MenuSettingInt::adjustInput() { #ifdef TARGET_GP2X - gmenu2x->input.setInterval(30, ACTION_LEFT ); - gmenu2x->input.setInterval(30, ACTION_RIGHT); +// gmenu2x->input.setInterval(30, ACTION_LEFT ); +// gmenu2x->input.setInterval(30, ACTION_RIGHT); #endif } diff --git a/src/menusettingint.h b/src/menusettingint.h index 153c800..f7fe48d 100644 --- a/src/menusettingint.h +++ b/src/menusettingint.h @@ -21,6 +21,7 @@ #define MENUSETTINGINT_H #include "menusetting.h" +#include "inputmanager.h" class MenuSettingInt : public MenuSetting { private: @@ -38,7 +39,7 @@ public: const std::string &description, int *value, int min, int max); virtual ~MenuSettingInt() {} - virtual void manageInput(); + virtual void manageInput(bevent_t *event); virtual void adjustInput(); virtual void draw(int); virtual bool edited(); diff --git a/src/menusettingmultistring.cpp b/src/menusettingmultistring.cpp index eda8059..394d0d7 100644 --- a/src/menusettingmultistring.cpp +++ b/src/menusettingmultistring.cpp @@ -49,10 +49,18 @@ MenuSettingMultiString::MenuSettingMultiString( buttonBox.add(btn); } -void MenuSettingMultiString::manageInput() +void MenuSettingMultiString::manageInput(bevent_t *event) { - if (gmenu2x->input[ACTION_LEFT ]) decSel(); - if (gmenu2x->input[ACTION_RIGHT]) incSel(); + switch(event->button) { + case LEFT: + decSel(); + break; + case RIGHT: + incSel(); + break; + default: + break; + } } void MenuSettingMultiString::incSel() diff --git a/src/menusettingmultistring.h b/src/menusettingmultistring.h index 4340c9b..6b03c47 100644 --- a/src/menusettingmultistring.h +++ b/src/menusettingmultistring.h @@ -21,6 +21,7 @@ #define MENUSETTINGMULTISTRING_H #include "menusettingstringbase.h" +#include "inputmanager.h" #include @@ -44,7 +45,7 @@ public: const std::vector *choices); virtual ~MenuSettingMultiString() {}; - virtual void manageInput(); + virtual void manageInput(bevent_t *event); }; #endif diff --git a/src/menusettingrgba.cpp b/src/menusettingrgba.cpp index 8ebaf76..e940d20 100644 --- a/src/menusettingrgba.cpp +++ b/src/menusettingrgba.cpp @@ -82,15 +82,23 @@ void MenuSettingRGBA::handleTS() { MenuSetting::handleTS(); } -void MenuSettingRGBA::manageInput() { - if (gmenu2x->input[ACTION_Y]) - inc(); - if (gmenu2x->input[ACTION_X]) - dec(); - if (gmenu2x->input[ACTION_LEFT]) - leftComponent(); - if (gmenu2x->input[ACTION_RIGHT]) - rightComponent(); +void MenuSettingRGBA::manageInput(bevent_t *event) { + switch(event->button) { + case MANUAL: + inc(); + break; + case CLEAR: + dec(); + break; + case LEFT: + leftComponent(); + break; + case RIGHT: + rightComponent(); + break; + default: + break; + } } void MenuSettingRGBA::dec() @@ -173,9 +181,11 @@ unsigned short MenuSettingRGBA::getSelPart() void MenuSettingRGBA::adjustInput() { #ifdef TARGET_GP2X + /* gmenu2x->input.setInterval(30, ACTION_Y ); gmenu2x->input.setInterval(30, ACTION_X ); gmenu2x->input.setInterval(30, ACTION_L ); + */ #endif } diff --git a/src/menusettingrgba.h b/src/menusettingrgba.h index 72453db..9c3d0e0 100644 --- a/src/menusettingrgba.h +++ b/src/menusettingrgba.h @@ -22,6 +22,7 @@ #include "menusetting.h" #include "surface.h" +#include "inputmanager.h" class GMenu2X; @@ -46,7 +47,7 @@ public: virtual void draw(int y); virtual void handleTS(); - virtual void manageInput(); + virtual void manageInput(bevent_t *event); virtual void adjustInput(); virtual void drawSelected(int y); virtual bool edited(); diff --git a/src/menusettingstringbase.cpp b/src/menusettingstringbase.cpp index 245ce77..aaab5c0 100644 --- a/src/menusettingstringbase.cpp +++ b/src/menusettingstringbase.cpp @@ -44,10 +44,18 @@ void MenuSettingStringBase::draw(int y) SFontHAlignLeft, SFontVAlignMiddle); } -void MenuSettingStringBase::manageInput() +void MenuSettingStringBase::manageInput(bevent_t *event) { - if (gmenu2x->input[ACTION_X]) clear(); - if (gmenu2x->input[ACTION_B]) edit(); + switch (event->button) { + case CLEAR: + clear(); + break; + case ACCEPT: + edit(); + break; + default: + break; + } } void MenuSettingStringBase::clear() diff --git a/src/menusettingstringbase.h b/src/menusettingstringbase.h index 396bab8..c92c785 100644 --- a/src/menusettingstringbase.h +++ b/src/menusettingstringbase.h @@ -21,6 +21,7 @@ #define MENUSETTINGSTRINGBASE_H #include "menusetting.h" +#include "inputmanager.h" class MenuSettingStringBase : public MenuSetting { protected: @@ -37,7 +38,7 @@ public: virtual ~MenuSettingStringBase(); virtual void draw(int y); - virtual void manageInput(); + virtual void manageInput(bevent_t *event); virtual bool edited(); void setValue(const std::string &value) { *_value = value; } diff --git a/src/messagebox.cpp b/src/messagebox.cpp index de36db8..95cebce 100644 --- a/src/messagebox.cpp +++ b/src/messagebox.cpp @@ -40,23 +40,23 @@ MessageBox::MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon) } //Default enabled button - buttons[ACTION_B] = "OK"; + buttons[ACCEPT] = "OK"; //Default labels - buttonLabels[ACTION_UP] = "up"; - buttonLabels[ACTION_DOWN] = "down"; - buttonLabels[ACTION_LEFT] = "left"; - buttonLabels[ACTION_RIGHT] = "right"; - buttonLabels[ACTION_A] = "a"; - buttonLabels[ACTION_B] = "b"; - buttonLabels[ACTION_X] = "x"; - buttonLabels[ACTION_Y] = "y"; - buttonLabels[ACTION_L] = "l"; - buttonLabels[ACTION_R] = "r"; - buttonLabels[ACTION_START] = "start"; - buttonLabels[ACTION_SELECT] = "select"; - buttonLabels[ACTION_VOLUP] = "vol+"; - buttonLabels[ACTION_VOLDOWN] = "vol-"; + buttonLabels[UP] = "up"; + buttonLabels[DOWN] = "down"; + buttonLabels[LEFT] = "left"; + buttonLabels[RIGHT] = "right"; + buttonLabels[CANCEL] = "a"; + buttonLabels[ACCEPT] = "b"; + buttonLabels[CLEAR] = "x"; + buttonLabels[MANUAL] = "y"; + buttonLabels[ALTLEFT] = "l"; + buttonLabels[ALTRIGHT] = "r"; + buttonLabels[SETTINGS] = "start"; + buttonLabels[MENU] = "select"; + buttonLabels[VOLUP] = "vol+"; + buttonLabels[VOLDOWN] = "vol-"; } void MessageBox::setButton(int action, const string &btn) { @@ -102,6 +102,7 @@ int MessageBox::exec() { bg.blit(gmenu2x->s,0,0); gmenu2x->s->flip(); + bevent_t event; while (result<0) { //touchscreen if (gmenu2x->f200) { @@ -113,11 +114,15 @@ int MessageBox::exec() { } } } - +/* gmenu2x->input.update(); for (uint i=0; iinput[i]) result = i; + */ + + if (gmenu2x->input.pollEvent(&event) && (event.state == PRESSED) && (buttons[event.button] != "")) result = event.button; + usleep(LOOP_DELAY); } diff --git a/src/selector.cpp b/src/selector.cpp index b49cdb2..21d4f6a 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -115,7 +115,65 @@ int Selector::exec(int startSelection) { gmenu2x->drawScrollBar(SELECTOR_ELEMENTS,fl.size(),firstElement,42,175); gmenu2x->s->flip(); + switch (gmenu2x->input.waitForPressedButton()) { + case SETTINGS: + close = true; + result = false; + break; + case UP: + if (selected == 0) selected = fl.size() -1; + else selected -= 1; + selTick = SDL_GetTicks(); + break; + case ALTLEFT: + if ((int)(selected-SELECTOR_ELEMENTS+1)<0) selected = 0; + else selected -= SELECTOR_ELEMENTS-1; + selTick = SDL_GetTicks(); + break; + case DOWN: + if (selected+1>=fl.size()) selected = 0; + else selected += 1; + selTick = SDL_GetTicks(); + break; + case ALTRIGHT: + if (selected+SELECTOR_ELEMENTS-1>=fl.size()) selected = fl.size()-1; + else selected += SELECTOR_ELEMENTS-1; + selTick = SDL_GetTicks(); + break; + case CLEAR: + if (link->getSelectorBrowser()) { + string::size_type p = dir.rfind("/", dir.size()-2); + if (p==string::npos || dir.compare(0, 1, "/") != 0 || dir.length() < 2) { + close = true; + result = false; + } else { + dir = dir.substr(0,p+1); + INFO("%s\n", dir.c_str()); + selected = 0; + firstElement = 0; + prepare(&fl,&screens,&titles); + } + } else { + close = true; + result = false; + } + break; + case ACCEPT: + if (fl.isFile(selected)) { + file = fl[selected]; + close = true; + } else { + dir = dir+fl[selected]+"/"; + selected = 0; + firstElement = 0; + prepare(&fl,&screens,&titles); + } + break; + default: + break; + } + /* gmenu2x->input.update(); if ( gmenu2x->input[ACTION_START] ) { close = true; result = false; } if ( gmenu2x->input[ACTION_UP] ) { @@ -179,6 +237,7 @@ int Selector::exec(int startSelection) { prepare(&fl,&screens,&titles); } } + */ } gmenu2x->sc.defaultAlpha = true; freeScreenshots(&screens); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 7f97143..5a0ac9c 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -105,11 +105,39 @@ bool SettingsDialog::exec() { gmenu2x->s->flip(); voices[sel]->handleTS(); + bevent_t event; + do { + inputMgr.waitForEvent(&event); + } while (event.state != PRESSED); + + switch (event.button) { + case SETTINGS: + close = true; + break; + case UP: + if (sel==0) + sel = voices.size()-1; + else + sel -= 1; + gmenu2x->setInputSpeed(); + voices[sel]->adjustInput(); + break; + case DOWN: + sel += 1; + if (sel>=voices.size()) sel = 0; + gmenu2x->setInputSpeed(); + voices[sel]->adjustInput(); + break; + default: + voices[sel]->manageInput(&event); + break; + } + + /* inputMgr.update(); if ( inputMgr[ACTION_START] ) action = SD_ACTION_CLOSE; if ( inputMgr[ACTION_UP ] ) action = SD_ACTION_UP; if ( inputMgr[ACTION_DOWN ] ) action = SD_ACTION_DOWN; - voices[sel]->manageInput(); switch (action) { case SD_ACTION_CLOSE: close = true; break; @@ -128,6 +156,7 @@ bool SettingsDialog::exec() { voices[sel]->adjustInput(); } break; } + */ } gmenu2x->setInputSpeed(); diff --git a/src/textdialog.cpp b/src/textdialog.cpp index 40000e7..4d12134 100644 --- a/src/textdialog.cpp +++ b/src/textdialog.cpp @@ -116,7 +116,30 @@ void TextDialog::exec() { drawText(text, firstRow, rowsPerPage); gmenu2x->s->flip(); + switch(gmenu2x->input.waitForPressedButton()) { + case UP: + if (firstRow > 0) firstRow--; + break; + case DOWN: + if (firstRow + rowsPerPage < text->size()) firstRow++; + break; + case ALTLEFT: + if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1; + else firstRow = 0; + break; + case ALTRIGHT: + if (firstRow + rowsPerPage*2 -1 < text->size()) firstRow += rowsPerPage-1; + else firstRow = max(0, text->size() - rowsPerPage); + break; + case SETTINGS: + case CLEAR: + close = true; + break; + default: + break; + } + /* gmenu2x->input.update(); if ( gmenu2x->input[ACTION_UP ] && firstRow>0 ) firstRow--; if ( gmenu2x->input[ACTION_DOWN] && firstRow+rowsPerPagesize() ) firstRow++; @@ -133,5 +156,6 @@ void TextDialog::exec() { firstRow = max(0,text->size()-rowsPerPage); } if ( gmenu2x->input[ACTION_START] || gmenu2x->input[ACTION_X] ) close = true; + */ } } diff --git a/src/textmanualdialog.cpp b/src/textmanualdialog.cpp index 5a1595a..2bceb4f 100644 --- a/src/textmanualdialog.cpp +++ b/src/textmanualdialog.cpp @@ -86,6 +86,7 @@ void TextManualDialog::exec() { string spagecount; ss >> spagecount; string pageStatus; + while (!close) { bg.blit(gmenu2x->s,0,0); writeSubTitle(pages[page].title); @@ -99,6 +100,42 @@ void TextManualDialog::exec() { gmenu2x->s->flip(); + switch(gmenu2x->input.waitForPressedButton()) { + case UP: + if (firstRow > 0) firstRow--; + break; + case DOWN: + if (firstRow + rowsPerPage < pages[page].text.size()) firstRow++; + break; + case LEFT: + if (page > 0) { + page--; + firstRow = 0; + } + break; + case RIGHT: + if (page < pages.size() -1) { + page++; + firstRow = 0; + } + break; + case ALTLEFT: + if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1; + else firstRow = 0; + break; + case ALTRIGHT: + if (firstRow + rowsPerPage*2 -1 < pages[page].text.size()) firstRow += rowsPerPage-1; + else firstRow = max(0, pages[page].text.size() - rowsPerPage); + break; + case SETTINGS: + case CLEAR: + close = true; + break; + default: + break; + } + + /* gmenu2x->input.update(); if ( gmenu2x->input[ACTION_UP ] && firstRow>0 ) firstRow--; if ( gmenu2x->input[ACTION_DOWN ] && firstRow+rowsPerPageinput[ACTION_START] || gmenu2x->input[ACTION_X] ) close = true; + */ } } diff --git a/src/wallpaperdialog.cpp b/src/wallpaperdialog.cpp index 7f98e08..91d73ea 100644 --- a/src/wallpaperdialog.cpp +++ b/src/wallpaperdialog.cpp @@ -51,6 +51,7 @@ bool WallpaperDialog::exec() DEBUG("Wallpapers: %i\n", wallpapers.size()); uint i, selected = 0, firstElement = 0, iY; + while (!close) { if (selected>firstElement+9) firstElement=selected-9; if (selecteddrawScrollBar(10,wallpapers.size(),firstElement,44,170); gmenu2x->s->flip(); - - gmenu2x->input.update(); - if ( gmenu2x->input[ACTION_SELECT] ) { close = true; result = false; } - if ( gmenu2x->input[ACTION_UP ] ) { - if (selected==0) - selected = wallpapers.size()-1; - else - selected -= 1; - } - if ( gmenu2x->input[ACTION_L ] ) { - if ((int)(selected-9)<0) { - selected = 0; - } else { - selected -= 9; - } - } - if ( gmenu2x->input[ACTION_DOWN ] ) { - if (selected+1>=wallpapers.size()) - selected = 0; - else - selected += 1; - } - if ( gmenu2x->input[ACTION_R ] ) { - if (selected+9>=wallpapers.size()) { - selected = wallpapers.size()-1; - } else { - selected += 9; - } - } - if ( gmenu2x->input[ACTION_X] ) { - close = true; - result = false; - } - if ( gmenu2x->input[ACTION_B] ) { - close = true; - if (wallpapers.size()>0) { - if (selectedconfStr["skin"]+"/wallpapers/"+wallpapers[selected]; - else - wallpaper = "skins/Default/wallpapers/"+wallpapers[selected]; - } else result = false; - } + switch(gmenu2x->input.waitForPressedButton()) { + case MENU: + case CLEAR: + close = true; + result = false; + break; + case UP: + if (selected == 0) selected = wallpapers.size()-1; + else selected -= 1; + break; + case ALTLEFT: + if ((int)(selected-9) < 0) selected = 0; + else selected -= 9; + break; + case DOWN: + if (selected+1 >= wallpapers.size()) selected = 0; + else selected += 1; + break; + case ALTRIGHT: + if (selected+9 >= wallpapers.size()) selected = wallpapers.size()-1; + else selected += 9; + break; + case ACCEPT: + close = true; + if (wallpapers.size() > 0) { + if (selected < wallpapers.size() - fl.getFiles().size()) + wallpaper = "skins/" + gmenu2x->confStr["skin"] + "/wallpapers/" + wallpapers[selected]; + else + wallpaper = "skins/Default/wallpapers/" + wallpapers[selected]; + } else result = false; + default: + break; + } } for (uint i=0; i