2017-10-29 10:28:14 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2016 Maschell
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
2018-06-21 20:44:58 +02:00
|
|
|
#include <gui/GuiToggle.h>
|
2020-08-13 12:38:07 +02:00
|
|
|
|
2017-10-29 10:28:14 +01:00
|
|
|
/**
|
|
|
|
* Constructor for the GuiToggle class.
|
|
|
|
*/
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
GuiToggle::GuiToggle(bool checked, float width, float height)
|
|
|
|
: GuiButton(width, height) {
|
2017-10-29 10:28:14 +01:00
|
|
|
bChanged = false;
|
|
|
|
selected = checked;
|
2020-08-13 12:38:07 +02:00
|
|
|
clicked.connect(this, &GuiToggle::OnToggleClick);
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor for the GuiButton class.
|
|
|
|
*/
|
2018-06-21 20:44:58 +02:00
|
|
|
GuiToggle::~GuiToggle() {
|
2017-10-29 10:28:14 +01:00
|
|
|
bChanged = false;
|
|
|
|
selected = false;
|
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiToggle::OnToggleClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
2020-08-13 12:38:07 +02:00
|
|
|
if (!isStateSet(STATE_DISABLED | STATE_HIDDEN | STATE_DISABLE_INPUT)) {
|
|
|
|
if (selected) {
|
2017-10-29 10:28:14 +01:00
|
|
|
setUnchecked();
|
2018-06-21 20:44:58 +02:00
|
|
|
} else {
|
2017-10-29 10:28:14 +01:00
|
|
|
setChecked();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
void GuiToggle::update(GuiController *c) {
|
2017-10-29 10:28:14 +01:00
|
|
|
GuiButton::update(c);
|
|
|
|
}
|
|
|
|
|