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 "menusettingint.h"
|
2010-07-28 03:36:46 +03:00
|
|
|
#include "gmenu2x.h"
|
2010-02-04 13:33:47 +02:00
|
|
|
#include "utilities.h"
|
2010-07-28 03:36:46 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2010-07-28 03:36:46 +03:00
|
|
|
using std::string;
|
|
|
|
using std::stringstream;
|
|
|
|
using fastdelegate::MakeDelegate;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
MenuSettingInt::MenuSettingInt(GMenu2X *gmenu2x, const string &name, const string &description, int *value, int min, int max)
|
2010-05-03 23:21:36 +03:00
|
|
|
: MenuSetting(gmenu2x,name,description)
|
|
|
|
{
|
|
|
|
IconButton *btn;
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
_value = value;
|
|
|
|
originalValue = *value;
|
|
|
|
this->min = min;
|
|
|
|
this->max = max;
|
|
|
|
setValue(this->value());
|
|
|
|
|
|
|
|
//Delegates
|
|
|
|
ButtonAction actionInc = MakeDelegate(this, &MenuSettingInt::inc);
|
|
|
|
ButtonAction actionDec = MakeDelegate(this, &MenuSettingInt::dec);
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
btn = new IconButton(gmenu2x, "skin:imgs/buttons/left.png");
|
|
|
|
btn->setAction(actionDec);
|
|
|
|
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/y.png", gmenu2x->tr["Increase value"]);
|
|
|
|
btn->setAction(actionInc);
|
|
|
|
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");
|
|
|
|
btn->setAction(actionInc);
|
|
|
|
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/x.png", gmenu2x->tr["Decrease value"]);
|
|
|
|
btn->setAction(actionDec);
|
|
|
|
buttonBox.add(btn);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingInt::draw(int y)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
MenuSetting::draw(y);
|
2011-05-10 01:31:45 +03:00
|
|
|
gmenu2x->s->write( gmenu2x->font, strvalue, 155, y, ASFont::HAlignLeft, ASFont::VAlignTop );
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-09-17 23:34:26 +03:00
|
|
|
void MenuSettingInt::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:
|
|
|
|
dec();
|
|
|
|
break;
|
|
|
|
case RIGHT:
|
|
|
|
inc();
|
|
|
|
break;
|
2010-09-19 01:50:16 +03:00
|
|
|
case ALTLEFT:
|
|
|
|
setValue(value() - 10);
|
|
|
|
break;
|
|
|
|
case ALTRIGHT:
|
|
|
|
setValue(value() + 10);
|
|
|
|
break;
|
2010-09-17 23:34:26 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingInt::inc()
|
|
|
|
{
|
|
|
|
setValue(value() + 1);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingInt::dec()
|
|
|
|
{
|
|
|
|
setValue(value() - 1);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingInt::setValue(int value)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
*_value = constrain(value,min,max);
|
|
|
|
stringstream ss;
|
|
|
|
ss << *_value;
|
|
|
|
strvalue = "";
|
|
|
|
ss >> strvalue;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
int MenuSettingInt::value()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
return *_value;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingInt::adjustInput()
|
|
|
|
{
|
2011-07-29 02:13:35 +03:00
|
|
|
#ifdef PLATFORM_GP2X
|
2010-09-17 23:34:26 +03:00
|
|
|
// gmenu2x->input.setInterval(30, ACTION_LEFT );
|
|
|
|
// gmenu2x->input.setInterval(30, ACTION_RIGHT);
|
2010-02-04 13:33:47 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
bool MenuSettingInt::edited()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
return originalValue != value();
|
|
|
|
}
|