From b4de68133243b3bf0756118b38d1459067f3be95 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 30 Mar 2013 16:56:23 +0100 Subject: Added 'middle' state of checkbox button to illustrate inbetween-states position. --- plugingui/checkbox.cc | 42 ++++++++++++++++++++++++++++++++++-------- plugingui/checkbox.h | 6 ++++++ 2 files changed, 40 insertions(+), 8 deletions(-) (limited to 'plugingui') 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 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()