mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 17:17:31 +02:00
Made MenuSettingMultiString a subclass of MenuSettingStringBase.
This commit is contained in:
parent
44bed79d5c
commit
961e030670
@ -18,21 +18,21 @@
|
|||||||
* 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;
|
|
||||||
|
|
||||||
this->choices = choices;
|
|
||||||
this->value = value;
|
|
||||||
originalValue = *value;
|
|
||||||
setSel(find(choices->begin(), choices->end(), *value) - choices->begin());
|
setSel(find(choices->begin(), choices->end(), *value) - choices->begin());
|
||||||
|
|
||||||
|
IconButton *btn;
|
||||||
|
|
||||||
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));
|
||||||
buttonBox.add(btn);
|
buttonBox.add(btn);
|
||||||
@ -42,18 +42,10 @@ 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()
|
||||||
@ -68,15 +60,11 @@ void MenuSettingMultiString::decSel()
|
|||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user