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/modelview.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/ui/modelview.cc') diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc index 679c7b6..f1676b1 100755 --- a/src/ui/modelview.cc +++ b/src/ui/modelview.cc @@ -100,19 +100,29 @@ void ModelView::set_zoom(const float zoom) math::clamp(modelview_zoom, 1.0f, 5.0f); } -bool ModelView::on_keypress(const int key, const unsigned int modifier) +bool ModelView::on_mousewheel(const math::Vector2f & direction) { - if (key == 512 + SDL_BUTTON_WHEELUP) { + if (direction.y() > 0 ) + { modelview_zoom -= 0.25f; if (modelview_zoom < 1.0f) modelview_zoom = 1.0f; return true; - } else if (key == 512 + SDL_BUTTON_WHEELDOWN) { + } else if (direction.y() < 0 ) + { modelview_zoom += 0.25f; if (modelview_zoom > 5.0f) modelview_zoom = 5.0f; return true; - } else if (key == 512 + SDL_BUTTON_LEFT) { + } + + return false; +} + +bool ModelView::on_mousepress(const unsigned int button) +{ + if (button == SDL_BUTTON_LEFT) + { modelview_dragging = true; return true; } @@ -120,9 +130,10 @@ bool ModelView::on_keypress(const int key, const unsigned int modifier) return false; } -bool ModelView::on_keyrelease(const int key, const unsigned int modifier) +bool ModelView::on_mouserelease(const unsigned int button) { - if (key == 512 + SDL_BUTTON_LEFT) { + if (button == SDL_BUTTON_LEFT) + { modelview_dragging = false; return true; } @@ -132,7 +143,8 @@ bool ModelView::on_keyrelease(const int key, const unsigned int modifier) void ModelView::on_mousemove(const math::Vector2f &cursor) { - if ((width() <= 0) || (height() <= 0)) { + if ((width() <= 0) || (height() <= 0)) + { return; } -- cgit v1.2.3