1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-02 18:32:20 +03: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 handleTS();
virtual bool manageInput(InputManager::ButtonEvent *event) = 0;
virtual bool handleButtonPress(InputManager::Button button) = 0;
virtual void adjustInput();
virtual void drawSelected(int y);
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 );
}
bool MenuSettingBool::manageInput(InputManager::ButtonEvent *event)
bool MenuSettingBool::handleButtonPress(InputManager::Button button)
{
if (event->button == InputManager::ACCEPT
&& event->state == InputManager::PRESSED) {
if (button == InputManager::ACCEPT) {
toggle();
return true;
} else {
return false;
}
return false;
}
void MenuSettingBool::toggle()

View File

@ -45,7 +45,7 @@ public:
virtual ~MenuSettingBool() {}
virtual void draw(int y);
virtual bool manageInput(InputManager::ButtonEvent *event);
virtual bool handleButtonPress(InputManager::Button button);
virtual bool edited();
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 );
}
bool MenuSettingInt::manageInput(InputManager::ButtonEvent *event)
bool MenuSettingInt::handleButtonPress(InputManager::Button button)
{
switch (event->button) {
case InputManager::LEFT:
dec();
break;
case InputManager::RIGHT:
inc();
break;
case InputManager::ALTLEFT:
setValue(value() - 10 * increment);
break;
case InputManager::ALTRIGHT:
setValue(value() + 10 * increment);
break;
default:
switch (button) {
case InputManager::LEFT:
dec();
break;
case InputManager::RIGHT:
inc();
break;
case InputManager::ALTLEFT:
setValue(value() - 10 * increment);
break;
case InputManager::ALTRIGHT:
setValue(value() + 10 * increment);
break;
default:
return false;
}
}
return true;
}

View File

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

View File

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

View File

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

View File

@ -68,9 +68,10 @@ void MenuSettingRGBA::handleTS() {
MenuSetting::handleTS();
}
bool MenuSettingRGBA::manageInput(InputManager::ButtonEvent *event) {
bool MenuSettingRGBA::handleButtonPress(InputManager::Button button)
{
if (edit) {
switch(event->button) {
switch (button) {
case InputManager::LEFT:
dec();
break;
@ -93,7 +94,7 @@ bool MenuSettingRGBA::manageInput(InputManager::ButtonEvent *event) {
return false;
}
} else {
switch(event->button) {
switch (button) {
case InputManager::LEFT:
leftComponent();
break;

View File

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

View File

@ -42,9 +42,9 @@ void MenuSettingStringBase::draw(int y)
ASFont::HAlignLeft, ASFont::VAlignTop);
}
bool MenuSettingStringBase::manageInput(InputManager::ButtonEvent *event)
bool MenuSettingStringBase::handleButtonPress(InputManager::Button button)
{
switch (event->button) {
switch (button) {
case InputManager::CANCEL:
clear();
break;

View File

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

View File

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