2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#include "menusettingmultistring.h"
|
2010-07-28 03:36:46 +03:00
|
|
|
#include "gmenu2x.h"
|
|
|
|
#include "iconbutton.h"
|
|
|
|
#include "FastDelegate.h"
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-07-28 04:31:41 +03:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using std::find;
|
2010-07-28 03:36:46 +03:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
using fastdelegate::MakeDelegate;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-07-28 03:06:49 +03:00
|
|
|
MenuSettingMultiString::MenuSettingMultiString(
|
|
|
|
GMenu2X *gmenu2x, const string &name,
|
|
|
|
const string &description, string *value,
|
|
|
|
const vector<string> *choices_)
|
|
|
|
: MenuSettingStringBase(gmenu2x, name, description, value)
|
|
|
|
, choices(choices_)
|
2010-05-03 23:21:36 +03:00
|
|
|
{
|
2010-07-28 03:06:49 +03:00
|
|
|
setSel(find(choices->begin(), choices->end(), *value) - choices->begin());
|
2010-05-03 23:21:36 +03:00
|
|
|
|
2010-07-28 03:06:49 +03:00
|
|
|
IconButton *btn;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
btn = new IconButton(gmenu2x, "skin:imgs/buttons/left.png");
|
|
|
|
btn->setAction(MakeDelegate(this, &MenuSettingMultiString::decSel));
|
|
|
|
buttonBox.add(btn);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
btn = new IconButton(gmenu2x, "skin:imgs/buttons/right.png", gmenu2x->tr["Change value"]);
|
|
|
|
btn->setAction(MakeDelegate(this, &MenuSettingMultiString::incSel));
|
|
|
|
buttonBox.add(btn);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-09-17 23:34:26 +03:00
|
|
|
void MenuSettingMultiString::manageInput(bevent_t *event)
|
2010-05-03 23:21:36 +03:00
|
|
|
{
|
2010-09-17 23:34:26 +03:00
|
|
|
switch(event->button) {
|
|
|
|
case LEFT:
|
|
|
|
decSel();
|
|
|
|
break;
|
|
|
|
case RIGHT:
|
|
|
|
incSel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingMultiString::incSel()
|
|
|
|
{
|
2010-07-28 03:06:49 +03:00
|
|
|
setSel(selected + 1);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingMultiString::decSel()
|
|
|
|
{
|
2010-07-28 03:06:49 +03:00
|
|
|
setSel(selected - 1);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingMultiString::setSel(int sel)
|
|
|
|
{
|
2010-07-28 03:06:49 +03:00
|
|
|
if (sel < 0) {
|
2010-05-03 23:21:36 +03:00
|
|
|
sel = choices->size()-1;
|
2010-07-28 03:06:49 +03:00
|
|
|
} else if (sel >= (int)choices->size()) {
|
2010-05-03 23:21:36 +03:00
|
|
|
sel = 0;
|
2010-07-28 03:06:49 +03:00
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
selected = sel;
|
2010-07-28 03:06:49 +03:00
|
|
|
setValue((*choices)[sel]);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|