diff options
author | Stijn Buys <ingar@osirion.org> | 2015-01-06 18:51:37 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2015-01-06 18:51:37 +0000 |
commit | 72ee43e9470c6fdbc6ed7ff92b85dfa5062c5762 (patch) | |
tree | 6474fa59066d5212dcd40e3d76652dce35565280 /src/ui/ui.cc | |
parent | 57d958d40af061e83aa99ca12e375e5345836ecd (diff) |
Added separate event handlers for mouse button clicks and mouse wheel movement.
Diffstat (limited to 'src/ui/ui.cc')
-rw-r--r-- | src/ui/ui.cc | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/src/ui/ui.cc b/src/ui/ui.cc index e10d77a..e3aeb31 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -284,31 +284,63 @@ void UI::input_mouse(const float x, const float y) mouse_cursor.assign(x, y); } +bool UI::input_mouse_button(const bool pressed, unsigned int button) +{ + bool handled = false; + + if (button == SDL_BUTTON_LEFT) + { + mouse_buttonleft_pressed = pressed; + } + + // set mouse focus + Widget *f = find_mouse_focus(mouse_cursor); + if (f) + { + f->event_mouse(mouse_cursor); + } + ui_mouse_focus = f; + + // send mouse button events + if (ui_mouse_focus) + { + handled = ui_mouse_focus->event_mouse_button(pressed, button); + } + return handled; +} + +bool UI::input_mouse_wheel(const math::Vector2f & direction) +{ + bool handled = false; + + // set mouse focus + Widget *f = find_mouse_focus(mouse_cursor); + if (f) + { + f->event_mouse(mouse_cursor); + } + ui_mouse_focus = f; + + // send mouse wheel events + if (ui_mouse_focus) + { + handled = ui_mouse_focus->event_mouse_wheel(direction); + } + return handled; +} + bool UI::input_key(const bool pressed, const int key, const unsigned int modifier) { bool handled = false; - if (key < 512) { - // keyboard keys - Widget *f = find_input_focus(); - if (f) { - handled = f->event_key(pressed, key, modifier); - } - ui_input_focus = f; - - } else if (key < 564) { - if ( key == 512 + SDL_BUTTON_LEFT) { - mouse_buttonleft_pressed = pressed; - } - // mouse buttons - Widget *f = find_mouse_focus(mouse_cursor); - if (f) { - f->event_mouse(mouse_cursor); - } - ui_mouse_focus = f; - if (ui_mouse_focus) - handled = ui_mouse_focus->event_key(pressed, key, modifier); + // send keyboard events + Widget *f = find_input_focus(); + if (f) + { + handled = f->event_key(pressed, key, modifier); } + ui_input_focus = f; + return handled; } |