Root/
Source at commit 00d3c3b57008bddf8770c51271db9d766acaf854 created 8 years 11 months ago. By Maarten ter Huurne, Gave Layer class a protected constructor | |
---|---|
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 "menusettingbool.h" |
22 | |
23 | #include "gmenu2x.h" |
24 | #include "iconbutton.h" |
25 | #include "surface.h" |
26 | #include "utilities.h" |
27 | |
28 | #include <sstream> |
29 | |
30 | using std::bind; |
31 | using std::string; |
32 | using std::unique_ptr; |
33 | |
34 | MenuSettingBool::MenuSettingBool( |
35 | GMenu2X& gmenu2x, |
36 | const string &name, const string &description, int *value) |
37 | : MenuSetting(gmenu2x, name, description) |
38 | { |
39 | _ivalue = value; |
40 | _value = NULL; |
41 | originalValue = *value != 0; |
42 | setValue(this->value()); |
43 | initButton(); |
44 | } |
45 | |
46 | MenuSettingBool::MenuSettingBool( |
47 | GMenu2X& gmenu2x, |
48 | const string &name, const string &description, bool *value) |
49 | : MenuSetting(gmenu2x, name, description) |
50 | { |
51 | _value = value; |
52 | _ivalue = NULL; |
53 | originalValue = *value; |
54 | setValue(this->value()); |
55 | initButton(); |
56 | } |
57 | |
58 | void MenuSettingBool::initButton() |
59 | { |
60 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
61 | gmenu2x, "skin:imgs/buttons/accept.png", |
62 | gmenu2x.tr["Switch"], |
63 | bind(&MenuSettingBool::toggle, this)))); |
64 | } |
65 | |
66 | void MenuSettingBool::draw(int valueX, int y, int h) |
67 | { |
68 | Surface& s = *gmenu2x.s; |
69 | MenuSetting::draw(valueX, y, h); |
70 | gmenu2x.font->write(s, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop); |
71 | } |
72 | |
73 | bool MenuSettingBool::handleButtonPress(InputManager::Button button) |
74 | { |
75 | switch (button) { |
76 | case InputManager::ACCEPT: |
77 | case InputManager::LEFT: |
78 | case InputManager::RIGHT: |
79 | toggle(); |
80 | break; |
81 | default: |
82 | return false; |
83 | } |
84 | return true; |
85 | } |
86 | |
87 | void MenuSettingBool::toggle() |
88 | { |
89 | setValue(!value()); |
90 | } |
91 | |
92 | void MenuSettingBool::setValue(int value) |
93 | { |
94 | setValue(value != 0); |
95 | } |
96 | |
97 | void MenuSettingBool::setValue(bool value) |
98 | { |
99 | if (_value == NULL) |
100 | *_ivalue = value; |
101 | else |
102 | *_value = value; |
103 | strvalue = value ? "ON" : "OFF"; |
104 | } |
105 | |
106 | bool MenuSettingBool::value() |
107 | { |
108 | if (_value == NULL) |
109 | return *_ivalue != 0; |
110 | else |
111 | return *_value; |
112 | } |
113 | |
114 | bool MenuSettingBool::edited() |
115 | { |
116 | return originalValue != value(); |
117 | } |
118 |
Branches:
install_locations
master
opkrun
packages