summaryrefslogtreecommitdiff
path: root/plugingui/checkbox.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-03-30 16:56:23 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-03-30 16:56:23 +0100
commitb4de68133243b3bf0756118b38d1459067f3be95 (patch)
treee19227fc83c26bbabe95c9682cca965a3dd3ee54 /plugingui/checkbox.cc
parent8956a23c6ca7e0174b5ece50e43bb343884cae8b (diff)
Added 'middle' state of checkbox button to illustrate inbetween-states position.
Diffstat (limited to 'plugingui/checkbox.cc')
-rw-r--r--plugingui/checkbox.cc42
1 files changed, 34 insertions, 8 deletions
diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc
index da3ce4b..d3c2512 100644
--- a/plugingui/checkbox.cc
+++ b/plugingui/checkbox.cc
@@ -31,8 +31,11 @@
#include <stdio.h>
GUI::CheckBox::CheckBox(Widget *parent)
- : GUI::Widget(parent)
+ : GUI::Widget(parent),
+ bg_on(":switch_back_on.png"), bg_off(":switch_back_off.png"),
+ knob(":switch_front.png")
{
+ middle = false;
state = false;
handler = NULL;
}
@@ -41,9 +44,13 @@ void GUI::CheckBox::buttonEvent(ButtonEvent *e)
{
if(e->direction == -1) {
state = !state;
- repaintEvent(NULL);
+ middle = false;
if(handler) handler(ptr);
+ } else {
+ middle = true;
}
+
+ repaintEvent(NULL);
}
void GUI::CheckBox::setText(std::string text)
@@ -60,10 +67,14 @@ void GUI::CheckBox::registerClickHandler(void (*handler)(void *), void *ptr)
void GUI::CheckBox::keyEvent(KeyEvent *e)
{
- if(e->direction != -1) return;
-
if(e->keycode == GUI::KeyEvent::KEY_CHARACTER && e->text == " ") {
- state = !state;
+ if(e->direction == -1) {
+ state = !state;
+ middle = false;
+ } else {
+ middle = true;
+ }
+
repaintEvent(NULL);
}
}
@@ -76,9 +87,22 @@ void GUI::CheckBox::repaintEvent(GUI::RepaintEvent *e)
p.clear();
- float alpha = 0.8;
+ if(state) {
+ p.drawImage(0, (knob.height() - bg_on.height()) / 2, &bg_on);
+ if(middle) p.drawImage((bg_on.width() - knob.width()) / 2, 0, &knob);
+ else p.drawImage(bg_on.width() - 40, 0, &knob);
+ } else {
+ p.drawImage(0, (knob.height() - bg_off.height()) / 2, &bg_off);
+ if(middle) p.drawImage((bg_on.width() - knob.width()) / 2, 0, &knob);
+ else p.drawImage(0, 0, &knob);
+ }
+
+ // int box = width()<height()?width():height();
+
+ /*
+ p.clear();
- int box = width()<height()?width():height();
+ float alpha = 0.8;
p.setColour(Colour(0.5, alpha));
p.drawFilledRectangle(0,0,box-1,box-1);
@@ -95,10 +119,12 @@ void GUI::CheckBox::repaintEvent(GUI::RepaintEvent *e)
p.setColour(Colour(0.3, alpha));
p.drawPoint(0,box-1);
p.drawPoint(box-1,0);
-
+ */
+ /*
p.setColour(Colour(1));
Font font;
p.drawText(box + 8, height() / 2 + 5, font, _text);
+ */
}
bool GUI::CheckBox::checked()