Root/
Source at commit d4490ba created 13 years 10 months ago. By Lars-Peter Clausen, remove redundant assignments | |
---|---|
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 "menusettingbool.h" |
21 | #include "utilities.h" |
22 | #include <sstream> |
23 | |
24 | using namespace std; |
25 | using namespace fastdelegate; |
26 | |
27 | MenuSettingBool::MenuSettingBool(GMenu2X *gmenu2x, const string &name, const string &description, int *value) |
28 | : MenuSetting(gmenu2x,name,description) { |
29 | _ivalue = value; |
30 | _value = NULL; |
31 | originalValue = *value != 0; |
32 | setValue(this->value()); |
33 | |
34 | btnToggle = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Switch"]); |
35 | btnToggle->setAction(MakeDelegate(this, &MenuSettingBool::toggle)); |
36 | } |
37 | |
38 | MenuSettingBool::MenuSettingBool(GMenu2X *gmenu2x, const string &name, const string &description, bool *value) |
39 | : MenuSetting(gmenu2x,name,description) { |
40 | _value = value; |
41 | _ivalue = NULL; |
42 | originalValue = *value; |
43 | setValue(this->value()); |
44 | |
45 | btnToggle = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Switch"]); |
46 | btnToggle->setAction(MakeDelegate(this, &MenuSettingBool::toggle)); |
47 | } |
48 | |
49 | void MenuSettingBool::draw(int y) { |
50 | MenuSetting::draw(y); |
51 | gmenu2x->s->write( gmenu2x->font, strvalue, 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); |
52 | } |
53 | |
54 | void MenuSettingBool::handleTS() { |
55 | btnToggle->handleTS(); |
56 | } |
57 | |
58 | void MenuSettingBool::manageInput() { |
59 | if ( gmenu2x->input[ACTION_B] ) toggle(); |
60 | } |
61 | |
62 | void MenuSettingBool::toggle() { |
63 | setValue(!value()); |
64 | } |
65 | |
66 | void MenuSettingBool::setValue(int value) { |
67 | setValue(value != 0); |
68 | } |
69 | |
70 | void MenuSettingBool::setValue(bool value) { |
71 | if (_value == NULL) |
72 | *_ivalue = value; |
73 | else |
74 | *_value = value; |
75 | strvalue = value ? "ON" : "OFF"; |
76 | } |
77 | |
78 | bool MenuSettingBool::value() { |
79 | if (_value == NULL) |
80 | return *_ivalue != 0; |
81 | else |
82 | return *_value; |
83 | } |
84 | |
85 | void MenuSettingBool::adjustInput() {} |
86 | |
87 | void MenuSettingBool::drawSelected(int) { |
88 | gmenu2x->drawButton(btnToggle); |
89 | } |
90 | |
91 | bool MenuSettingBool::edited() { |
92 | return originalValue != value(); |
93 | } |
94 |
Branches:
install_locations
master
opkrun
packages