Root/src/menusettingint.cpp

1/***************************************************************************
2 * Copyright (C) 2006 by Massimiliano Torromeo *
3 * massimiliano.torromeo@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20#include "menusettingint.h"
21#include "gmenu2x.h"
22#include "utilities.h"
23
24#include <sstream>
25
26using std::string;
27using std::stringstream;
28using fastdelegate::MakeDelegate;
29
30MenuSettingInt::MenuSettingInt(GMenu2X *gmenu2x, const string &name, const string &description, int *value, int min, int max)
31    : MenuSetting(gmenu2x,name,description)
32{
33    IconButton *btn;
34
35    _value = value;
36    originalValue = *value;
37    this->min = min;
38    this->max = max;
39    setValue(this->value());
40
41    //Delegates
42    ButtonAction actionInc = MakeDelegate(this, &MenuSettingInt::inc);
43    ButtonAction actionDec = MakeDelegate(this, &MenuSettingInt::dec);
44
45    btn = new IconButton(gmenu2x, "skin:imgs/buttons/left.png");
46    btn->setAction(actionDec);
47    buttonBox.add(btn);
48
49    btn = new IconButton(gmenu2x, "skin:imgs/buttons/y.png", gmenu2x->tr["Increase value"]);
50    btn->setAction(actionInc);
51    buttonBox.add(btn);
52
53    btn = new IconButton(gmenu2x, "skin:imgs/buttons/right.png");
54    btn->setAction(actionInc);
55    buttonBox.add(btn);
56
57    btn = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Decrease value"]);
58    btn->setAction(actionDec);
59    buttonBox.add(btn);
60}
61
62void MenuSettingInt::draw(int y)
63{
64    MenuSetting::draw(y);
65    gmenu2x->s->write( gmenu2x->font, strvalue, 155, y, ASFont::HAlignLeft, ASFont::VAlignTop );
66}
67
68void MenuSettingInt::manageInput(bevent_t *event)
69{
70    switch (event->button) {
71        case LEFT:
72            dec();
73            break;
74        case RIGHT:
75            inc();
76            break;
77        case ALTLEFT:
78            setValue(value() - 10);
79            break;
80        case ALTRIGHT:
81            setValue(value() + 10);
82            break;
83        default:
84            break;
85    }
86}
87
88void MenuSettingInt::inc()
89{
90    setValue(value() + 1);
91}
92
93void MenuSettingInt::dec()
94{
95    setValue(value() - 1);
96}
97
98void MenuSettingInt::setValue(int value)
99{
100    *_value = constrain(value,min,max);
101    stringstream ss;
102    ss << *_value;
103    strvalue = "";
104    ss >> strvalue;
105}
106
107int MenuSettingInt::value()
108{
109    return *_value;
110}
111
112void MenuSettingInt::adjustInput()
113{
114#ifdef TARGET_GP2X
115// gmenu2x->input.setInterval(30, ACTION_LEFT );
116// gmenu2x->input.setInterval(30, ACTION_RIGHT);
117#endif
118}
119
120bool MenuSettingInt::edited()
121{
122    return originalValue != value();
123}
124

Archive Download this file



interactive