1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 03:06:15 +02:00

Made MenuSettingMultiString a subclass of MenuSettingStringBase.

This commit is contained in:
Maarten ter Huurne 2010-07-28 02:06:49 +02:00
parent 44bed79d5c
commit 961e030670
2 changed files with 28 additions and 39 deletions

View File

@ -18,20 +18,20 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "menusettingmultistring.h" #include "menusettingmultistring.h"
#include "utilities.h"
using namespace std; using namespace std;
using namespace fastdelegate; using namespace fastdelegate;
MenuSettingMultiString::MenuSettingMultiString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const vector<string> *choices) MenuSettingMultiString::MenuSettingMultiString(
: MenuSetting(gmenu2x,name,description) GMenu2X *gmenu2x, const string &name,
const string &description, string *value,
const vector<string> *choices_)
: MenuSettingStringBase(gmenu2x, name, description, value)
, choices(choices_)
{ {
IconButton *btn; setSel(find(choices->begin(), choices->end(), *value) - choices->begin());
this->choices = choices; IconButton *btn;
this->value = value;
originalValue = *value;
setSel( find(choices->begin(),choices->end(),*value)-choices->begin() );
btn = new IconButton(gmenu2x, "skin:imgs/buttons/left.png"); btn = new IconButton(gmenu2x, "skin:imgs/buttons/left.png");
btn->setAction(MakeDelegate(this, &MenuSettingMultiString::decSel)); btn->setAction(MakeDelegate(this, &MenuSettingMultiString::decSel));
@ -42,41 +42,29 @@ MenuSettingMultiString::MenuSettingMultiString(GMenu2X *gmenu2x, const string &n
buttonBox.add(btn); buttonBox.add(btn);
} }
void MenuSettingMultiString::draw(int y)
{
MenuSetting::draw(y);
gmenu2x->s->write( gmenu2x->font, *value, 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle );
}
void MenuSettingMultiString::manageInput() void MenuSettingMultiString::manageInput()
{ {
if (gmenu2x->input[ACTION_LEFT ]) if (gmenu2x->input[ACTION_LEFT ]) decSel();
decSel(); if (gmenu2x->input[ACTION_RIGHT]) incSel();
if (gmenu2x->input[ACTION_RIGHT])
incSel();
} }
void MenuSettingMultiString::incSel() void MenuSettingMultiString::incSel()
{ {
setSel(selected+1); setSel(selected + 1);
} }
void MenuSettingMultiString::decSel() void MenuSettingMultiString::decSel()
{ {
setSel(selected-1); setSel(selected - 1);
} }
void MenuSettingMultiString::setSel(int sel) void MenuSettingMultiString::setSel(int sel)
{ {
if (sel < 0) if (sel < 0) {
sel = choices->size()-1; sel = choices->size()-1;
else if (sel >= (int)choices->size()) } else if (sel >= (int)choices->size()) {
sel = 0; sel = 0;
}
selected = sel; selected = sel;
*value = (*choices)[sel]; setValue((*choices)[sel]);
}
bool MenuSettingMultiString::edited()
{
return originalValue != *value;
} }

View File

@ -20,30 +20,31 @@
#ifndef MENUSETTINGMULTISTRING_H #ifndef MENUSETTINGMULTISTRING_H
#define MENUSETTINGMULTISTRING_H #define MENUSETTINGMULTISTRING_H
#include "gmenu2x.h" #include "menusettingstringbase.h"
#include "menusetting.h"
using std::string; using std::string;
class MenuSettingMultiString : public MenuSetting { class MenuSettingMultiString : public MenuSettingStringBase {
private: private:
uint selected; virtual void edit() {
string *value; /* never called because manageInput() is overridden */
string originalValue; }
const vector<string> *choices; const vector<string> *choices;
IconButton *btnDec, *btnInc; uint selected;
void incSel(); void incSel();
void decSel(); void decSel();
void setSel(int); void setSel(int sel);
public: public:
MenuSettingMultiString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const vector<string> *choices); MenuSettingMultiString(
GMenu2X *gmenu2x, const string &name,
const string &description, string *value,
const vector<string> *choices);
virtual ~MenuSettingMultiString() {}; virtual ~MenuSettingMultiString() {};
virtual void draw(int y);
virtual void manageInput(); virtual void manageInput();
virtual bool edited();
}; };
#endif #endif