mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-12-26 08:55:30 +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:
parent
c6db9ff21b
commit
315bf0a180
@ -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 {
|
||||
|
@ -76,7 +76,7 @@ private:
|
||||
|
||||
ButtonBox buttonBox;
|
||||
|
||||
Action getAction(bevent_t *event);
|
||||
Action getAction(InputManager::ButtonEvent *event);
|
||||
void handleInput();
|
||||
|
||||
void paint();
|
||||
|
@ -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<string> *files) {
|
||||
|
@ -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:
|
||||
|
@ -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; i<BUTTONTYPE_T_SIZE; i++) {
|
||||
if (ButtonMap[i].source == KEYBOARD
|
||||
&& (unsigned int)event.key.keysym.sym == ButtonMap[i].code) {
|
||||
bevent->button = (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<Button>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i=0; i<BUTTONTYPE_T_SIZE; i++) {
|
||||
if (ButtonMap[i].source == JOYSTICK
|
||||
&& (unsigned int)event.jbutton.button == ButtonMap[i].code) {
|
||||
bevent->button = (buttontype_t)i;
|
||||
for (int i = 0; i < BUTTON_TYPE_SIZE; i++) {
|
||||
if (buttonMap[i].source == JOYSTICK
|
||||
&& (unsigned int)event.jbutton.button == buttonMap[i].code) {
|
||||
bevent->button = static_cast<Button>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -23,49 +23,47 @@
|
||||
|
||||
#include <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 {
|
||||
source_type_e source;
|
||||
unsigned int code;
|
||||
} input_t;
|
||||
|
||||
typedef struct {
|
||||
buttontype_t button;
|
||||
state_e state;
|
||||
} bevent_t;
|
||||
|
||||
|
||||
class InputManager {
|
||||
public:
|
||||
enum Button {
|
||||
UP, DOWN, LEFT, RIGHT,
|
||||
ACCEPT, CANCEL,
|
||||
CLEAR, MANUAL,
|
||||
ALTLEFT, ALTRIGHT,
|
||||
MENU, SETTINGS,
|
||||
VOLUP, VOLDOWN,
|
||||
POWER, LOCK
|
||||
};
|
||||
#define BUTTON_TYPE_SIZE 16
|
||||
|
||||
enum ButtonState { PRESSED, RELEASED };
|
||||
struct ButtonEvent {
|
||||
Button button;
|
||||
ButtonState state;
|
||||
};
|
||||
|
||||
InputManager();
|
||||
~InputManager();
|
||||
|
||||
void init(const std::string &conffile);
|
||||
void waitForEvent(bevent_t *event);
|
||||
buttontype_t waitForPressedButton();
|
||||
buttontype_t waitForReleasedButton();
|
||||
bool pollEvent(bevent_t *event);
|
||||
void waitForEvent(ButtonEvent *event);
|
||||
Button waitForPressedButton();
|
||||
Button waitForReleasedButton();
|
||||
bool pollEvent(ButtonEvent *event);
|
||||
|
||||
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);
|
||||
void initJoystick();
|
||||
bool getEvent(bevent_t *bevent, bool wait);
|
||||
buttontype_t waitForButton(enum state_e state);
|
||||
bool getEvent(ButtonEvent *bevent, bool wait);
|
||||
Button waitForButton(ButtonState state);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -318,17 +318,17 @@ void LinkApp::showManual() {
|
||||
}
|
||||
|
||||
switch(inputMgr.waitForPressedButton()) {
|
||||
case SETTINGS:
|
||||
case CANCEL:
|
||||
case InputManager::SETTINGS:
|
||||
case InputManager::CANCEL:
|
||||
close = true;
|
||||
break;
|
||||
case LEFT:
|
||||
case InputManager::LEFT:
|
||||
if (page > 0) {
|
||||
page--;
|
||||
repaint = true;
|
||||
}
|
||||
break;
|
||||
case RIGHT:
|
||||
case InputManager::RIGHT:
|
||||
if (page < pagecount-1) {
|
||||
page++;
|
||||
repaint=true;
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
virtual void draw(int y);
|
||||
virtual void handleTS();
|
||||
|
||||
virtual bool manageInput(bevent_t *event) = 0;
|
||||
virtual bool manageInput(InputManager::ButtonEvent *event) = 0;
|
||||
virtual void adjustInput();
|
||||
virtual void drawSelected(int y);
|
||||
virtual bool edited() = 0;
|
||||
|
@ -64,9 +64,10 @@ void MenuSettingBool::draw(int y)
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
virtual ~MenuSettingBool() {}
|
||||
|
||||
virtual void draw(int y);
|
||||
virtual bool manageInput(bevent_t *event);
|
||||
virtual bool manageInput(InputManager::ButtonEvent *event);
|
||||
virtual bool edited();
|
||||
|
||||
void setValue(int value);
|
||||
|
@ -66,19 +66,19 @@ void MenuSettingInt::draw(int y)
|
||||
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) {
|
||||
case LEFT:
|
||||
case InputManager::LEFT:
|
||||
dec();
|
||||
break;
|
||||
case RIGHT:
|
||||
case InputManager::RIGHT:
|
||||
inc();
|
||||
break;
|
||||
case ALTLEFT:
|
||||
case InputManager::ALTLEFT:
|
||||
setValue(value() - 10 * increment);
|
||||
break;
|
||||
case ALTRIGHT:
|
||||
case InputManager::ALTRIGHT:
|
||||
setValue(value() + 10 * increment);
|
||||
break;
|
||||
default:
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
int increment = 1);
|
||||
virtual ~MenuSettingInt() {}
|
||||
|
||||
virtual bool manageInput(bevent_t *event);
|
||||
virtual bool manageInput(InputManager::ButtonEvent *event);
|
||||
virtual void adjustInput();
|
||||
virtual void draw(int);
|
||||
virtual bool edited();
|
||||
|
@ -49,13 +49,13 @@ MenuSettingMultiString::MenuSettingMultiString(
|
||||
buttonBox.add(btn);
|
||||
}
|
||||
|
||||
bool MenuSettingMultiString::manageInput(bevent_t *event)
|
||||
bool MenuSettingMultiString::manageInput(InputManager::ButtonEvent *event)
|
||||
{
|
||||
switch(event->button) {
|
||||
case LEFT:
|
||||
case InputManager::LEFT:
|
||||
decSel();
|
||||
break;
|
||||
case RIGHT:
|
||||
case InputManager::RIGHT:
|
||||
incSel();
|
||||
break;
|
||||
default:
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
const std::vector<std::string> *choices);
|
||||
virtual ~MenuSettingMultiString() {};
|
||||
|
||||
virtual bool manageInput(bevent_t *event);
|
||||
virtual bool manageInput(InputManager::ButtonEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -68,39 +68,39 @@ void MenuSettingRGBA::handleTS() {
|
||||
MenuSetting::handleTS();
|
||||
}
|
||||
|
||||
bool MenuSettingRGBA::manageInput(bevent_t *event) {
|
||||
bool MenuSettingRGBA::manageInput(InputManager::ButtonEvent *event) {
|
||||
if (edit) {
|
||||
switch(event->button) {
|
||||
case LEFT:
|
||||
dec();
|
||||
break;
|
||||
case RIGHT:
|
||||
inc();
|
||||
break;
|
||||
case ALTLEFT:
|
||||
update_value(-10);
|
||||
break;
|
||||
case ALTRIGHT:
|
||||
update_value(10);
|
||||
break;
|
||||
case ACCEPT:
|
||||
case UP:
|
||||
case DOWN:
|
||||
edit = false;
|
||||
updateButtonBox();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
switch(event->button) {
|
||||
case InputManager::LEFT:
|
||||
dec();
|
||||
break;
|
||||
case InputManager::RIGHT:
|
||||
inc();
|
||||
break;
|
||||
case InputManager::ALTLEFT:
|
||||
update_value(-10);
|
||||
break;
|
||||
case InputManager::ALTRIGHT:
|
||||
update_value(10);
|
||||
break;
|
||||
case InputManager::ACCEPT:
|
||||
case InputManager::UP:
|
||||
case InputManager::DOWN:
|
||||
edit = false;
|
||||
updateButtonBox();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
switch(event->button) {
|
||||
case LEFT:
|
||||
case InputManager::LEFT:
|
||||
leftComponent();
|
||||
break;
|
||||
case RIGHT:
|
||||
case InputManager::RIGHT:
|
||||
rightComponent();
|
||||
break;
|
||||
case ACCEPT:
|
||||
case InputManager::ACCEPT:
|
||||
edit = true;
|
||||
updateButtonBox();
|
||||
break;
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
|
||||
virtual void draw(int y);
|
||||
virtual void handleTS();
|
||||
virtual bool manageInput(bevent_t *event);
|
||||
virtual bool manageInput(InputManager::ButtonEvent *event);
|
||||
virtual void adjustInput();
|
||||
virtual void drawSelected(int y);
|
||||
virtual bool edited();
|
||||
|
@ -42,19 +42,18 @@ void MenuSettingStringBase::draw(int y)
|
||||
ASFont::HAlignLeft, ASFont::VAlignTop);
|
||||
}
|
||||
|
||||
bool MenuSettingStringBase::manageInput(bevent_t *event)
|
||||
bool MenuSettingStringBase::manageInput(InputManager::ButtonEvent *event)
|
||||
{
|
||||
switch (event->button) {
|
||||
case CANCEL:
|
||||
clear();
|
||||
break;
|
||||
case ACCEPT:
|
||||
edit();
|
||||
break;
|
||||
default:
|
||||
switch (event->button) {
|
||||
case InputManager::CANCEL:
|
||||
clear();
|
||||
break;
|
||||
case InputManager::ACCEPT:
|
||||
edit();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
virtual ~MenuSettingStringBase();
|
||||
|
||||
virtual void draw(int y);
|
||||
virtual bool manageInput(bevent_t *event);
|
||||
virtual bool manageInput(InputManager::ButtonEvent *event);
|
||||
virtual bool edited();
|
||||
|
||||
void setValue(const std::string &value) { *_value = value; }
|
||||
|
@ -40,23 +40,23 @@ MessageBox::MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon)
|
||||
}
|
||||
|
||||
//Default enabled button
|
||||
buttons[ACCEPT] = "OK";
|
||||
buttons[InputManager::ACCEPT] = "OK";
|
||||
|
||||
//Default labels
|
||||
buttonLabels[UP] = "up";
|
||||
buttonLabels[DOWN] = "down";
|
||||
buttonLabels[LEFT] = "left";
|
||||
buttonLabels[RIGHT] = "right";
|
||||
buttonLabels[CANCEL] = "cancel";
|
||||
buttonLabels[ACCEPT] = "accept";
|
||||
buttonLabels[CLEAR] = "x";
|
||||
buttonLabels[MANUAL] = "y";
|
||||
buttonLabels[ALTLEFT] = "l";
|
||||
buttonLabels[ALTRIGHT] = "r";
|
||||
buttonLabels[SETTINGS] = "start";
|
||||
buttonLabels[MENU] = "select";
|
||||
buttonLabels[VOLUP] = "vol+";
|
||||
buttonLabels[VOLDOWN] = "vol-";
|
||||
buttonLabels[InputManager::UP] = "up";
|
||||
buttonLabels[InputManager::DOWN] = "down";
|
||||
buttonLabels[InputManager::LEFT] = "left";
|
||||
buttonLabels[InputManager::RIGHT] = "right";
|
||||
buttonLabels[InputManager::CANCEL] = "cancel";
|
||||
buttonLabels[InputManager::ACCEPT] = "accept";
|
||||
buttonLabels[InputManager::CLEAR] = "x";
|
||||
buttonLabels[InputManager::MANUAL] = "y";
|
||||
buttonLabels[InputManager::ALTLEFT] = "l";
|
||||
buttonLabels[InputManager::ALTRIGHT] = "r";
|
||||
buttonLabels[InputManager::SETTINGS] = "start";
|
||||
buttonLabels[InputManager::MENU] = "select";
|
||||
buttonLabels[InputManager::VOLUP] = "vol+";
|
||||
buttonLabels[InputManager::VOLDOWN] = "vol-";
|
||||
}
|
||||
|
||||
void MessageBox::setButton(int action, const string &btn) {
|
||||
@ -103,7 +103,7 @@ int MessageBox::exec() {
|
||||
bg.blit(gmenu2x->s,0,0);
|
||||
gmenu2x->s->flip();
|
||||
|
||||
bevent_t event;
|
||||
InputManager::ButtonEvent event;
|
||||
while (result<0) {
|
||||
|
||||
#ifdef PLATFORM_GP2X
|
||||
@ -119,14 +119,11 @@ int MessageBox::exec() {
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
gmenu2x->input.update();
|
||||
for (uint i=0; i<buttons.size(); i++)
|
||||
if (buttons[i]!="" && gmenu2x->input[i]) result = i;
|
||||
|
||||
*/
|
||||
|
||||
if (gmenu2x->input.pollEvent(&event) && (event.state == PRESSED) && (buttons[event.button] != "")) result = event.button;
|
||||
if (gmenu2x->input.pollEvent(&event)
|
||||
&& (event.state == InputManager::PRESSED)
|
||||
&& (buttons[event.button] != "")) {
|
||||
result = event.button;
|
||||
}
|
||||
|
||||
usleep(LOOP_DELAY);
|
||||
}
|
||||
|
@ -119,32 +119,32 @@ int Selector::exec(int startSelection) {
|
||||
gmenu2x->s->flip();
|
||||
|
||||
switch (gmenu2x->input.waitForPressedButton()) {
|
||||
case SETTINGS:
|
||||
case InputManager::SETTINGS:
|
||||
close = true;
|
||||
result = false;
|
||||
break;
|
||||
case UP:
|
||||
case InputManager::UP:
|
||||
if (selected == 0) selected = fl.size() -1;
|
||||
else selected -= 1;
|
||||
selTick = SDL_GetTicks();
|
||||
break;
|
||||
case ALTLEFT:
|
||||
case InputManager::ALTLEFT:
|
||||
if ((int)(selected-SELECTOR_ELEMENTS+1)<0) selected = 0;
|
||||
else selected -= SELECTOR_ELEMENTS-1;
|
||||
selTick = SDL_GetTicks();
|
||||
break;
|
||||
case DOWN:
|
||||
case InputManager::DOWN:
|
||||
if (selected+1>=fl.size()) selected = 0;
|
||||
else selected += 1;
|
||||
selTick = SDL_GetTicks();
|
||||
break;
|
||||
case ALTRIGHT:
|
||||
case InputManager::ALTRIGHT:
|
||||
if (selected+SELECTOR_ELEMENTS-1>=fl.size()) selected = fl.size()-1;
|
||||
else selected += SELECTOR_ELEMENTS-1;
|
||||
selTick = SDL_GetTicks();
|
||||
break;
|
||||
case CANCEL:
|
||||
case LEFT:
|
||||
case InputManager::CANCEL:
|
||||
case InputManager::LEFT:
|
||||
if (link->getSelectorBrowser()) {
|
||||
string::size_type p = dir.rfind("/", dir.size()-2);
|
||||
if (p==string::npos || dir.compare(0, 1, "/") != 0 || dir.length() < 2) {
|
||||
@ -159,7 +159,7 @@ int Selector::exec(int startSelection) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ACCEPT:
|
||||
case InputManager::ACCEPT:
|
||||
if (fl.isFile(selected)) {
|
||||
file = fl[selected];
|
||||
close = true;
|
||||
|
@ -105,17 +105,17 @@ bool SettingsDialog::exec() {
|
||||
gmenu2x->s->flip();
|
||||
voices[sel]->handleTS();
|
||||
|
||||
bevent_t event;
|
||||
do {
|
||||
inputMgr.waitForEvent(&event);
|
||||
} while (event.state != PRESSED);
|
||||
InputManager::ButtonEvent event;
|
||||
do {
|
||||
inputMgr.waitForEvent(&event);
|
||||
} while (event.state != InputManager::PRESSED);
|
||||
|
||||
if (voices[sel]->manageInput(&event) == false) {
|
||||
switch (event.button) {
|
||||
case SETTINGS:
|
||||
case InputManager::SETTINGS:
|
||||
close = true;
|
||||
break;
|
||||
case UP:
|
||||
case InputManager::UP:
|
||||
if (sel==0)
|
||||
sel = voices.size()-1;
|
||||
else
|
||||
@ -123,7 +123,7 @@ bool SettingsDialog::exec() {
|
||||
gmenu2x->setInputSpeed();
|
||||
voices[sel]->adjustInput();
|
||||
break;
|
||||
case DOWN:
|
||||
case InputManager::DOWN:
|
||||
sel += 1;
|
||||
if (sel>=voices.size()) sel = 0;
|
||||
gmenu2x->setInputSpeed();
|
||||
|
@ -113,52 +113,37 @@ void TextDialog::exec() {
|
||||
|
||||
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) {
|
||||
bg.blit(gmenu2x->s,0,0);
|
||||
bg.blit(gmenu2x->s, 0, 0);
|
||||
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 CANCEL:
|
||||
close = true;
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
switch(gmenu2x->input.waitForPressedButton()) {
|
||||
case InputManager::UP:
|
||||
if (firstRow > 0) firstRow--;
|
||||
break;
|
||||
case InputManager::DOWN:
|
||||
if (firstRow + rowsPerPage < text->size()) firstRow++;
|
||||
break;
|
||||
case InputManager::ALTLEFT:
|
||||
if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1;
|
||||
else firstRow = 0;
|
||||
break;
|
||||
case InputManager::ALTRIGHT:
|
||||
if (firstRow + rowsPerPage*2 -1 < text->size()) {
|
||||
firstRow += rowsPerPage-1;
|
||||
} else {
|
||||
firstRow = max(0, text->size() - rowsPerPage);
|
||||
}
|
||||
break;
|
||||
case InputManager::SETTINGS:
|
||||
case InputManager::CANCEL:
|
||||
close = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
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;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ void TextManualDialog::exec() {
|
||||
string spagecount;
|
||||
ss >> spagecount;
|
||||
string pageStatus;
|
||||
|
||||
|
||||
while (!close) {
|
||||
bg.blit(gmenu2x->s,0,0);
|
||||
writeSubTitle(pages[page].title);
|
||||
@ -103,60 +103,39 @@ 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 CANCEL:
|
||||
case SETTINGS:
|
||||
close = true;
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
switch(gmenu2x->input.waitForPressedButton()) {
|
||||
case InputManager::UP:
|
||||
if (firstRow > 0) firstRow--;
|
||||
break;
|
||||
case InputManager::DOWN:
|
||||
if (firstRow + rowsPerPage < pages[page].text.size()) firstRow++;
|
||||
break;
|
||||
case InputManager::LEFT:
|
||||
if (page > 0) {
|
||||
page--;
|
||||
firstRow = 0;
|
||||
}
|
||||
break;
|
||||
case InputManager::RIGHT:
|
||||
if (page < pages.size() -1) {
|
||||
page++;
|
||||
firstRow = 0;
|
||||
}
|
||||
break;
|
||||
case InputManager::ALTLEFT:
|
||||
if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1;
|
||||
else firstRow = 0;
|
||||
break;
|
||||
case InputManager::ALTRIGHT:
|
||||
if (firstRow + rowsPerPage*2 -1 < pages[page].text.size()) firstRow += rowsPerPage-1;
|
||||
else firstRow = max(0, pages[page].text.size() - rowsPerPage);
|
||||
break;
|
||||
case InputManager::CANCEL:
|
||||
case InputManager::SETTINGS:
|
||||
close = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
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;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -108,27 +108,27 @@ bool WallpaperDialog::exec()
|
||||
gmenu2x->s->flip();
|
||||
|
||||
switch(gmenu2x->input.waitForPressedButton()) {
|
||||
case CANCEL:
|
||||
case InputManager::CANCEL:
|
||||
close = true;
|
||||
result = false;
|
||||
break;
|
||||
case UP:
|
||||
case InputManager::UP:
|
||||
if (selected == 0) selected = wallpapers.size()-1;
|
||||
else selected -= 1;
|
||||
break;
|
||||
case ALTLEFT:
|
||||
case InputManager::ALTLEFT:
|
||||
if ((int)(selected-9) < 0) selected = 0;
|
||||
else selected -= 9;
|
||||
break;
|
||||
case DOWN:
|
||||
case InputManager::DOWN:
|
||||
if (selected+1 >= wallpapers.size()) selected = 0;
|
||||
else selected += 1;
|
||||
break;
|
||||
case ALTRIGHT:
|
||||
case InputManager::ALTRIGHT:
|
||||
if (selected+9 >= wallpapers.size()) selected = wallpapers.size()-1;
|
||||
else selected += 9;
|
||||
break;
|
||||
case ACCEPT:
|
||||
case InputManager::ACCEPT:
|
||||
close = true;
|
||||
if (wallpapers.size() > 0)
|
||||
wallpaper = gmenu2x->sc.getSkinFilePath("wallpapers/" + wallpapers[selected]);
|
||||
|
Loading…
Reference in New Issue
Block a user