2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
#include "menusettingbool.h"
|
2010-07-28 03:36:46 +03:00
|
|
|
#include "gmenu2x.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>
|
|
|
|
|
2010-07-28 03:36:46 +03:00
|
|
|
using std::string;
|
|
|
|
using fastdelegate::MakeDelegate;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-07-28 03:36:46 +03:00
|
|
|
MenuSettingBool::MenuSettingBool(
|
|
|
|
GMenu2X *gmenu2x, const string &name,
|
|
|
|
const string &description, int *value)
|
2010-07-28 00:45:53 +03:00
|
|
|
: MenuSetting(gmenu2x, name, description)
|
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(
|
|
|
|
GMenu2X *gmenu2x, const string &name,
|
|
|
|
const string &description, bool *value)
|
2010-07-28 00:45:53 +03:00
|
|
|
: MenuSetting(gmenu2x, name, description)
|
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()
|
|
|
|
{
|
|
|
|
IconButton *btn = new IconButton(gmenu2x, "skin:imgs/buttons/b.png",
|
|
|
|
gmenu2x->tr["Switch"]);
|
2010-05-03 23:21:36 +03:00
|
|
|
btn->setAction(MakeDelegate(this, &MenuSettingBool::toggle));
|
|
|
|
buttonBox.add(btn);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingBool::draw(int y)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
MenuSetting::draw(y);
|
|
|
|
gmenu2x->s->write( gmenu2x->font, strvalue, 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle );
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingBool::manageInput()
|
|
|
|
{
|
|
|
|
if (gmenu2x->input[ACTION_B])
|
|
|
|
toggle();
|
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();
|
|
|
|
}
|