summaryrefslogtreecommitdiff
path: root/plugingui
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
parent6a5f7728f45926f0443a1577c3769020ca02f8aa (diff)
Make 'mouse button down, move mouse in/out of button' work correctly.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/button.cc39
-rw-r--r--plugingui/button.h8
2 files changed, 33 insertions, 14 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
diff --git a/plugingui/button.h b/plugingui/button.h
index 89cabf5..682dfa2 100644
--- a/plugingui/button.h
+++ b/plugingui/button.h
@@ -39,6 +39,7 @@ public:
Button(Widget *parent);
bool isFocusable() { return true; }
+ bool catchMouse() { return true; }
void setText(std::string text);
@@ -52,8 +53,11 @@ public:
virtual void mouseLeaveEvent();
virtual void mouseEnterEvent();
+ virtual void mouseMoveEvent(MouseMoveEvent *e);
private:
+ bool in_button;
+
Painter::Box box_up;
Painter::Box box_down;
@@ -63,7 +67,9 @@ private:
} state_t;
std::string text;
- state_t state;
+
+ state_t draw_state;
+ state_t button_state;
void (*handler)(void *);
void *ptr;