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(
|
2011-12-23 15:03:05 +02:00
|
|
|
GMenu2X *gmenu2x, Touchscreen &ts,
|
|
|
|
const string &name, const string &description,
|
|
|
|
string *value, const vector<string> *choices_)
|
2010-07-28 03:06:49 +03:00
|
|
|
: 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
|
|
|
|
2011-12-23 15:03:05 +02:00
|
|
|
btn = new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png");
|
2010-05-03 23:21:36 +03:00
|
|
|
btn->setAction(MakeDelegate(this, &MenuSettingMultiString::decSel));
|
|
|
|
buttonBox.add(btn);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-12-23 15:03:05 +02:00
|
|
|
btn = new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x->tr["Change value"]);
|
2010-05-03 23:21:36 +03:00
|
|
|
btn->setAction(MakeDelegate(this, &MenuSettingMultiString::incSel));
|
|
|
|
buttonBox.add(btn);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2011-10-23 10:38:59 +03:00
|
|
|
bool MenuSettingMultiString::handleButtonPress(InputManager::Button button)
|
2010-05-03 23:21:36 +03:00
|
|
|
{
|
2011-10-23 10:38:59 +03:00
|
|
|
switch (button) {
|
|
|
|
case InputManager::LEFT:
|
|
|
|
decSel();
|
|
|
|
break;
|
|
|
|
case InputManager::RIGHT:
|
|
|
|
incSel();
|
|
|
|
break;
|
|
|
|
default:
|
2011-09-15 21:20:35 +03:00
|
|
|
return false;
|
2011-10-23 10:38:59 +03:00
|
|
|
}
|
2011-09-15 21:20:35 +03:00
|
|
|
return true;
|
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
|
|
|
}
|