From be675587812c27fac9838af844f8ecb44703ff08 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 30 Mar 2013 22:02:20 +0100 Subject: Implemented new mouseLeave/Enter Events. Use for buttons. --- plugingui/button.cc | 16 ++++++++++++++++ plugingui/button.h | 3 +++ plugingui/eventhandler.cc | 9 +++++++++ plugingui/widget.h | 3 +++ 4 files changed, 31 insertions(+) (limited to 'plugingui') diff --git a/plugingui/button.cc b/plugingui/button.cc index 05d16a2..2370f29 100644 --- a/plugingui/button.cc +++ b/plugingui/button.cc @@ -29,6 +29,7 @@ #include "painter.h" #include +#include GUI::Button::Button(Widget *parent) : GUI::Widget(parent) @@ -110,6 +111,21 @@ void GUI::Button::setText(std::string text) repaintEvent(NULL); } +void GUI::Button::mouseLeaveEvent() +{ + DEBUG(button, "Leave\n"); + if(state == down) { + state = up; + repaintEvent(NULL); + } +} + +void GUI::Button::mouseEnterEvent() +{ + DEBUG(button, "Enter\n"); +} + + #ifdef TEST_BUTTON //Additional dependency files //deps: diff --git a/plugingui/button.h b/plugingui/button.h index f39f24f..89cabf5 100644 --- a/plugingui/button.h +++ b/plugingui/button.h @@ -50,6 +50,9 @@ public: virtual void repaintEvent(RepaintEvent *e); virtual void buttonEvent(ButtonEvent *e); + virtual void mouseLeaveEvent(); + virtual void mouseEnterEvent(); + private: Painter::Box box_up; Painter::Box box_down; diff --git a/plugingui/eventhandler.cc b/plugingui/eventhandler.cc index 1cf67fc..050c2e1 100644 --- a/plugingui/eventhandler.cc +++ b/plugingui/eventhandler.cc @@ -447,6 +447,15 @@ void GUI::EventHandler::processEvents(Window *window) MouseMoveEvent *me = (MouseMoveEvent*)event; Widget *w = window->find(me->x, me->y); + Widget *oldw = window->mouseFocus(); + if(w != oldw) { + // Send focus leave to oldw + if(oldw) oldw->mouseLeaveEvent(); + // Send focus enter to w + if(w) w->mouseEnterEvent(); + + window->setMouseFocus(w); + } if(window->buttonDownFocus()) { Widget *w = window->buttonDownFocus(); diff --git a/plugingui/widget.h b/plugingui/widget.h index 34cdaee..47c374e 100644 --- a/plugingui/widget.h +++ b/plugingui/widget.h @@ -66,6 +66,9 @@ public: virtual void scrollEvent(ScrollEvent *e) {} virtual void keyEvent(KeyEvent *e) {} + virtual void mouseLeaveEvent() {} + virtual void mouseEnterEvent() {} + Widget *find(size_t x, size_t y); virtual Window *window(); -- cgit v1.2.3