1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-27 11:49:54 +02:00

InputManager: C++-style type definitions.

There is no need to typedef enums and structs in C++.
Put types defined by InputManager inside the class namespace.
Changed type names to CamelCase.
This commit is contained in:
Maarten ter Huurne 2011-10-23 08:57:52 +02:00
parent c6db9ff21b
commit 315bf0a180
24 changed files with 265 additions and 321 deletions

View File

@ -73,34 +73,34 @@ bool BrowseDialog::exec()
return result; return result;
} }
BrowseDialog::Action BrowseDialog::getAction(bevent_t *event) BrowseDialog::Action BrowseDialog::getAction(InputManager::ButtonEvent *event)
{ {
BrowseDialog::Action action; BrowseDialog::Action action;
switch(event->button) { switch(event->button) {
case MENU: case InputManager::MENU:
action = BrowseDialog::ACT_CLOSE; action = BrowseDialog::ACT_CLOSE;
break; break;
case UP: case InputManager::UP:
action = BrowseDialog::ACT_UP; action = BrowseDialog::ACT_UP;
break; break;
case DOWN: case InputManager::DOWN:
action = BrowseDialog::ACT_DOWN; action = BrowseDialog::ACT_DOWN;
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
action = BrowseDialog::ACT_SCROLLUP; action = BrowseDialog::ACT_SCROLLUP;
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
action = BrowseDialog::ACT_SCROLLDOWN; action = BrowseDialog::ACT_SCROLLDOWN;
break; break;
case LEFT: case InputManager::LEFT:
case CANCEL: case InputManager::CANCEL:
action = BrowseDialog::ACT_GOUP; action = BrowseDialog::ACT_GOUP;
break; break;
case ACCEPT: case InputManager::ACCEPT:
action = BrowseDialog::ACT_SELECT; action = BrowseDialog::ACT_SELECT;
break; break;
case SETTINGS: case InputManager::SETTINGS:
action = BrowseDialog::ACT_CONFIRM; action = BrowseDialog::ACT_CONFIRM;
break; break;
default: default:
@ -114,16 +114,11 @@ BrowseDialog::Action BrowseDialog::getAction(bevent_t *event)
void BrowseDialog::handleInput() void BrowseDialog::handleInput()
{ {
BrowseDialog::Action action; BrowseDialog::Action action;
bevent_t event; InputManager::ButtonEvent event;
do { do {
gmenu2x->input.waitForEvent(&event); gmenu2x->input.waitForEvent(&event);
} while (event.state != PRESSED); } while (event.state != InputManager::PRESSED);
/*
while(!gmenu2x->input.update())
usleep(LOOP_DELAY);
*/
if (ts_pressed && !gmenu2x->ts.pressed()) { if (ts_pressed && !gmenu2x->ts.pressed()) {
action = BrowseDialog::ACT_SELECT; action = BrowseDialog::ACT_SELECT;

View File

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

View File

@ -649,9 +649,9 @@ void GMenu2X::viewLog() {
td.exec(); td.exec();
MessageBox mb(this, tr["Do you want to delete the log file?"], "icons/ebook.png"); MessageBox mb(this, tr["Do you want to delete the log file?"], "icons/ebook.png");
mb.setButton(ACCEPT, tr["Yes"]); mb.setButton(InputManager::ACCEPT, tr["Yes"]);
mb.setButton(CANCEL, tr["No"]); mb.setButton(InputManager::CANCEL, tr["No"]);
if (mb.exec() == ACCEPT) { if (mb.exec() == InputManager::ACCEPT) {
ledOn(); ledOn();
unlink(logfile.c_str()); unlink(logfile.c_str());
sync(); sync();
@ -1089,7 +1089,7 @@ void GMenu2X::main() {
if (fwType=="open2x") s->write( font, tr["X: Toggle speaker mode"], 20, 185 ); if (fwType=="open2x") s->write( font, tr["X: Toggle speaker mode"], 20, 185 );
#endif #endif
s->flip(); s->flip();
while (input.waitForPressedButton() != CANCEL) {} while (input.waitForPressedButton() != InputManager::CANCEL) {}
helpDisplayed=false; helpDisplayed=false;
continue; continue;
} }
@ -1138,35 +1138,35 @@ void GMenu2X::main() {
} }
switch (input.waitForPressedButton()) { switch (input.waitForPressedButton()) {
case ACCEPT: case InputManager::ACCEPT:
if (menu->selLink() != NULL) menu->selLink()->run(); if (menu->selLink() != NULL) menu->selLink()->run();
break; break;
case CANCEL: case InputManager::CANCEL:
helpDisplayed=true; helpDisplayed=true;
break; break;
case SETTINGS: case InputManager::SETTINGS:
options(); options();
break; break;
case MENU: case InputManager::MENU:
contextMenu(); contextMenu();
break; break;
case UP: case InputManager::UP:
menu->linkUp(); menu->linkUp();
break; break;
case DOWN: case InputManager::DOWN:
menu->linkDown(); menu->linkDown();
break; break;
case LEFT: case InputManager::LEFT:
menu->linkLeft(); menu->linkLeft();
break; break;
case RIGHT: case InputManager::RIGHT:
menu->linkRight(); menu->linkRight();
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
menu->decSectionIndex(); menu->decSectionIndex();
offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6;
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
menu->incSectionIndex(); menu->incSectionIndex();
offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6;
break; break;
@ -1563,7 +1563,7 @@ void GMenu2X::contextMenu() {
bg.box(box.x, box.y, box.w, box.h, skinConfColors["messageBoxBg"]); 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"] );*/ bg.rectangle( box.x+2, box.y+2, box.w-4, box.h-4, skinConfColors["messageBoxBorder"] );*/
bevent_t event; InputManager::ButtonEvent event;
while (!close) { while (!close) {
tickNow = SDL_GetTicks(); tickNow = SDL_GetTicks();
@ -1613,22 +1613,22 @@ void GMenu2X::contextMenu() {
if (fadeAlpha < 200) { if (fadeAlpha < 200) {
if (!input.pollEvent(&event) || event.state != PRESSED) continue; if (!input.pollEvent(&event) || event.state != InputManager::PRESSED) continue;
} else { } else {
event.button = input.waitForPressedButton(); event.button = input.waitForPressedButton();
} }
switch(event.button) { switch(event.button) {
case MENU: case InputManager::MENU:
close = true; close = true;
break; break;
case UP: case InputManager::UP:
sel = max(0, sel-1); sel = max(0, sel-1);
break; break;
case DOWN: case InputManager::DOWN:
sel = min((int)voices.size()-1, sel+1); sel = min((int)voices.size()-1, sel+1);
break; break;
case ACCEPT: case InputManager::ACCEPT:
voices[sel].action(); voices[sel].action();
close = true; close = true;
break; break;
@ -1753,9 +1753,9 @@ void GMenu2X::editLink() {
void GMenu2X::deleteLink() { void GMenu2X::deleteLink() {
if (menu->selLinkApp()!=NULL) { 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()); 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(InputManager::ACCEPT, tr["Yes"]);
mb.setButton(CANCEL, tr["No"]); mb.setButton(InputManager::CANCEL, tr["No"]);
if (mb.exec() == ACCEPT) { if (mb.exec() == InputManager::ACCEPT) {
ledOn(); ledOn();
menu->deleteSelectedLink(); menu->deleteSelectedLink();
sync(); sync();
@ -1818,9 +1818,9 @@ void GMenu2X::renameSection() {
void GMenu2X::deleteSection() { void GMenu2X::deleteSection() {
MessageBox mb(this,tr["You will lose all the links in this section."]+"\n"+tr["Are you sure?"]); 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(InputManager::ACCEPT, tr["Yes"]);
mb.setButton(CANCEL, tr["No"]); mb.setButton(InputManager::CANCEL, tr["No"]);
if (mb.exec() == ACCEPT) { if (mb.exec() == InputManager::ACCEPT) {
ledOn(); ledOn();
if (rmtree(getHome() + "/sections/" + menu->selSection())) { if (rmtree(getHome() + "/sections/" + menu->selSection())) {
menu->deleteSelectedSection(); menu->deleteSelectedSection();
@ -1922,22 +1922,12 @@ void GMenu2X::scanner() {
ledOff(); ledOff();
#endif #endif
buttontype_t button; InputManager::Button button;
do { do {
button = input.waitForPressedButton(); button = input.waitForPressedButton();
} while ((button != SETTINGS) } while ((button != InputManager::SETTINGS)
&& (button != ACCEPT) && (button != InputManager::ACCEPT)
&& (button != CANCEL)); && (button != InputManager::CANCEL));
/*
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<string> *files) { void GMenu2X::scanPath(string path, vector<string> *files) {

View File

@ -161,33 +161,33 @@ bool InputDialog::exec() {
gmenu2x->s->flip(); gmenu2x->s->flip();
switch (inputMgr.waitForPressedButton()) { switch (inputMgr.waitForPressedButton()) {
case SETTINGS: case InputManager::SETTINGS:
ok = false; ok = false;
close = true; close = true;
break; break;
case UP: case InputManager::UP:
selRow--; selRow--;
break; break;
case DOWN: case InputManager::DOWN:
selRow++; selRow++;
if (selRow==(int)kb->size()) selCol = selCol<8 ? 0 : 1; if (selRow==(int)kb->size()) selCol = selCol<8 ? 0 : 1;
break; break;
case LEFT: case InputManager::LEFT:
selCol--; selCol--;
break; break;
case RIGHT: case InputManager::RIGHT:
selCol++; selCol++;
break; break;
case ACCEPT: case InputManager::ACCEPT:
confirm(); confirm();
break; break;
case CANCEL: case InputManager::CANCEL:
changeKeys(); changeKeys();
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
backspace(); backspace();
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
space(); space();
break; break;
default: default:

View File

@ -66,7 +66,7 @@ bool InputManager::readConfFile(const string &conffile) {
string line, name, source; string line, name, source;
string::size_type pos; string::size_type pos;
buttontype_t button; Button button;
while(getline(inf, line, '\n')) { while(getline(inf, line, '\n')) {
pos = line.find("="); pos = line.find("=");
@ -95,42 +95,42 @@ bool InputManager::readConfFile(const string &conffile) {
source = trim(line.substr(0,pos)); source = trim(line.substr(0,pos));
line = trim(line.substr(pos+1, line.length())); line = trim(line.substr(pos+1, line.length()));
if (source == "keyboard") ButtonMap[button].source = KEYBOARD; if (source == "keyboard") buttonMap[button].source = KEYBOARD;
else if (source == "joystick") ButtonMap[button].source = JOYSTICK; else if (source == "joystick") buttonMap[button].source = JOYSTICK;
else return false; else return false;
ButtonMap[button].code = atoi(line.c_str()); buttonMap[button].code = atoi(line.c_str());
} }
inf.close(); inf.close();
return true; return true;
} }
buttontype_t InputManager::waitForPressedButton() { InputManager::Button InputManager::waitForPressedButton() {
return waitForButton(PRESSED); return waitForButton(PRESSED);
} }
buttontype_t InputManager::waitForReleasedButton() { InputManager::Button InputManager::waitForReleasedButton() {
return waitForButton(RELEASED); return waitForButton(RELEASED);
} }
buttontype_t InputManager::waitForButton(enum state_e state) { InputManager::Button InputManager::waitForButton(ButtonState state) {
bevent_t event; ButtonEvent event;
do { do {
waitForEvent(&event); waitForEvent(&event);
} while (event.state != state); } while (event.state != state);
return event.button; return event.button;
} }
void InputManager::waitForEvent(bevent_t *event) { void InputManager::waitForEvent(ButtonEvent *event) {
getEvent(event, true); getEvent(event, true);
} }
bool InputManager::pollEvent(bevent_t *event) { bool InputManager::pollEvent(ButtonEvent *event) {
return getEvent(event, false); 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 //TODO: when an event is processed, program a new event
//in some time, and when it occurs, do a key repeat //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) { switch(event.type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
bevent->state = PRESSED; bevent->state = PRESSED;
@ -168,18 +168,18 @@ bool InputManager::getEvent(bevent_t *bevent, bool wait) {
} }
if (source == KEYBOARD) { if (source == KEYBOARD) {
for (int i=0; i<BUTTONTYPE_T_SIZE; i++) { for (int i = 0; i < BUTTON_TYPE_SIZE; i++) {
if (ButtonMap[i].source == KEYBOARD if (buttonMap[i].source == KEYBOARD
&& (unsigned int)event.key.keysym.sym == ButtonMap[i].code) { && (unsigned int)event.key.keysym.sym == buttonMap[i].code) {
bevent->button = (buttontype_t)i; bevent->button = static_cast<Button>(i);
break; break;
} }
} }
} else { } else {
for (int i=0; i<BUTTONTYPE_T_SIZE; i++) { for (int i = 0; i < BUTTON_TYPE_SIZE; i++) {
if (ButtonMap[i].source == JOYSTICK if (buttonMap[i].source == JOYSTICK
&& (unsigned int)event.jbutton.button == ButtonMap[i].code) { && (unsigned int)event.jbutton.button == buttonMap[i].code) {
bevent->button = (buttontype_t)i; bevent->button = static_cast<Button>(i);
break; break;
} }
} }

View File

@ -23,7 +23,9 @@
#include <string> #include <string>
typedef enum buttontype_e { class InputManager {
public:
enum Button {
UP, DOWN, LEFT, RIGHT, UP, DOWN, LEFT, RIGHT,
ACCEPT, CANCEL, ACCEPT, CANCEL,
CLEAR, MANUAL, CLEAR, MANUAL,
@ -31,41 +33,37 @@ typedef enum buttontype_e {
MENU, SETTINGS, MENU, SETTINGS,
VOLUP, VOLDOWN, VOLUP, VOLDOWN,
POWER, LOCK POWER, LOCK
} buttontype_t; };
#define BUTTONTYPE_T_SIZE 16 #define BUTTON_TYPE_SIZE 16
enum source_type_e {KEYBOARD, JOYSTICK}; enum ButtonState { PRESSED, RELEASED };
enum state_e {PRESSED, RELEASED}; struct ButtonEvent {
Button button;
ButtonState state;
};
typedef struct {
source_type_e source;
unsigned int code;
} input_t;
typedef struct {
buttontype_t button;
state_e state;
} bevent_t;
class InputManager {
public:
InputManager(); InputManager();
~InputManager(); ~InputManager();
void init(const std::string &conffile); void init(const std::string &conffile);
void waitForEvent(bevent_t *event); void waitForEvent(ButtonEvent *event);
buttontype_t waitForPressedButton(); Button waitForPressedButton();
buttontype_t waitForReleasedButton(); Button waitForReleasedButton();
bool pollEvent(bevent_t *event); bool pollEvent(ButtonEvent *event);
private: private:
input_t ButtonMap[BUTTONTYPE_T_SIZE]; enum ButtonSource { KEYBOARD, JOYSTICK };
struct ButtonMapEntry {
ButtonSource source;
unsigned int code;
};
ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
bool readConfFile(const std::string &conffile); bool readConfFile(const std::string &conffile);
void initJoystick(); void initJoystick();
bool getEvent(bevent_t *bevent, bool wait); bool getEvent(ButtonEvent *bevent, bool wait);
buttontype_t waitForButton(enum state_e state); Button waitForButton(ButtonState state);
}; };
#endif #endif

View File

@ -318,17 +318,17 @@ void LinkApp::showManual() {
} }
switch(inputMgr.waitForPressedButton()) { switch(inputMgr.waitForPressedButton()) {
case SETTINGS: case InputManager::SETTINGS:
case CANCEL: case InputManager::CANCEL:
close = true; close = true;
break; break;
case LEFT: case InputManager::LEFT:
if (page > 0) { if (page > 0) {
page--; page--;
repaint = true; repaint = true;
} }
break; break;
case RIGHT: case InputManager::RIGHT:
if (page < pagecount-1) { if (page < pagecount-1) {
page++; page++;
repaint=true; repaint=true;

View File

@ -47,7 +47,7 @@ public:
virtual void draw(int y); virtual void draw(int y);
virtual void handleTS(); virtual void handleTS();
virtual bool manageInput(bevent_t *event) = 0; virtual bool manageInput(InputManager::ButtonEvent *event) = 0;
virtual void adjustInput(); virtual void adjustInput();
virtual void drawSelected(int y); virtual void drawSelected(int y);
virtual bool edited() = 0; virtual bool edited() = 0;

View File

@ -64,9 +64,10 @@ void MenuSettingBool::draw(int y)
gmenu2x->s->write( gmenu2x->font, strvalue, 155, y, ASFont::HAlignLeft, ASFont::VAlignTop ); gmenu2x->s->write( gmenu2x->font, strvalue, 155, y, ASFont::HAlignLeft, ASFont::VAlignTop );
} }
bool MenuSettingBool::manageInput(bevent_t *event) bool MenuSettingBool::manageInput(InputManager::ButtonEvent *event)
{ {
if (event->button == ACCEPT && event->state == PRESSED) { if (event->button == InputManager::ACCEPT
&& event->state == InputManager::PRESSED) {
toggle(); toggle();
return true; return true;
} }

View File

@ -45,7 +45,7 @@ public:
virtual ~MenuSettingBool() {} virtual ~MenuSettingBool() {}
virtual void draw(int y); virtual void draw(int y);
virtual bool manageInput(bevent_t *event); virtual bool manageInput(InputManager::ButtonEvent *event);
virtual bool edited(); virtual bool edited();
void setValue(int value); void setValue(int value);

View File

@ -66,19 +66,19 @@ void MenuSettingInt::draw(int y)
gmenu2x->s->write( gmenu2x->font, strvalue, 155, y, ASFont::HAlignLeft, ASFont::VAlignTop ); gmenu2x->s->write( gmenu2x->font, strvalue, 155, y, ASFont::HAlignLeft, ASFont::VAlignTop );
} }
bool MenuSettingInt::manageInput(bevent_t *event) bool MenuSettingInt::manageInput(InputManager::ButtonEvent *event)
{ {
switch (event->button) { switch (event->button) {
case LEFT: case InputManager::LEFT:
dec(); dec();
break; break;
case RIGHT: case InputManager::RIGHT:
inc(); inc();
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
setValue(value() - 10 * increment); setValue(value() - 10 * increment);
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
setValue(value() + 10 * increment); setValue(value() + 10 * increment);
break; break;
default: default:

View File

@ -41,7 +41,7 @@ public:
int increment = 1); int increment = 1);
virtual ~MenuSettingInt() {} virtual ~MenuSettingInt() {}
virtual bool manageInput(bevent_t *event); virtual bool manageInput(InputManager::ButtonEvent *event);
virtual void adjustInput(); virtual void adjustInput();
virtual void draw(int); virtual void draw(int);
virtual bool edited(); virtual bool edited();

View File

@ -49,13 +49,13 @@ MenuSettingMultiString::MenuSettingMultiString(
buttonBox.add(btn); buttonBox.add(btn);
} }
bool MenuSettingMultiString::manageInput(bevent_t *event) bool MenuSettingMultiString::manageInput(InputManager::ButtonEvent *event)
{ {
switch(event->button) { switch(event->button) {
case LEFT: case InputManager::LEFT:
decSel(); decSel();
break; break;
case RIGHT: case InputManager::RIGHT:
incSel(); incSel();
break; break;
default: default:

View File

@ -45,7 +45,7 @@ public:
const std::vector<std::string> *choices); const std::vector<std::string> *choices);
virtual ~MenuSettingMultiString() {}; virtual ~MenuSettingMultiString() {};
virtual bool manageInput(bevent_t *event); virtual bool manageInput(InputManager::ButtonEvent *event);
}; };
#endif #endif

View File

@ -68,24 +68,24 @@ void MenuSettingRGBA::handleTS() {
MenuSetting::handleTS(); MenuSetting::handleTS();
} }
bool MenuSettingRGBA::manageInput(bevent_t *event) { bool MenuSettingRGBA::manageInput(InputManager::ButtonEvent *event) {
if (edit) { if (edit) {
switch(event->button) { switch(event->button) {
case LEFT: case InputManager::LEFT:
dec(); dec();
break; break;
case RIGHT: case InputManager::RIGHT:
inc(); inc();
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
update_value(-10); update_value(-10);
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
update_value(10); update_value(10);
break; break;
case ACCEPT: case InputManager::ACCEPT:
case UP: case InputManager::UP:
case DOWN: case InputManager::DOWN:
edit = false; edit = false;
updateButtonBox(); updateButtonBox();
break; break;
@ -94,13 +94,13 @@ bool MenuSettingRGBA::manageInput(bevent_t *event) {
} }
} else { } else {
switch(event->button) { switch(event->button) {
case LEFT: case InputManager::LEFT:
leftComponent(); leftComponent();
break; break;
case RIGHT: case InputManager::RIGHT:
rightComponent(); rightComponent();
break; break;
case ACCEPT: case InputManager::ACCEPT:
edit = true; edit = true;
updateButtonBox(); updateButtonBox();
break; break;

View File

@ -51,7 +51,7 @@ public:
virtual void draw(int y); virtual void draw(int y);
virtual void handleTS(); virtual void handleTS();
virtual bool manageInput(bevent_t *event); virtual bool manageInput(InputManager::ButtonEvent *event);
virtual void adjustInput(); virtual void adjustInput();
virtual void drawSelected(int y); virtual void drawSelected(int y);
virtual bool edited(); virtual bool edited();

View File

@ -42,18 +42,17 @@ void MenuSettingStringBase::draw(int y)
ASFont::HAlignLeft, ASFont::VAlignTop); ASFont::HAlignLeft, ASFont::VAlignTop);
} }
bool MenuSettingStringBase::manageInput(bevent_t *event) bool MenuSettingStringBase::manageInput(InputManager::ButtonEvent *event)
{ {
switch (event->button) { switch (event->button) {
case CANCEL: case InputManager::CANCEL:
clear(); clear();
break; break;
case ACCEPT: case InputManager::ACCEPT:
edit(); edit();
break; break;
default: default:
return false; return false;
break;
} }
return true; return true;
} }

View File

@ -38,7 +38,7 @@ public:
virtual ~MenuSettingStringBase(); virtual ~MenuSettingStringBase();
virtual void draw(int y); virtual void draw(int y);
virtual bool manageInput(bevent_t *event); virtual bool manageInput(InputManager::ButtonEvent *event);
virtual bool edited(); virtual bool edited();
void setValue(const std::string &value) { *_value = value; } void setValue(const std::string &value) { *_value = value; }

View File

@ -40,23 +40,23 @@ MessageBox::MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon)
} }
//Default enabled button //Default enabled button
buttons[ACCEPT] = "OK"; buttons[InputManager::ACCEPT] = "OK";
//Default labels //Default labels
buttonLabels[UP] = "up"; buttonLabels[InputManager::UP] = "up";
buttonLabels[DOWN] = "down"; buttonLabels[InputManager::DOWN] = "down";
buttonLabels[LEFT] = "left"; buttonLabels[InputManager::LEFT] = "left";
buttonLabels[RIGHT] = "right"; buttonLabels[InputManager::RIGHT] = "right";
buttonLabels[CANCEL] = "cancel"; buttonLabels[InputManager::CANCEL] = "cancel";
buttonLabels[ACCEPT] = "accept"; buttonLabels[InputManager::ACCEPT] = "accept";
buttonLabels[CLEAR] = "x"; buttonLabels[InputManager::CLEAR] = "x";
buttonLabels[MANUAL] = "y"; buttonLabels[InputManager::MANUAL] = "y";
buttonLabels[ALTLEFT] = "l"; buttonLabels[InputManager::ALTLEFT] = "l";
buttonLabels[ALTRIGHT] = "r"; buttonLabels[InputManager::ALTRIGHT] = "r";
buttonLabels[SETTINGS] = "start"; buttonLabels[InputManager::SETTINGS] = "start";
buttonLabels[MENU] = "select"; buttonLabels[InputManager::MENU] = "select";
buttonLabels[VOLUP] = "vol+"; buttonLabels[InputManager::VOLUP] = "vol+";
buttonLabels[VOLDOWN] = "vol-"; buttonLabels[InputManager::VOLDOWN] = "vol-";
} }
void MessageBox::setButton(int action, const string &btn) { void MessageBox::setButton(int action, const string &btn) {
@ -103,7 +103,7 @@ int MessageBox::exec() {
bg.blit(gmenu2x->s,0,0); bg.blit(gmenu2x->s,0,0);
gmenu2x->s->flip(); gmenu2x->s->flip();
bevent_t event; InputManager::ButtonEvent event;
while (result<0) { while (result<0) {
#ifdef PLATFORM_GP2X #ifdef PLATFORM_GP2X
@ -119,14 +119,11 @@ int MessageBox::exec() {
} }
#endif #endif
/* if (gmenu2x->input.pollEvent(&event)
gmenu2x->input.update(); && (event.state == InputManager::PRESSED)
for (uint i=0; i<buttons.size(); i++) && (buttons[event.button] != "")) {
if (buttons[i]!="" && gmenu2x->input[i]) result = i; result = event.button;
}
*/
if (gmenu2x->input.pollEvent(&event) && (event.state == PRESSED) && (buttons[event.button] != "")) result = event.button;
usleep(LOOP_DELAY); usleep(LOOP_DELAY);
} }

View File

@ -119,32 +119,32 @@ int Selector::exec(int startSelection) {
gmenu2x->s->flip(); gmenu2x->s->flip();
switch (gmenu2x->input.waitForPressedButton()) { switch (gmenu2x->input.waitForPressedButton()) {
case SETTINGS: case InputManager::SETTINGS:
close = true; close = true;
result = false; result = false;
break; break;
case UP: case InputManager::UP:
if (selected == 0) selected = fl.size() -1; if (selected == 0) selected = fl.size() -1;
else selected -= 1; else selected -= 1;
selTick = SDL_GetTicks(); selTick = SDL_GetTicks();
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
if ((int)(selected-SELECTOR_ELEMENTS+1)<0) selected = 0; if ((int)(selected-SELECTOR_ELEMENTS+1)<0) selected = 0;
else selected -= SELECTOR_ELEMENTS-1; else selected -= SELECTOR_ELEMENTS-1;
selTick = SDL_GetTicks(); selTick = SDL_GetTicks();
break; break;
case DOWN: case InputManager::DOWN:
if (selected+1>=fl.size()) selected = 0; if (selected+1>=fl.size()) selected = 0;
else selected += 1; else selected += 1;
selTick = SDL_GetTicks(); selTick = SDL_GetTicks();
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
if (selected+SELECTOR_ELEMENTS-1>=fl.size()) selected = fl.size()-1; if (selected+SELECTOR_ELEMENTS-1>=fl.size()) selected = fl.size()-1;
else selected += SELECTOR_ELEMENTS-1; else selected += SELECTOR_ELEMENTS-1;
selTick = SDL_GetTicks(); selTick = SDL_GetTicks();
break; break;
case CANCEL: case InputManager::CANCEL:
case LEFT: case InputManager::LEFT:
if (link->getSelectorBrowser()) { if (link->getSelectorBrowser()) {
string::size_type p = dir.rfind("/", dir.size()-2); string::size_type p = dir.rfind("/", dir.size()-2);
if (p==string::npos || dir.compare(0, 1, "/") != 0 || dir.length() < 2) { if (p==string::npos || dir.compare(0, 1, "/") != 0 || dir.length() < 2) {
@ -159,7 +159,7 @@ int Selector::exec(int startSelection) {
} }
} }
break; break;
case ACCEPT: case InputManager::ACCEPT:
if (fl.isFile(selected)) { if (fl.isFile(selected)) {
file = fl[selected]; file = fl[selected];
close = true; close = true;

View File

@ -105,17 +105,17 @@ bool SettingsDialog::exec() {
gmenu2x->s->flip(); gmenu2x->s->flip();
voices[sel]->handleTS(); voices[sel]->handleTS();
bevent_t event; InputManager::ButtonEvent event;
do { do {
inputMgr.waitForEvent(&event); inputMgr.waitForEvent(&event);
} while (event.state != PRESSED); } while (event.state != InputManager::PRESSED);
if (voices[sel]->manageInput(&event) == false) { if (voices[sel]->manageInput(&event) == false) {
switch (event.button) { switch (event.button) {
case SETTINGS: case InputManager::SETTINGS:
close = true; close = true;
break; break;
case UP: case InputManager::UP:
if (sel==0) if (sel==0)
sel = voices.size()-1; sel = voices.size()-1;
else else
@ -123,7 +123,7 @@ bool SettingsDialog::exec() {
gmenu2x->setInputSpeed(); gmenu2x->setInputSpeed();
voices[sel]->adjustInput(); voices[sel]->adjustInput();
break; break;
case DOWN: case InputManager::DOWN:
sel += 1; sel += 1;
if (sel>=voices.size()) sel = 0; if (sel>=voices.size()) sel = 0;
gmenu2x->setInputSpeed(); gmenu2x->setInputSpeed();

View File

@ -113,52 +113,37 @@ void TextDialog::exec() {
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
uint firstRow = 0, rowsPerPage = (gmenu2x->resY-60)/gmenu2x->font->getHeight(); uint firstRow = 0;
uint rowsPerPage = (gmenu2x->resY - 60) / gmenu2x->font->getHeight();
while (!close) { while (!close) {
bg.blit(gmenu2x->s, 0, 0); bg.blit(gmenu2x->s, 0, 0);
drawText(text, firstRow, rowsPerPage); drawText(text, firstRow, rowsPerPage);
gmenu2x->s->flip(); gmenu2x->s->flip();
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x->input.waitForPressedButton()) {
case UP: case InputManager::UP:
if (firstRow > 0) firstRow--; if (firstRow > 0) firstRow--;
break; break;
case DOWN: case InputManager::DOWN:
if (firstRow + rowsPerPage < text->size()) firstRow++; if (firstRow + rowsPerPage < text->size()) firstRow++;
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1; if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1;
else firstRow = 0; else firstRow = 0;
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
if (firstRow + rowsPerPage*2 -1 < text->size()) firstRow += rowsPerPage-1; if (firstRow + rowsPerPage*2 -1 < text->size()) {
else firstRow = max(0, text->size() - rowsPerPage); firstRow += rowsPerPage-1;
} else {
firstRow = max(0, text->size() - rowsPerPage);
}
break; break;
case SETTINGS: case InputManager::SETTINGS:
case CANCEL: case InputManager::CANCEL:
close = true; close = true;
break; break;
default: default:
break; break;
} }
/*
gmenu2x->input.update();
if ( gmenu2x->input[ACTION_UP ] && firstRow>0 ) firstRow--;
if ( gmenu2x->input[ACTION_DOWN] && firstRow+rowsPerPage<text->size() ) firstRow++;
if ( gmenu2x->input[ACTION_L ] ) {
if (firstRow>=rowsPerPage-1)
firstRow-= rowsPerPage-1;
else
firstRow = 0;
}
if ( gmenu2x->input[ACTION_R ] ) {
if (firstRow+rowsPerPage*2-1<text->size())
firstRow+= rowsPerPage-1;
else
firstRow = max(0,text->size()-rowsPerPage);
}
if ( gmenu2x->input[ACTION_START] || gmenu2x->input[ACTION_X] ) close = true;
*/
} }
} }

View File

@ -104,59 +104,38 @@ void TextManualDialog::exec() {
gmenu2x->s->flip(); gmenu2x->s->flip();
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x->input.waitForPressedButton()) {
case UP: case InputManager::UP:
if (firstRow > 0) firstRow--; if (firstRow > 0) firstRow--;
break; break;
case DOWN: case InputManager::DOWN:
if (firstRow + rowsPerPage < pages[page].text.size()) firstRow++; if (firstRow + rowsPerPage < pages[page].text.size()) firstRow++;
break; break;
case LEFT: case InputManager::LEFT:
if (page > 0) { if (page > 0) {
page--; page--;
firstRow = 0; firstRow = 0;
} }
break; break;
case RIGHT: case InputManager::RIGHT:
if (page < pages.size() -1) { if (page < pages.size() -1) {
page++; page++;
firstRow = 0; firstRow = 0;
} }
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1; if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1;
else firstRow = 0; else firstRow = 0;
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
if (firstRow + rowsPerPage*2 -1 < pages[page].text.size()) firstRow += rowsPerPage-1; if (firstRow + rowsPerPage*2 -1 < pages[page].text.size()) firstRow += rowsPerPage-1;
else firstRow = max(0, pages[page].text.size() - rowsPerPage); else firstRow = max(0, pages[page].text.size() - rowsPerPage);
break; break;
case CANCEL: case InputManager::CANCEL:
case SETTINGS: case InputManager::SETTINGS:
close = true; close = true;
break; break;
default: default:
break; break;
} }
/*
gmenu2x->input.update();
if ( gmenu2x->input[ACTION_UP ] && firstRow>0 ) firstRow--;
if ( gmenu2x->input[ACTION_DOWN ] && firstRow+rowsPerPage<pages[page].text.size() ) firstRow++;
if ( gmenu2x->input[ACTION_LEFT ] && page>0 ) { page--; firstRow=0; }
if ( gmenu2x->input[ACTION_RIGHT] && page<pages.size()-1 ) { page++; firstRow=0; }
if ( gmenu2x->input[ACTION_L ] ) {
if (firstRow>=rowsPerPage-1)
firstRow-= rowsPerPage-1;
else
firstRow = 0;
}
if ( gmenu2x->input[ACTION_R ] ) {
if (firstRow+rowsPerPage*2-1<pages[page].text.size())
firstRow+= rowsPerPage-1;
else
firstRow = max(0,pages[page].text.size()-rowsPerPage);
}
if ( gmenu2x->input[ACTION_START] || gmenu2x->input[ACTION_X] ) close = true;
*/
} }
} }

View File

@ -108,27 +108,27 @@ bool WallpaperDialog::exec()
gmenu2x->s->flip(); gmenu2x->s->flip();
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x->input.waitForPressedButton()) {
case CANCEL: case InputManager::CANCEL:
close = true; close = true;
result = false; result = false;
break; break;
case UP: case InputManager::UP:
if (selected == 0) selected = wallpapers.size()-1; if (selected == 0) selected = wallpapers.size()-1;
else selected -= 1; else selected -= 1;
break; break;
case ALTLEFT: case InputManager::ALTLEFT:
if ((int)(selected-9) < 0) selected = 0; if ((int)(selected-9) < 0) selected = 0;
else selected -= 9; else selected -= 9;
break; break;
case DOWN: case InputManager::DOWN:
if (selected+1 >= wallpapers.size()) selected = 0; if (selected+1 >= wallpapers.size()) selected = 0;
else selected += 1; else selected += 1;
break; break;
case ALTRIGHT: case InputManager::ALTRIGHT:
if (selected+9 >= wallpapers.size()) selected = wallpapers.size()-1; if (selected+9 >= wallpapers.size()) selected = wallpapers.size()-1;
else selected += 9; else selected += 9;
break; break;
case ACCEPT: case InputManager::ACCEPT:
close = true; close = true;
if (wallpapers.size() > 0) if (wallpapers.size() > 0)
wallpaper = gmenu2x->sc.getSkinFilePath("wallpapers/" + wallpapers[selected]); wallpaper = gmenu2x->sc.getSkinFilePath("wallpapers/" + wallpapers[selected]);