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 "menusettingbool.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"
|
2010-02-04 13:33:47 +02:00
|
|
|
#include "utilities.h"
|
2010-07-28 03:36:46 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2014-08-16 08:07:41 +03:00
|
|
|
using std::bind;
|
2010-07-28 03:36:46 +03:00
|
|
|
using std::string;
|
2014-08-16 00:52:48 +03:00
|
|
|
using std::unique_ptr;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-07-28 03:36:46 +03:00
|
|
|
MenuSettingBool::MenuSettingBool(
|
2011-12-23 15:03:05 +02:00
|
|
|
GMenu2X *gmenu2x, Touchscreen &ts,
|
|
|
|
const string &name, const string &description, int *value)
|
2010-07-28 00:45:53 +03:00
|
|
|
: MenuSetting(gmenu2x, name, description)
|
2011-12-23 15:03:05 +02:00
|
|
|
, ts(ts)
|
2010-05-03 23:21:36 +03:00
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
_ivalue = value;
|
|
|
|
_value = NULL;
|
|
|
|
originalValue = *value != 0;
|
|
|
|
setValue(this->value());
|
2010-07-28 00:45:53 +03:00
|
|
|
initButton();
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-07-28 03:36:46 +03:00
|
|
|
MenuSettingBool::MenuSettingBool(
|
2011-12-23 15:03:05 +02:00
|
|
|
GMenu2X *gmenu2x, Touchscreen &ts,
|
|
|
|
const string &name, const string &description, bool *value)
|
2010-07-28 00:45:53 +03:00
|
|
|
: MenuSetting(gmenu2x, name, description)
|
2011-12-23 15:03:05 +02:00
|
|
|
, ts(ts)
|
2010-05-03 23:21:36 +03:00
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
_value = value;
|
|
|
|
_ivalue = NULL;
|
|
|
|
originalValue = *value;
|
|
|
|
setValue(this->value());
|
2010-07-28 00:45:53 +03:00
|
|
|
initButton();
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-07-28 00:45:53 +03:00
|
|
|
void MenuSettingBool::initButton()
|
|
|
|
{
|
2014-08-16 07:35:27 +03:00
|
|
|
buttonBox.add(unique_ptr<IconButton>(new IconButton(
|
|
|
|
gmenu2x, ts, "skin:imgs/buttons/accept.png",
|
|
|
|
gmenu2x->tr["Switch"],
|
2014-08-16 08:07:41 +03:00
|
|
|
bind(&MenuSettingBool::toggle, this))));
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 09:08:54 +03:00
|
|
|
void MenuSettingBool::draw(int valueX, int y, int h)
|
2010-05-03 23:21:36 +03:00
|
|
|
{
|
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
|
|
|
gmenu2x->font->write(s, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2011-10-23 10:38:59 +03:00
|
|
|
bool MenuSettingBool::handleButtonPress(InputManager::Button button)
|
2010-05-03 23:21:36 +03:00
|
|
|
{
|
2011-10-23 10:47:51 +03:00
|
|
|
switch (button) {
|
|
|
|
case InputManager::ACCEPT:
|
|
|
|
case InputManager::LEFT:
|
|
|
|
case InputManager::RIGHT:
|
|
|
|
toggle();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
2011-09-15 21:20:35 +03:00
|
|
|
}
|
2011-10-23 10:47:51 +03:00
|
|
|
return true;
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingBool::toggle()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
setValue(!value());
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingBool::setValue(int value)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
setValue(value != 0);
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingBool::setValue(bool value)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
if (_value == NULL)
|
|
|
|
*_ivalue = value;
|
|
|
|
else
|
|
|
|
*_value = value;
|
|
|
|
strvalue = value ? "ON" : "OFF";
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
bool MenuSettingBool::value()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
if (_value == NULL)
|
|
|
|
return *_ivalue != 0;
|
|
|
|
else
|
|
|
|
return *_value;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
bool MenuSettingBool::edited()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
return originalValue != value();
|
|
|
|
}
|