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