1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 16:54:04 +02:00

SettingsDialog: simplify code using InputManager::waitForPressedButton().

Replaced MenuSetting::manageInput() by handleButtonPress(), because we will
only pass pressed buttons to it, not the entire input event.
This commit is contained in:
Maarten ter Huurne 2011-10-23 09:38:59 +02:00
parent 40fd35d764
commit a38c283e17
12 changed files with 46 additions and 49 deletions

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(InputManager::ButtonEvent *event) = 0; virtual bool handleButtonPress(InputManager::Button button) = 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,14 +64,14 @@ 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(InputManager::ButtonEvent *event) bool MenuSettingBool::handleButtonPress(InputManager::Button button)
{ {
if (event->button == InputManager::ACCEPT if (button == InputManager::ACCEPT) {
&& event->state == InputManager::PRESSED) {
toggle(); toggle();
return true; return true;
} else {
return false;
} }
return false;
} }
void MenuSettingBool::toggle() void MenuSettingBool::toggle()

View File

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

View File

@ -66,24 +66,24 @@ 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(InputManager::ButtonEvent *event) bool MenuSettingInt::handleButtonPress(InputManager::Button button)
{ {
switch (event->button) { switch (button) {
case InputManager::LEFT: case InputManager::LEFT:
dec(); dec();
break; break;
case InputManager::RIGHT: case InputManager::RIGHT:
inc(); inc();
break; break;
case InputManager::ALTLEFT: case InputManager::ALTLEFT:
setValue(value() - 10 * increment); setValue(value() - 10 * increment);
break; break;
case InputManager::ALTRIGHT: case InputManager::ALTRIGHT:
setValue(value() + 10 * increment); setValue(value() + 10 * increment);
break; break;
default: default:
return false; return false;
} }
return true; return true;
} }

View File

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

View File

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

View File

@ -28,7 +28,7 @@
class MenuSettingMultiString : public MenuSettingStringBase { class MenuSettingMultiString : public MenuSettingStringBase {
private: private:
virtual void edit() { virtual void edit() {
/* never called because manageInput() is overridden */ /* never called because handleButtonPress() is overridden */
} }
const std::vector<std::string> *choices; const std::vector<std::string> *choices;
@ -45,7 +45,7 @@ public:
const std::vector<std::string> *choices); const std::vector<std::string> *choices);
virtual ~MenuSettingMultiString() {}; virtual ~MenuSettingMultiString() {};
virtual bool manageInput(InputManager::ButtonEvent *event); virtual bool handleButtonPress(InputManager::Button button);
}; };
#endif #endif

View File

@ -68,9 +68,10 @@ void MenuSettingRGBA::handleTS() {
MenuSetting::handleTS(); MenuSetting::handleTS();
} }
bool MenuSettingRGBA::manageInput(InputManager::ButtonEvent *event) { bool MenuSettingRGBA::handleButtonPress(InputManager::Button button)
{
if (edit) { if (edit) {
switch(event->button) { switch (button) {
case InputManager::LEFT: case InputManager::LEFT:
dec(); dec();
break; break;
@ -93,7 +94,7 @@ bool MenuSettingRGBA::manageInput(InputManager::ButtonEvent *event) {
return false; return false;
} }
} else { } else {
switch(event->button) { switch (button) {
case InputManager::LEFT: case InputManager::LEFT:
leftComponent(); leftComponent();
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(InputManager::ButtonEvent *event); virtual bool handleButtonPress(InputManager::Button button);
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,9 +42,9 @@ void MenuSettingStringBase::draw(int y)
ASFont::HAlignLeft, ASFont::VAlignTop); ASFont::HAlignLeft, ASFont::VAlignTop);
} }
bool MenuSettingStringBase::manageInput(InputManager::ButtonEvent *event) bool MenuSettingStringBase::handleButtonPress(InputManager::Button button)
{ {
switch (event->button) { switch (button) {
case InputManager::CANCEL: case InputManager::CANCEL:
clear(); clear();
break; break;

View File

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

View File

@ -105,13 +105,9 @@ bool SettingsDialog::exec() {
gmenu2x->s->flip(); gmenu2x->s->flip();
voices[sel]->handleTS(); voices[sel]->handleTS();
InputManager::ButtonEvent event; InputManager::Button button = inputMgr.waitForPressedButton();
do { if (!voices[sel]->handleButtonPress(button)) {
inputMgr.waitForEvent(&event); switch (button) {
} while (event.state != InputManager::PRESSED);
if (voices[sel]->manageInput(&event) == false) {
switch (event.button) {
case InputManager::SETTINGS: case InputManager::SETTINGS:
close = true; close = true;
break; break;