summaryrefslogtreecommitdiff
path: root/plugingui/button.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-04-18 22:22:52 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2013-04-18 22:22:52 +0200
commit615c1f1544cabbe7ed4b33a1bde10b1b2ab71d2e (patch)
tree659d8efb4711deaa3f7d1c32f55280d4ceb17482 /plugingui/button.cc
parent6a5f7728f45926f0443a1577c3769020ca02f8aa (diff)
Make 'mouse button down, move mouse in/out of button' work correctly.
Diffstat (limited to 'plugingui/button.cc')
-rw-r--r--plugingui/button.cc39
1 files changed, 26 insertions, 13 deletions
diff --git a/plugingui/button.cc b/plugingui/button.cc
index d03bc01..c316ef3 100644
--- a/plugingui/button.cc
+++ b/plugingui/button.cc
@@ -54,7 +54,9 @@ GUI::Button::Button(Widget *parent)
box_down.bottomRight = new Image(":pushbuttondown_br.png");
box_down.center = new Image(":pushbuttondown_c.png");
- state = up;
+ draw_state = up;
+ button_state = up;
+
handler = NULL;
ptr = NULL;
}
@@ -68,14 +70,19 @@ void GUI::Button::registerClickHandler(void (*handler)(void *), void *ptr)
void GUI::Button::buttonEvent(ButtonEvent *e)
{
if(e->direction == 1) {
- state = down;
+ draw_state = down;
+ button_state = down;
+ in_button = true;
repaintEvent(NULL);
}
if(e->direction == -1) {
- state = up;
+ draw_state = up;
+ button_state = up;
repaintEvent(NULL);
- clicked();
- if(handler) handler(ptr);
+ if(in_button) {
+ clicked();
+ if(handler) handler(ptr);
+ }
}
}
@@ -89,8 +96,7 @@ void GUI::Button::repaintEvent(GUI::RepaintEvent *e)
int h = height();
if(w == 0 || h == 0) return;
-
- switch(state) {
+ switch(draw_state) {
case up:
p.drawBox(0, 0, &box_up, w, h);
break;
@@ -101,8 +107,8 @@ void GUI::Button::repaintEvent(GUI::RepaintEvent *e)
Font font(":fontemboss.png");
p.setColour(Colour(0.1));
- p.drawText(width()/2-(text.length()*3)+(state==up?0:1),
- height()/2+5+(state==up?0:1), font, text, true);
+ p.drawText(width()/2-(text.length()*3)+(draw_state==up?0:1),
+ height()/2+5+1+(draw_state==up?0:1), font, text, true);
}
void GUI::Button::setText(std::string text)
@@ -113,18 +119,25 @@ void GUI::Button::setText(std::string text)
void GUI::Button::mouseLeaveEvent()
{
- DEBUG(button, "Leave\n");
- if(state == down) {
- state = up;
+ in_button = false;
+ if(button_state == down) {
+ draw_state = up;
repaintEvent(NULL);
}
}
void GUI::Button::mouseEnterEvent()
{
- DEBUG(button, "Enter\n");
+ in_button = true;
+ if(button_state == down) {
+ draw_state = down;
+ repaintEvent(NULL);
+ }
}
+void GUI::Button::mouseMoveEvent(MouseMoveEvent *e)
+{
+}
#ifdef TEST_BUTTON
//Additional dependency files