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 "menusettingrgba.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::string; |
| 31 | using std::stringstream; |
| 32 | |
| 33 | MenuSettingRGBA::MenuSettingRGBA( |
| 34 | GMenu2X *gmenu2x, Touchscreen &ts_, |
| 35 | const string &name, const string &description, RGBAColor *value) |
| 36 | : MenuSetting(gmenu2x, name, description) |
| 37 | , ts(ts_) |
| 38 | { |
| 39 | edit = false; |
| 40 | |
| 41 | selPart = 0; |
| 42 | _value = value; |
| 43 | originalValue = *value; |
| 44 | this->setR(this->value().r); |
| 45 | this->setG(this->value().g); |
| 46 | this->setB(this->value().b); |
| 47 | this->setA(this->value().a); |
| 48 | |
| 49 | updateButtonBox(); |
| 50 | } |
| 51 | |
| 52 | void MenuSettingRGBA::draw(int y) { |
| 53 | this->y = y; |
| 54 | MenuSetting::draw(y); |
| 55 | gmenu2x->s->rectangle( 153, y+1, 11, 11, 0,0,0,255 ); |
| 56 | gmenu2x->s->box( 154, y+2, 9, 9, value() ); |
| 57 | gmenu2x->s->write( gmenu2x->font, "R: "+strR, 169, y, Font::HAlignLeft, Font::VAlignTop ); |
| 58 | gmenu2x->s->write( gmenu2x->font, "G: "+strG, 205, y, Font::HAlignLeft, Font::VAlignTop ); |
| 59 | gmenu2x->s->write( gmenu2x->font, "B: "+strB, 241, y, Font::HAlignLeft, Font::VAlignTop ); |
| 60 | gmenu2x->s->write( gmenu2x->font, "A: "+strA, 277, y, Font::HAlignLeft, Font::VAlignTop ); |
| 61 | } |
| 62 | |
| 63 | void MenuSettingRGBA::handleTS() { |
| 64 | if (ts.pressed()) { |
| 65 | for (int i=0; i<4; i++) { |
| 66 | if (i!=selPart && ts.inRect(166+i*36,y,36,14)) { |
| 67 | selPart = i; |
| 68 | i = 4; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | MenuSetting::handleTS(); |
| 74 | } |
| 75 | |
| 76 | bool MenuSettingRGBA::handleButtonPress(InputManager::Button button) |
| 77 | { |
| 78 | if (edit) { |
| 79 | switch (button) { |
| 80 | case InputManager::LEFT: |
| 81 | dec(); |
| 82 | break; |
| 83 | case InputManager::RIGHT: |
| 84 | inc(); |
| 85 | break; |
| 86 | case InputManager::ALTLEFT: |
| 87 | update_value(-10); |
| 88 | break; |
| 89 | case InputManager::ALTRIGHT: |
| 90 | update_value(10); |
| 91 | break; |
| 92 | case InputManager::ACCEPT: |
| 93 | case InputManager::UP: |
| 94 | case InputManager::DOWN: |
| 95 | edit = false; |
| 96 | updateButtonBox(); |
| 97 | break; |
| 98 | default: |
| 99 | return false; |
| 100 | } |
| 101 | } else { |
| 102 | switch (button) { |
| 103 | case InputManager::LEFT: |
| 104 | leftComponent(); |
| 105 | break; |
| 106 | case InputManager::RIGHT: |
| 107 | rightComponent(); |
| 108 | break; |
| 109 | case InputManager::ACCEPT: |
| 110 | edit = true; |
| 111 | updateButtonBox(); |
| 112 | break; |
| 113 | default: |
| 114 | return false; |
| 115 | } |
| 116 | } |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | void MenuSettingRGBA::update_value(int value) |
| 121 | { |
| 122 | setSelPart(constrain(getSelPart() + value, 0, 255)); |
| 123 | } |
| 124 | |
| 125 | void MenuSettingRGBA::dec() |
| 126 | { |
| 127 | update_value(-1); |
| 128 | } |
| 129 | |
| 130 | void MenuSettingRGBA::inc() |
| 131 | { |
| 132 | update_value(+1); |
| 133 | } |
| 134 | |
| 135 | void MenuSettingRGBA::leftComponent() |
| 136 | { |
| 137 | selPart = constrain(selPart-1,0,3); |
| 138 | } |
| 139 | |
| 140 | void MenuSettingRGBA::rightComponent() |
| 141 | { |
| 142 | selPart = constrain(selPart+1,0,3); |
| 143 | } |
| 144 | |
| 145 | void MenuSettingRGBA::setR(unsigned short r) |
| 146 | { |
| 147 | _value->r = r; |
| 148 | stringstream ss; |
| 149 | ss << r; |
| 150 | ss >> strR; |
| 151 | } |
| 152 | |
| 153 | void MenuSettingRGBA::setG(unsigned short g) |
| 154 | { |
| 155 | _value->g = g; |
| 156 | stringstream ss; |
| 157 | ss << g; |
| 158 | ss >> strG; |
| 159 | } |
| 160 | |
| 161 | void MenuSettingRGBA::setB(unsigned short b) |
| 162 | { |
| 163 | _value->b = b; |
| 164 | stringstream ss; |
| 165 | ss << b; |
| 166 | ss >> strB; |
| 167 | } |
| 168 | |
| 169 | void MenuSettingRGBA::setA(unsigned short a) |
| 170 | { |
| 171 | _value->a = a; |
| 172 | stringstream ss; |
| 173 | ss << a; |
| 174 | ss >> strA; |
| 175 | } |
| 176 | |
| 177 | void MenuSettingRGBA::setSelPart(unsigned short value) |
| 178 | { |
| 179 | switch (selPart) { |
| 180 | default: case 0: setR(value); break; |
| 181 | case 1: setG(value); break; |
| 182 | case 2: setB(value); break; |
| 183 | case 3: setA(value); break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | RGBAColor MenuSettingRGBA::value() |
| 188 | { |
| 189 | return *_value; |
| 190 | } |
| 191 | |
| 192 | unsigned short MenuSettingRGBA::getSelPart() |
| 193 | { |
| 194 | switch (selPart) { |
| 195 | default: case 0: return value().r; |
| 196 | case 1: return value().g; |
| 197 | case 2: return value().b; |
| 198 | case 3: return value().a; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | void MenuSettingRGBA::drawSelected(int y) |
| 203 | { |
| 204 | int x = 166+selPart*36; |
| 205 | gmenu2x->s->box( x, y, 36, 14, gmenu2x->skinConfColors[COLOR_SELECTION_BG] ); |
| 206 | |
| 207 | MenuSetting::drawSelected(y); |
| 208 | } |
| 209 | |
| 210 | bool MenuSettingRGBA::edited() |
| 211 | { |
| 212 | return originalValue.r != value().r || originalValue.g != value().g || originalValue.b != value().b || originalValue.a != value().a; |
| 213 | } |
| 214 | |
| 215 | void MenuSettingRGBA::updateButtonBox() |
| 216 | { |
| 217 | buttonBox.clear(); |
| 218 | if (edit) { |
| 219 | buttonBox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/l.png")); |
| 220 | buttonBox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x->tr["Decrease"])); |
| 221 | buttonBox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png")); |
| 222 | buttonBox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x->tr["Increase"])); |
| 223 | buttonBox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Confirm"])); |
| 224 | } else { |
| 225 | buttonBox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png")); |
| 226 | buttonBox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x->tr["Change color component"])); |
| 227 | buttonBox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Edit"])); |
| 228 | } |
| 229 | } |
| 230 |
Branches:
install_locations
master
opkrun
packages
