Root/
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 | |
21 | #include "menusettingint.h" |
22 | |
23 | #include "delegate.h" |
24 | #include "gmenu2x.h" |
25 | #include "iconbutton.h" |
26 | #include "surface.h" |
27 | #include "utilities.h" |
28 | |
29 | #include <sstream> |
30 | |
31 | using std::string; |
32 | using std::stringstream; |
33 | |
34 | MenuSettingInt::MenuSettingInt( |
35 | GMenu2X *gmenu2x, Touchscreen &ts, |
36 | const string &name, const string &description, |
37 | int *value, int min, int max, int increment) |
38 | : MenuSetting(gmenu2x,name,description) |
39 | { |
40 | IconButton *btn; |
41 | |
42 | _value = value; |
43 | originalValue = *value; |
44 | this->min = min; |
45 | this->max = max; |
46 | this->increment = increment; |
47 | setValue(this->value()); |
48 | |
49 | //Delegates |
50 | function_t actionInc = BIND(&MenuSettingInt::inc); |
51 | function_t actionDec = BIND(&MenuSettingInt::dec); |
52 | |
53 | btn = new IconButton(gmenu2x, ts, "skin:imgs/buttons/l.png"); |
54 | btn->setAction(actionDec); |
55 | buttonBox.add(btn); |
56 | |
57 | btn = new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x->tr["Decrease"]); |
58 | btn->setAction(actionDec); |
59 | buttonBox.add(btn); |
60 | |
61 | btn = new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png"); |
62 | btn->setAction(actionInc); |
63 | buttonBox.add(btn); |
64 | |
65 | btn = new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x->tr["Increase"]); |
66 | btn->setAction(actionInc); |
67 | buttonBox.add(btn); |
68 | } |
69 | |
70 | void MenuSettingInt::draw(int y) |
71 | { |
72 | MenuSetting::draw(y); |
73 | gmenu2x->s->write(gmenu2x->font, strvalue, 155, y, Font::HAlignLeft, Font::VAlignTop); |
74 | } |
75 | |
76 | bool MenuSettingInt::handleButtonPress(InputManager::Button button) |
77 | { |
78 | switch (button) { |
79 | case InputManager::LEFT: |
80 | dec(); |
81 | break; |
82 | case InputManager::RIGHT: |
83 | inc(); |
84 | break; |
85 | case InputManager::ALTLEFT: |
86 | setValue(value() - 10 * increment); |
87 | break; |
88 | case InputManager::ALTRIGHT: |
89 | setValue(value() + 10 * increment); |
90 | break; |
91 | default: |
92 | return false; |
93 | } |
94 | return true; |
95 | } |
96 | |
97 | void MenuSettingInt::inc() |
98 | { |
99 | setValue(value() + increment); |
100 | } |
101 | |
102 | void MenuSettingInt::dec() |
103 | { |
104 | setValue(value() - increment); |
105 | } |
106 | |
107 | void MenuSettingInt::setValue(int value) |
108 | { |
109 | *_value = constrain(value,min,max); |
110 | stringstream ss; |
111 | ss << *_value; |
112 | strvalue = ""; |
113 | ss >> strvalue; |
114 | } |
115 | |
116 | int MenuSettingInt::value() |
117 | { |
118 | return *_value; |
119 | } |
120 | |
121 | bool MenuSettingInt::edited() |
122 | { |
123 | return originalValue != value(); |
124 | } |
125 |
Branches:
install_locations
master
opkrun
packages