From 0098be04d737fe00d867aa5c73e6d58f19a55b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 5 Aug 2014 21:13:50 -0700 Subject: [PATCH] Added mouse wheel handling. --- examples/common/entry/entry.cpp | 3 ++- examples/common/entry/entry.h | 6 ++++-- examples/common/entry/entry_linux.cpp | 2 ++ examples/common/entry/entry_p.h | 7 +++++-- examples/common/entry/entry_sdl.cpp | 4 ++-- examples/common/entry/entry_windows.cpp | 17 +++++++++++++---- examples/common/entry/input.cpp | 21 +++++++++++++++------ examples/common/entry/input.h | 4 ++-- 8 files changed, 45 insertions(+), 19 deletions(-) diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index a24fb35d..fb340142 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -283,7 +283,7 @@ namespace entry if (mouse->m_move) { - inputSetMousePos(mouse->m_mx, mouse->m_my); + inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz); } else { @@ -297,6 +297,7 @@ namespace entry { _mouse->m_mx = mouse->m_mx; _mouse->m_my = mouse->m_my; + _mouse->m_mz = mouse->m_mz; } else { diff --git a/examples/common/entry/entry.h b/examples/common/entry/entry.h index 18f48862..9247a9b7 100644 --- a/examples/common/entry/entry.h +++ b/examples/common/entry/entry.h @@ -134,6 +134,7 @@ namespace entry MouseState() : m_mx(0) , m_my(0) + , m_mz(0) { for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii) { @@ -141,8 +142,9 @@ namespace entry } } - uint32_t m_mx; - uint32_t m_my; + int32_t m_mx; + int32_t m_my; + int32_t m_mz; uint8_t m_buttons[entry::MouseButton::Count]; }; diff --git a/examples/common/entry/entry_linux.cpp b/examples/common/entry/entry_linux.cpp index 27e80453..c17cb45f 100644 --- a/examples/common/entry/entry_linux.cpp +++ b/examples/common/entry/entry_linux.cpp @@ -216,6 +216,7 @@ namespace entry { m_eventQueue.postMouseEvent(xbutton.x , xbutton.y + , 0 , mb , event.type == ButtonPress ); @@ -228,6 +229,7 @@ namespace entry const XMotionEvent& xmotion = event.xmotion; m_eventQueue.postMouseEvent(xmotion.x , xmotion.y + , 0 ); } break; diff --git a/examples/common/entry/entry_p.h b/examples/common/entry/entry_p.h index 4125b09a..0276dcff 100644 --- a/examples/common/entry/entry_p.h +++ b/examples/common/entry/entry_p.h @@ -56,6 +56,7 @@ namespace entry { int32_t m_mx; int32_t m_my; + int32_t m_mz; MouseButton::Enum m_button; bool m_down; bool m_move; @@ -90,24 +91,26 @@ namespace entry m_queue.push(ev); } - void postMouseEvent(int32_t _mx, int32_t _my) + void postMouseEvent(int32_t _mx, int32_t _my, int32_t _mz) { MouseEvent* ev = new MouseEvent; ev->m_type = Event::Mouse; ev->m_mx = _mx; ev->m_my = _my; + ev->m_mz = _mz; ev->m_button = MouseButton::None; ev->m_down = false; ev->m_move = true; m_queue.push(ev); } - void postMouseEvent(int32_t _mx, int32_t _my, MouseButton::Enum _button, bool _down) + void postMouseEvent(int32_t _mx, int32_t _my, int32_t _mz, MouseButton::Enum _button, bool _down) { MouseEvent* ev = new MouseEvent; ev->m_type = Event::Mouse; ev->m_mx = _mx; ev->m_my = _my; + ev->m_mz = _mz; ev->m_button = _button; ev->m_down = _down; ev->m_move = false; diff --git a/examples/common/entry/entry_sdl.cpp b/examples/common/entry/entry_sdl.cpp index d7bcc0df..e9ad6fee 100644 --- a/examples/common/entry/entry_sdl.cpp +++ b/examples/common/entry/entry_sdl.cpp @@ -186,7 +186,7 @@ namespace entry case SDL_MOUSEMOTION: { const SDL_MouseMotionEvent& mev = event.motion; - m_eventQueue.postMouseEvent(mev.x, mev.y); + m_eventQueue.postMouseEvent(mev.x, mev.y, 0); } break; @@ -194,7 +194,7 @@ namespace entry case SDL_MOUSEBUTTONUP: { const SDL_MouseButtonEvent& mev = event.button; - m_eventQueue.postMouseEvent(mev.x, mev.y, MouseButton::Left, mev.type == SDL_MOUSEBUTTONDOWN); + m_eventQueue.postMouseEvent(mev.x, mev.y, 0, MouseButton::Left, mev.type == SDL_MOUSEBUTTONDOWN); } break; diff --git a/examples/common/entry/entry_windows.cpp b/examples/common/entry/entry_windows.cpp index 22a239a1..0d5662b5 100644 --- a/examples/common/entry/entry_windows.cpp +++ b/examples/common/entry/entry_windows.cpp @@ -374,7 +374,16 @@ namespace entry setMousePos(m_mx, m_my); } - m_eventQueue.postMouseEvent(mx, my); + m_eventQueue.postMouseEvent(mx, my, 0); + } + break; + + case WM_MOUSEWHEEL: + { + int32_t mx = GET_X_LPARAM(_lparam); + int32_t my = GET_Y_LPARAM(_lparam); + int32_t mz = GET_WHEEL_DELTA_WPARAM(_wparam); + m_eventQueue.postMouseEvent(mx, my, mz); } break; @@ -384,7 +393,7 @@ namespace entry { int32_t mx = GET_X_LPARAM(_lparam); int32_t my = GET_Y_LPARAM(_lparam); - m_eventQueue.postMouseEvent(mx, my, MouseButton::Left, _id == WM_LBUTTONDOWN); + m_eventQueue.postMouseEvent(mx, my, 0, MouseButton::Left, _id == WM_LBUTTONDOWN); } break; @@ -394,7 +403,7 @@ namespace entry { int32_t mx = GET_X_LPARAM(_lparam); int32_t my = GET_Y_LPARAM(_lparam); - m_eventQueue.postMouseEvent(mx, my, MouseButton::Middle, _id == WM_MBUTTONDOWN); + m_eventQueue.postMouseEvent(mx, my, 0, MouseButton::Middle, _id == WM_MBUTTONDOWN); } break; @@ -404,7 +413,7 @@ namespace entry { int32_t mx = GET_X_LPARAM(_lparam); int32_t my = GET_Y_LPARAM(_lparam); - m_eventQueue.postMouseEvent(mx, my, MouseButton::Right, _id == WM_RBUTTONDOWN); + m_eventQueue.postMouseEvent(mx, my, 0, MouseButton::Right, _id == WM_RBUTTONDOWN); } break; diff --git a/examples/common/entry/input.cpp b/examples/common/entry/input.cpp index e5b49ad7..8b3e909a 100644 --- a/examples/common/entry/input.cpp +++ b/examples/common/entry/input.cpp @@ -15,6 +15,7 @@ struct Mouse Mouse() : m_width(1280) , m_height(720) + , m_wheelDelta(120) , m_lock(false) { } @@ -25,6 +26,7 @@ struct Mouse { m_norm[0] = 0.0f; m_norm[1] = 0.0f; + m_norm[2] = 0.0f; } memset(m_buttons, 0, sizeof(m_buttons) ); @@ -36,12 +38,14 @@ struct Mouse m_height = _height; } - void setPos(int32_t _mx, int32_t _my) + void setPos(int32_t _mx, int32_t _my, int32_t _mz) { m_absolute[0] = _mx; m_absolute[1] = _my; + m_absolute[2] = _mz; m_norm[0] = float(_mx)/float(m_width); m_norm[1] = float(_my)/float(m_height); + m_norm[2] = float(_mz)/float(m_wheelDelta); } void setButtonState(entry::MouseButton::Enum _button, uint8_t _state) @@ -49,12 +53,13 @@ struct Mouse m_buttons[_button] = _state; } - int32_t m_absolute[2]; - float m_norm[2]; + int32_t m_absolute[3]; + float m_norm[3]; int32_t m_wheel; uint8_t m_buttons[entry::MouseButton::Count]; uint16_t m_width; uint16_t m_height; + uint16_t m_wheelDelta; bool m_lock; }; @@ -197,9 +202,10 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down) s_input.m_keyboard.setKeyState(_key, _modifiers, _down); } -void inputSetMousePos(int32_t _mx, int32_t _my) +void inputSetMousePos(int32_t _mx, int32_t _my, int32_t _mz) { - s_input.m_mouse.setPos(_mx, _my); + DBG("%d, %d, %d", _mx, _my, _mz); + s_input.m_mouse.setPos(_mx, _my, _mz); } void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state) @@ -207,12 +213,14 @@ void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state) s_input.m_mouse.setButtonState(_button, _state); } -void inputGetMouse(float _mouse[2]) +void inputGetMouse(float _mouse[3]) { _mouse[0] = s_input.m_mouse.m_norm[0]; _mouse[1] = s_input.m_mouse.m_norm[1]; + _mouse[2] = s_input.m_mouse.m_norm[2]; s_input.m_mouse.m_norm[0] = 0.0f; s_input.m_mouse.m_norm[1] = 0.0f; + s_input.m_mouse.m_norm[2] = 0.0f; } bool inputIsMouseLocked() @@ -230,6 +238,7 @@ void inputSetMouseLock(bool _lock) { s_input.m_mouse.m_norm[0] = 0.0f; s_input.m_mouse.m_norm[1] = 0.0f; + s_input.m_mouse.m_norm[2] = 0.0f; } } } diff --git a/examples/common/entry/input.h b/examples/common/entry/input.h index 8034c955..b16dcfd1 100644 --- a/examples/common/entry/input.h +++ b/examples/common/entry/input.h @@ -38,7 +38,7 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down); void inputSetMouseResolution(uint16_t _width, uint16_t _height); /// -void inputSetMousePos(int32_t _mx, int32_t _my); +void inputSetMousePos(int32_t _mx, int32_t _my, int32_t _mz); /// void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state); @@ -47,7 +47,7 @@ void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state); void inputSetMouseLock(bool _lock); /// -void inputGetMouse(float _mouse[2]); +void inputGetMouse(float _mouse[3]); /// bool inputIsMouseLocked();