libgui/source/gui/GuiSwitch.cpp

78 lines
2.0 KiB
C++
Raw Normal View History

2017-10-29 10:28:14 +01:00
/****************************************************************************
* Copyright (C) 2016,2017 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/GuiSwitch.h>
#include <gui/GuiImage.h>
#include <gui/GuiImageData.h>
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
/**
* Constructor for the GuiSwitch class.
*/
2020-08-13 12:38:07 +02:00
GuiSwitch::GuiSwitch(GuiImage *background, bool checked, float w, float h)
: GuiToggle(checked, w, h) {
2017-10-31 17:18:42 +01:00
setImageBackground(background);
2017-10-29 10:28:14 +01:00
}
2020-08-13 12:38:07 +02:00
2017-10-29 10:28:14 +01:00
/**
* Destructor for the GuiSwitch class.
*/
2018-06-21 20:44:58 +02:00
GuiSwitch::~GuiSwitch() {
2017-10-29 10:28:14 +01:00
}
2020-08-13 12:38:07 +02:00
void GuiSwitch::setImageBackground(GuiImage *img) {
2018-06-21 20:44:58 +02:00
backgroundImg = img;
2020-08-13 12:38:07 +02:00
if (img) {
2018-06-21 20:44:58 +02:00
img->setParent(this);
}
setImage(img);
2017-10-29 10:28:14 +01:00
}
2020-08-13 12:38:07 +02:00
void GuiSwitch::setImageOn(GuiImage *img) {
2018-06-21 20:44:58 +02:00
onImg = img;
2020-08-13 12:38:07 +02:00
if (img) {
2017-10-29 10:28:14 +01:00
img->setParent(this);
img->setAlignment(ALIGN_RIGHT);
2018-06-21 20:44:58 +02:00
}
2017-10-29 10:28:14 +01:00
}
2020-08-13 12:38:07 +02:00
void GuiSwitch::setImageOff(GuiImage *img) {
2018-06-21 20:44:58 +02:00
offImg = img;
2020-08-13 12:38:07 +02:00
if (img) {
2017-10-29 10:28:14 +01:00
img->setParent(this);
img->setAlignment(ALIGN_LEFT);
2018-06-21 20:44:58 +02:00
}
2017-10-29 10:28:14 +01:00
}
2020-08-13 12:38:07 +02:00
void GuiSwitch::setImageHighlighted(GuiImage *img) {
2017-10-29 10:28:14 +01:00
highlightedImg = img;
2018-06-21 20:44:58 +02:00
setIconOver(img);
2017-10-29 10:28:14 +01:00
}
2018-06-21 20:44:58 +02:00
void GuiSwitch::draw(CVideo *v) {
2017-10-29 10:28:14 +01:00
GuiToggle::draw(v);
2020-08-13 12:38:07 +02:00
if (getValue()) {
if (onImg != NULL) {
2018-06-21 20:44:58 +02:00
onImg->draw(v);
}
} else {
2020-08-13 12:38:07 +02:00
if (offImg != NULL) {
2018-06-21 20:44:58 +02:00
offImg->draw(v);
}
2017-10-29 10:28:14 +01:00
}
}