From d03dbea9bdfbc0068794154e0109f54547e47920 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 27 Jul 2010 22:56:03 +0200 Subject: [PATCH] Give InputDialog a direct reference to the Touchscreen and InputManager objects instead of fetching them from the GMenu2X object. --- src/gmenu2x.cpp | 4 ++-- src/inputdialog.cpp | 39 +++++++++++++++++++++------------------ src/inputdialog.h | 7 ++++++- src/menusettingstring.cpp | 3 ++- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index a08c628..9eabb70 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -1513,7 +1513,7 @@ void GMenu2X::deleteLink() { } void GMenu2X::addSection() { - InputDialog id(this,tr["Insert a name for the new section"]); + InputDialog id(this, input, ts, tr["Insert a name for the new section"]); if (id.exec()) { //only if a section with the same name does not exist if (find(menu->getSections().begin(), menu->getSections().end(), id.getInput()) @@ -1530,7 +1530,7 @@ void GMenu2X::addSection() { } void GMenu2X::renameSection() { - InputDialog id(this,tr["Insert a new name for this section"],menu->selSection()); + InputDialog id(this, input, ts, tr["Insert a new name for this section"],menu->selSection()); if (id.exec()) { //only if a section with the same name does not exist & !samename if (menu->selSection() != id.getInput() diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index 17bc5e3..aa580b7 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -26,9 +26,12 @@ using namespace std; using namespace fastdelegate; -InputDialog::InputDialog(GMenu2X *gmenu2x, const string &text, - const string &startvalue, const string &title, const string &icon) : - Dialog(gmenu2x) +InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_, + Touchscreen &ts_, const string &text, + const string &startvalue, const string &title, const string &icon) + : Dialog(gmenu2x) + , inputMgr(inputMgr_) + , ts(ts_) { if (title=="") { this->title = text; @@ -157,20 +160,20 @@ bool InputDialog::exec() { if (caretOn) gmenu2x->s->box(box.x+box.w-12, box.y+3, 8, box.h-6, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - if (gmenu2x->f200) gmenu2x->ts.poll(); + if (gmenu2x->f200) ts.poll(); action = drawVirtualKeyboard(); gmenu2x->s->flip(); - gmenu2x->input.update(); - if ( gmenu2x->input[ACTION_START] ) action = ID_ACTION_CLOSE; - if ( gmenu2x->input[ACTION_UP ] ) action = ID_ACTION_UP; - if ( gmenu2x->input[ACTION_DOWN ] ) action = ID_ACTION_DOWN; - if ( gmenu2x->input[ACTION_LEFT ] ) action = ID_ACTION_LEFT; - if ( gmenu2x->input[ACTION_RIGHT] ) action = ID_ACTION_RIGHT; - if ( gmenu2x->input[ACTION_B] ) action = ID_ACTION_SELECT; - if ( gmenu2x->input[ACTION_Y] ) action = ID_ACTION_KB_CHANGE; - if ( gmenu2x->input[ACTION_X] || gmenu2x->input[ACTION_L] ) action = ID_ACTION_BACKSPACE; - if ( gmenu2x->input[ACTION_R ] ) action = ID_ACTION_SPACE; + inputMgr.update(); + if ( inputMgr[ACTION_START] ) action = ID_ACTION_CLOSE; + if ( inputMgr[ACTION_UP ] ) action = ID_ACTION_UP; + if ( inputMgr[ACTION_DOWN ] ) action = ID_ACTION_DOWN; + if ( inputMgr[ACTION_LEFT ] ) action = ID_ACTION_LEFT; + if ( inputMgr[ACTION_RIGHT] ) action = ID_ACTION_RIGHT; + if ( inputMgr[ACTION_B] ) action = ID_ACTION_SELECT; + if ( inputMgr[ACTION_Y] ) action = ID_ACTION_KB_CHANGE; + if ( inputMgr[ACTION_X] || inputMgr[ACTION_L] ) action = ID_ACTION_BACKSPACE; + if ( inputMgr[ACTION_R ] ) action = ID_ACTION_SPACE; switch (action) { case ID_ACTION_CLOSE: { @@ -270,7 +273,7 @@ int InputDialog::drawVirtualKeyboard() { SDL_Rect re = {kbLeft+xc*KEY_WIDTH-1, KB_TOP+l*KEY_HEIGHT, KEY_WIDTH-1, KEY_HEIGHT-2}; //if ts on rect, change selection - if (gmenu2x->f200 && gmenu2x->ts.pressed() && gmenu2x->ts.inRect(re)) { + if (gmenu2x->f200 && ts.pressed() && ts.inRect(re)) { selCol = xc; selRow = l; } @@ -284,7 +287,7 @@ int InputDialog::drawVirtualKeyboard() { //Ok/Cancel SDL_Rect re = {kbLeft-1, KB_TOP+kb->size()*KEY_HEIGHT, kbLength*KEY_WIDTH/2-1, KEY_HEIGHT-1}; gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - if (gmenu2x->f200 && gmenu2x->ts.pressed() && gmenu2x->ts.inRect(re)) { + if (gmenu2x->f200 && ts.pressed() && ts.inRect(re)) { selCol = 0; selRow = kb->size(); } @@ -292,14 +295,14 @@ int InputDialog::drawVirtualKeyboard() { re.x = kbLeft+kbLength*KEY_WIDTH/2-1; gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - if (gmenu2x->f200 && gmenu2x->ts.pressed() && gmenu2x->ts.inRect(re)) { + if (gmenu2x->f200 && ts.pressed() && ts.inRect(re)) { selCol = 1; selRow = kb->size(); } gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["OK"], (int)(160+kbLength*KEY_WIDTH/4), KB_TOP+kb->size()*KEY_HEIGHT+KEY_HEIGHT/2, SFontHAlignCenter, SFontVAlignMiddle); //if ts released - if (gmenu2x->f200 && gmenu2x->ts.released() && gmenu2x->ts.inRect(kbRect)) { + if (gmenu2x->f200 && ts.released() && ts.inRect(kbRect)) { action = ID_ACTION_SELECT; } diff --git a/src/inputdialog.h b/src/inputdialog.h index 9b311c9..4d9d2c2 100644 --- a/src/inputdialog.h +++ b/src/inputdialog.h @@ -46,8 +46,13 @@ using std::vector; typedef vector stringlist; +class InputManager; +class Touchscreen; + class InputDialog : protected Dialog { private: + InputManager &inputMgr; + Touchscreen &ts; int selRow, selCol; bool close, ok; string title, text, icon; @@ -68,7 +73,7 @@ private: void setKeyboard(int); public: - InputDialog(GMenu2X *gmenu2x, const string &text, const string &startvalue="", const string &title="", const string &icon=""); + InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr, Touchscreen &ts, const string &text, const string &startvalue="", const string &title="", const string &icon=""); bool exec(); const string &getInput() { return input; } diff --git a/src/menusettingstring.cpp b/src/menusettingstring.cpp index 04e3347..053bd65 100644 --- a/src/menusettingstring.cpp +++ b/src/menusettingstring.cpp @@ -76,7 +76,8 @@ void MenuSettingString::clear() void MenuSettingString::edit() { - InputDialog id(gmenu2x,description,value(), diagTitle,diagIcon); + InputDialog id(gmenu2x, gmenu2x->input, gmenu2x->ts, + description, value(), diagTitle, diagIcon); if (id.exec()) setValue(id.getInput()); }