2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
2011-10-23 18:27:29 +03:00
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
2010-02-04 13:33:47 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
2011-10-23 18:27:29 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
#include "menusettingrgba.h"
|
2011-10-23 18:27:29 +03:00
|
|
|
|
2010-07-28 03:36:46 +03:00
|
|
|
#include "gmenu2x.h"
|
2011-10-23 18:27:29 +03:00
|
|
|
#include "iconbutton.h"
|
2013-08-03 23:30:12 +03:00
|
|
|
#include "surface.h"
|
2011-10-23 18:27:29 +03:00
|
|
|
#include "utilities.h"
|
2010-07-28 03:36:46 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2010-07-28 03:36:46 +03:00
|
|
|
using std::string;
|
|
|
|
using std::stringstream;
|
2014-08-16 00:52:48 +03:00
|
|
|
using std::unique_ptr;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-07-24 09:45:23 +03:00
|
|
|
constexpr unsigned int COMPONENT_WIDTH = 28;
|
2014-07-24 09:08:54 +03:00
|
|
|
|
2010-07-28 03:36:46 +03:00
|
|
|
MenuSettingRGBA::MenuSettingRGBA(
|
2011-12-23 15:03:05 +02:00
|
|
|
GMenu2X *gmenu2x, Touchscreen &ts_,
|
|
|
|
const string &name, const string &description, RGBAColor *value)
|
|
|
|
: MenuSetting(gmenu2x, name, description)
|
|
|
|
, ts(ts_)
|
2010-07-28 03:36:46 +03:00
|
|
|
{
|
2011-09-18 02:33:11 +03:00
|
|
|
edit = false;
|
2010-05-03 23:21:36 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
selPart = 0;
|
|
|
|
_value = value;
|
|
|
|
originalValue = *value;
|
|
|
|
this->setR(this->value().r);
|
|
|
|
this->setG(this->value().g);
|
|
|
|
this->setB(this->value().b);
|
|
|
|
this->setA(this->value().a);
|
|
|
|
|
2011-09-18 02:33:11 +03:00
|
|
|
updateButtonBox();
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 09:08:54 +03:00
|
|
|
void MenuSettingRGBA::draw(int valueX, int y, int h) {
|
2014-08-10 05:26:59 +03:00
|
|
|
Surface& s = *gmenu2x->s;
|
|
|
|
|
2014-07-24 09:08:54 +03:00
|
|
|
MenuSetting::draw(valueX, y, h);
|
2014-08-10 05:26:59 +03:00
|
|
|
s.rectangle(valueX, y + 1, h - 2, h - 2, 0,0,0,255);
|
|
|
|
s.rectangle(valueX + 1, y + 2, h - 4, h - 4, 255,255,255,255);
|
|
|
|
s.box(valueX + 2, y + 3, h - 6, h - 6, value());
|
2014-07-24 09:45:23 +03:00
|
|
|
gmenu2x->font->write(s, strR, valueX + h + COMPONENT_WIDTH - 2, y, Font::HAlignRight, Font::VAlignTop);
|
|
|
|
gmenu2x->font->write(s, strG, valueX + h + COMPONENT_WIDTH * 2 - 2, y, Font::HAlignRight, Font::VAlignTop);
|
|
|
|
gmenu2x->font->write(s, strB, valueX + h + COMPONENT_WIDTH * 3 - 2, y, Font::HAlignRight, Font::VAlignTop);
|
|
|
|
gmenu2x->font->write(s, strA, valueX + h + COMPONENT_WIDTH * 4 - 2, y, Font::HAlignRight, Font::VAlignTop);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 09:08:54 +03:00
|
|
|
void MenuSettingRGBA::handleTS(int valueX, int y, int h) {
|
2011-12-23 15:03:05 +02:00
|
|
|
if (ts.pressed()) {
|
2010-05-03 23:21:36 +03:00
|
|
|
for (int i=0; i<4; i++) {
|
2014-07-24 09:08:54 +03:00
|
|
|
if (i!=selPart && ts.inRect(valueX + h + i * COMPONENT_WIDTH,y,COMPONENT_WIDTH,h)) {
|
2010-02-04 13:33:47 +02:00
|
|
|
selPart = i;
|
2014-07-24 09:08:54 +03:00
|
|
|
break;
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
2010-05-03 23:21:36 +03:00
|
|
|
}
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-07-24 09:08:54 +03:00
|
|
|
MenuSetting::handleTS(valueX, y, h);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2011-10-23 10:38:59 +03:00
|
|
|
bool MenuSettingRGBA::handleButtonPress(InputManager::Button button)
|
|
|
|
{
|
2011-09-18 02:33:11 +03:00
|
|
|
if (edit) {
|
2011-10-23 10:38:59 +03:00
|
|
|
switch (button) {
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::LEFT:
|
|
|
|
dec();
|
|
|
|
break;
|
|
|
|
case InputManager::RIGHT:
|
|
|
|
inc();
|
|
|
|
break;
|
|
|
|
case InputManager::ALTLEFT:
|
|
|
|
update_value(-10);
|
|
|
|
break;
|
|
|
|
case InputManager::ALTRIGHT:
|
|
|
|
update_value(10);
|
|
|
|
break;
|
|
|
|
case InputManager::ACCEPT:
|
|
|
|
case InputManager::UP:
|
|
|
|
case InputManager::DOWN:
|
|
|
|
edit = false;
|
|
|
|
updateButtonBox();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-18 02:33:11 +03:00
|
|
|
} else {
|
2011-10-23 10:38:59 +03:00
|
|
|
switch (button) {
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::LEFT:
|
2011-09-18 02:33:11 +03:00
|
|
|
leftComponent();
|
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::RIGHT:
|
2011-09-18 02:33:11 +03:00
|
|
|
rightComponent();
|
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::ACCEPT:
|
2011-09-18 02:33:11 +03:00
|
|
|
edit = true;
|
|
|
|
updateButtonBox();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-09-15 21:20:35 +03:00
|
|
|
return true;
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2011-04-14 20:35:50 +03:00
|
|
|
void MenuSettingRGBA::update_value(int value)
|
|
|
|
{
|
|
|
|
setSelPart(constrain(getSelPart() + value, 0, 255));
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::dec()
|
|
|
|
{
|
2011-04-14 20:35:50 +03:00
|
|
|
update_value(-1);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::inc()
|
|
|
|
{
|
2011-04-14 20:35:50 +03:00
|
|
|
update_value(+1);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::leftComponent()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
selPart = constrain(selPart-1,0,3);
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::rightComponent()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
selPart = constrain(selPart+1,0,3);
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::setR(unsigned short r)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
_value->r = r;
|
|
|
|
stringstream ss;
|
|
|
|
ss << r;
|
|
|
|
ss >> strR;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::setG(unsigned short g)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
_value->g = g;
|
|
|
|
stringstream ss;
|
|
|
|
ss << g;
|
|
|
|
ss >> strG;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::setB(unsigned short b)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
_value->b = b;
|
|
|
|
stringstream ss;
|
|
|
|
ss << b;
|
|
|
|
ss >> strB;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::setA(unsigned short a)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
_value->a = a;
|
|
|
|
stringstream ss;
|
|
|
|
ss << a;
|
|
|
|
ss >> strA;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingRGBA::setSelPart(unsigned short value)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
switch (selPart) {
|
|
|
|
default: case 0: setR(value); break;
|
|
|
|
case 1: setG(value); break;
|
|
|
|
case 2: setB(value); break;
|
|
|
|
case 3: setA(value); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
RGBAColor MenuSettingRGBA::value()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
return *_value;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
unsigned short MenuSettingRGBA::getSelPart()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
switch (selPart) {
|
|
|
|
default: case 0: return value().r;
|
|
|
|
case 1: return value().g;
|
|
|
|
case 2: return value().b;
|
|
|
|
case 3: return value().a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 09:08:54 +03:00
|
|
|
void MenuSettingRGBA::drawSelected(int valueX, int y, int h)
|
2010-05-03 23:21:36 +03:00
|
|
|
{
|
2014-07-24 09:08:54 +03:00
|
|
|
int x = valueX + selPart * COMPONENT_WIDTH;
|
2014-07-24 09:45:23 +03:00
|
|
|
RGBAColor color;
|
|
|
|
switch (selPart) {
|
|
|
|
default: /* fallthrough */
|
|
|
|
case 0: color = RGBAColor(255, 0, 0, 255); break;
|
|
|
|
case 1: color = RGBAColor( 0, 255, 0, 255); break;
|
|
|
|
case 2: color = RGBAColor( 0, 0, 255, 255); break;
|
|
|
|
case 3: color = RGBAColor(128, 128, 128, 255); break;
|
|
|
|
}
|
|
|
|
gmenu2x->s->box( x + h, y, COMPONENT_WIDTH, h, color );
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-07-24 09:08:54 +03:00
|
|
|
MenuSetting::drawSelected(valueX, y, h);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
bool MenuSettingRGBA::edited()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
return originalValue.r != value().r || originalValue.g != value().g || originalValue.b != value().b || originalValue.a != value().a;
|
|
|
|
}
|
2011-09-18 02:33:11 +03:00
|
|
|
|
|
|
|
void MenuSettingRGBA::updateButtonBox()
|
|
|
|
{
|
|
|
|
buttonBox.clear();
|
|
|
|
if (edit) {
|
2014-08-16 00:52:48 +03:00
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/l.png")));
|
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x->tr["Decrease"])));
|
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png")));
|
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x->tr["Increase"])));
|
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Confirm"])));
|
2011-09-18 02:33:11 +03:00
|
|
|
} else {
|
2014-08-16 00:52:48 +03:00
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png")));
|
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x->tr["Change color component"])));
|
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Edit"])));
|
2011-09-18 02:33:11 +03:00
|
|
|
}
|
|
|
|
}
|