From 72ee43e9470c6fdbc6ed7ff92b85dfa5062c5762 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 6 Jan 2015 18:51:37 +0000 Subject: Added separate event handlers for mouse button clicks and mouse wheel movement. --- src/ui/widget.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'src/ui/widget.cc') diff --git a/src/ui/widget.cc b/src/ui/widget.cc index e931147..982b792 100644 --- a/src/ui/widget.cc +++ b/src/ui/widget.cc @@ -438,7 +438,8 @@ bool Widget::event_key(const bool pressed, const int key, const unsigned int mod { bool handled = false; - if (enabled()) { + if (enabled()) + { if (pressed) { handled = on_keypress(key, modifier); } else { @@ -452,19 +453,51 @@ bool Widget::event_key(const bool pressed, const int key, const unsigned int mod return handled; } -bool Widget::event_mouse(const math::Vector2f &cursor) +void Widget::event_mouse(const math::Vector2f & cursor) { if (disabled()) - return false; + return; math::Vector2f local_cursor = to_local_coords(cursor); - bool handled = false; if (root()->mouse_focus() != this) { on_mouseover(local_cursor); } on_mousemove(local_cursor); +} + +bool Widget::event_mouse_button(const bool pressed, const unsigned int button) +{ + bool handled = false; + + if (enabled()) + { + if (pressed) { + handled = on_mousepress(button); + } else { + handled = on_mouserelease(button); + } + } + + if (!handled && parent()) + handled = parent()->event_mouse_button(pressed, button); + + return handled; +} + +bool Widget::event_mouse_wheel(const math::Vector2f & direction) +{ + bool handled = false; + + if (enabled()) + { + handled = on_mousewheel(direction); + } + + if (!handled && parent()) + handled = parent()->event_mouse_wheel(direction); + return handled; } @@ -512,6 +545,21 @@ void Widget::on_mousemove(const math::Vector2f &cursor) return; } +bool Widget::on_mousepress(const unsigned int button) +{ + return false; +} + +bool Widget::on_mouserelease(const unsigned int button) +{ + return false; +} + +bool Widget::on_mousewheel(const math::Vector2f & direction) +{ + return false; +} + bool Widget::on_keypress(const int key, const unsigned int modifier) { return false; -- cgit v1.2.3