Combined separate horizontal/vertical mouse wheel event types

Instead of separate Event::MouseWheel{Vertical,Horizontal}Moved events, a single Event::MouseWheelScrolled event is used for all wheel-related events.
The new Mouse::Wheel enum is used to differentiate between mouse wheels.
This commit is contained in:
Jan Haller 2015-03-31 22:19:43 +02:00 committed by Lukas Dürrenberger
parent 534a23e074
commit 22c9674389
5 changed files with 88 additions and 85 deletions

View File

@ -103,7 +103,7 @@ public:
/// \brief Mouse wheel events parameters (MouseWheelMoved) /// \brief Mouse wheel events parameters (MouseWheelMoved)
/// ///
/// \deprecated This event is deprecated and potentially inaccurate. /// \deprecated This event is deprecated and potentially inaccurate.
/// Use MouseWheelVerticalEvent instead. /// Use MouseWheelScrollEvent instead.
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct MouseWheelEvent struct MouseWheelEvent
@ -114,25 +114,15 @@ public:
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Mouse wheel horizontal events parameters (MouseWheelHorizontalMoved) /// \brief Mouse wheel events parameters (MouseWheelScrolled)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct MouseWheelHorizontalEvent struct MouseWheelScrollEvent
{ {
float delta; ///< Number of ticks the wheel has moved (positive is left, negative is right) Mouse::Wheel wheel; ///< Which wheel (for mice with multiple ones)
int x; ///< X position of the mouse pointer, relative to the left of the owner window float delta; ///< Wheel offset (positive is up/left, negative is down/right). High-precision mice may use non-integral offsets.
int y; ///< Y position of the mouse pointer, relative to the top of the owner window int x; ///< X position of the mouse pointer, relative to the left of the owner window
}; int y; ///< Y position of the mouse pointer, relative to the top of the owner window
////////////////////////////////////////////////////////////
/// \brief Mouse wheel vertical events parameters (MouseWheelVerticalMoved)
///
////////////////////////////////////////////////////////////
struct MouseWheelVerticalEvent
{
float delta; ///< Number of ticks the wheel has moved (positive is up, negative is down)
int x; ///< X position of the mouse pointer, relative to the left of the owner window
int y; ///< Y position of the mouse pointer, relative to the top of the owner window
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -196,32 +186,31 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
enum EventType enum EventType
{ {
Closed, ///< The window requested to be closed (no data) Closed, ///< The window requested to be closed (no data)
Resized, ///< The window was resized (data in event.size) Resized, ///< The window was resized (data in event.size)
LostFocus, ///< The window lost the focus (no data) LostFocus, ///< The window lost the focus (no data)
GainedFocus, ///< The window gained the focus (no data) GainedFocus, ///< The window gained the focus (no data)
TextEntered, ///< A character was entered (data in event.text) TextEntered, ///< A character was entered (data in event.text)
KeyPressed, ///< A key was pressed (data in event.key) KeyPressed, ///< A key was pressed (data in event.key)
KeyReleased, ///< A key was released (data in event.key) KeyReleased, ///< A key was released (data in event.key)
MouseWheelMoved, ///< The mouse wheel was scrolled (data in event.mouseWheel) (deprecated) MouseWheelMoved, ///< The mouse wheel was scrolled (data in event.mouseWheel) (deprecated)
MouseWheelHorizontalMoved, ///< The mouse wheel was tilted horizontally (data in event.mouseWheelHorizontal) MouseWheelScrolled, ///< The mouse wheel was scrolled (data in event.mouseWheelScroll)
MouseWheelVerticalMoved, ///< The mouse wheel was scrolled vertically (data in event.mouseWheelVertical) MouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton)
MouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton) MouseButtonReleased, ///< A mouse button was released (data in event.mouseButton)
MouseButtonReleased, ///< A mouse button was released (data in event.mouseButton) MouseMoved, ///< The mouse cursor moved (data in event.mouseMove)
MouseMoved, ///< The mouse cursor moved (data in event.mouseMove) MouseEntered, ///< The mouse cursor entered the area of the window (no data)
MouseEntered, ///< The mouse cursor entered the area of the window (no data) MouseLeft, ///< The mouse cursor left the area of the window (no data)
MouseLeft, ///< The mouse cursor left the area of the window (no data) JoystickButtonPressed, ///< A joystick button was pressed (data in event.joystickButton)
JoystickButtonPressed, ///< A joystick button was pressed (data in event.joystickButton) JoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton)
JoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton) JoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove)
JoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove) JoystickConnected, ///< A joystick was connected (data in event.joystickConnect)
JoystickConnected, ///< A joystick was connected (data in event.joystickConnect) JoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect)
JoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect) TouchBegan, ///< A touch event began (data in event.touch)
TouchBegan, ///< A touch event began (data in event.touch) TouchMoved, ///< A touch moved (data in event.touch)
TouchMoved, ///< A touch moved (data in event.touch) TouchEnded, ///< A touch event ended (data in event.touch)
TouchEnded, ///< A touch event ended (data in event.touch) SensorChanged, ///< A sensor value changed (data in event.sensor)
SensorChanged, ///< A sensor value changed (data in event.sensor)
Count ///< Keep last -- the total number of event types Count ///< Keep last -- the total number of event types
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -231,19 +220,18 @@ public:
union union
{ {
SizeEvent size; ///< Size event parameters (Event::Resized) SizeEvent size; ///< Size event parameters (Event::Resized)
KeyEvent key; ///< Key event parameters (Event::KeyPressed, Event::KeyReleased) KeyEvent key; ///< Key event parameters (Event::KeyPressed, Event::KeyReleased)
TextEvent text; ///< Text event parameters (Event::TextEntered) TextEvent text; ///< Text event parameters (Event::TextEntered)
MouseMoveEvent mouseMove; ///< Mouse move event parameters (Event::MouseMoved) MouseMoveEvent mouseMove; ///< Mouse move event parameters (Event::MouseMoved)
MouseButtonEvent mouseButton; ///< Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased) MouseButtonEvent mouseButton; ///< Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased)
MouseWheelEvent mouseWheel; ///< Mouse wheel event parameters (Event::MouseWheelMoved) (deprecated) MouseWheelEvent mouseWheel; ///< Mouse wheel event parameters (Event::MouseWheelMoved) (deprecated)
MouseWheelHorizontalEvent mouseWheelHorizontal; ///< Mouse wheel horizontal event parameters (Event::MouseWheelHorizontalMoved) MouseWheelScrollEvent mouseWheelScroll; ///< Mouse wheel event parameters (Event::MouseWheelScrolled)
MouseWheelVerticalEvent mouseWheelVertical; ///< Mouse wheel vertical event parameters (Event::MouseWheelVerticalMoved) JoystickMoveEvent joystickMove; ///< Joystick move event parameters (Event::JoystickMoved)
JoystickMoveEvent joystickMove; ///< Joystick move event parameters (Event::JoystickMoved) JoystickButtonEvent joystickButton; ///< Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased)
JoystickButtonEvent joystickButton; ///< Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased) JoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected)
JoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected) TouchEvent touch; ///< Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded)
TouchEvent touch; ///< Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded) SensorEvent sensor; ///< Sensor event parameters (Event::SensorChanged)
SensorEvent sensor; ///< Sensor event parameters (Event::SensorChanged)
}; };
}; };

View File

@ -59,6 +59,16 @@ public:
ButtonCount ///< Keep last -- the total number of mouse buttons ButtonCount ///< Keep last -- the total number of mouse buttons
}; };
////////////////////////////////////////////////////////////
/// \brief Mouse wheels
///
////////////////////////////////////////////////////////////
enum Wheel
{
VerticalWheel, ///< The vertical mouse wheel
HorizontalWheel ///< The horizontal mouse wheel
};
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Check if a mouse button is pressed /// \brief Check if a mouse button is pressed
/// ///

View File

@ -381,18 +381,20 @@ void WindowImplCocoa::mouseWheelScrolledAt(float deltaX, float deltaY, int x, in
scaleOutXY(event.mouseWheel, m_delegate); scaleOutXY(event.mouseWheel, m_delegate);
pushEvent(event); pushEvent(event);
event.type = Event::MouseWheelVerticalMoved; event.type = Event::MouseWheelScrolled;
event.mouseWheelVertical.delta = deltaY; event.mouseWheelScroll.wheel = Mouse::VerticalWheel;
event.mouseWheelVertical.x = x; event.mouseWheelScroll.delta = deltaY;
event.mouseWheelVertical.y = y; event.mouseWheelScroll.x = x;
scaleOutXY(event.mouseWheelVertical, m_delegate); event.mouseWheelScroll.y = y;
scaleOutXY(event.mouseWheelScroll, m_delegate);
pushEvent(event); pushEvent(event);
event.type = Event::MouseWheelHorizontalMoved; event.type = Event::MouseWheelScrolled;
event.mouseWheelHorizontal.delta = deltaX; event.mouseWheelScroll.wheel = Mouse::HorizontalWheel;
event.mouseWheelHorizontal.x = x; event.mouseWheelScroll.delta = deltaX;
event.mouseWheelHorizontal.y = y; event.mouseWheelScroll.x = x;
scaleOutXY(event.mouseWheelHorizontal, m_delegate); event.mouseWheelScroll.y = y;
scaleOutXY(event.mouseWheelScroll, m_delegate);
pushEvent(event); pushEvent(event);
} }

View File

@ -2127,24 +2127,26 @@ bool WindowImplX11::processEvent(xcb_generic_event_t* windowEvent)
Event event; Event event;
event.type = Event::MouseWheelMoved; event.type = Event::MouseWheelMoved;
event.mouseWheel.delta = button == XCB_BUTTON_INDEX_4 ? 1 : -1; event.mouseWheel.delta = (button == XCB_BUTTON_INDEX_4) ? 1 : -1;
event.mouseWheel.x = e->event_x; event.mouseWheel.x = e->event_x;
event.mouseWheel.y = e->event_y; event.mouseWheel.y = e->event_y;
pushEvent(event); pushEvent(event);
event.type = Event::MouseWheelVerticalMoved; event.type = Event::MouseWheelScrolled;
event.mouseWheelVertical.delta = button == XCB_BUTTON_INDEX_4 ? 1 : -1; event.mouseWheelScroll.wheel = Mouse::VerticalWheel;
event.mouseWheelVertical.x = e->event_x; event.mouseWheelScroll.delta = (button == XCB_BUTTON_INDEX_4) ? 1 : -1;
event.mouseWheelVertical.y = e->event_y; event.mouseWheelScroll.x = e->event_x;
event.mouseWheelScroll.y = e->event_y;
pushEvent(event); pushEvent(event);
} }
else if ((button == 6) || (button == 7)) else if ((button == 6) || (button == 7))
{ {
Event event; Event event;
event.type = Event::MouseWheelHorizontalMoved; event.type = Event::MouseWheelScrolled;
event.mouseWheelHorizontal.delta = button == 6 ? 1 : -1; event.mouseWheelScroll.wheel = Mouse::HorizontalWheel;
event.mouseWheelHorizontal.x = e->event_x; event.mouseWheelScroll.delta = (button == 6) ? 1 : -1;
event.mouseWheelHorizontal.y = e->event_y; event.mouseWheelScroll.x = e->event_x;
event.mouseWheelScroll.y = e->event_y;
pushEvent(event); pushEvent(event);
} }
break; break;

View File

@ -665,7 +665,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
break; break;
} }
// Mouse wheel event // Vertical mouse wheel event
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
// Mouse position is in screen coordinates, convert it to window coordinates // Mouse position is in screen coordinates, convert it to window coordinates
@ -684,16 +684,16 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
event.mouseWheel.y = position.y; event.mouseWheel.y = position.y;
pushEvent(event); pushEvent(event);
event.type = Event::MouseWheelVerticalMoved; event.type = Event::MouseWheelScrolled;
event.mouseWheelVertical.delta = static_cast<float>(delta) / 120.f; event.mouseWheelScroll.wheel = Mouse::VerticalWheel;
event.mouseWheelVertical.x = position.x; event.mouseWheelScroll.delta = static_cast<float>(delta) / 120.f;
event.mouseWheelVertical.y = position.y; event.mouseWheelScroll.x = position.x;
event.mouseWheelScroll.y = position.y;
pushEvent(event); pushEvent(event);
break; break;
} }
// Mouse wheel event // Horizontal mouse wheel event
case WM_MOUSEHWHEEL: case WM_MOUSEHWHEEL:
{ {
// Mouse position is in screen coordinates, convert it to window coordinates // Mouse position is in screen coordinates, convert it to window coordinates
@ -705,10 +705,11 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Int16 delta = static_cast<Int16>(HIWORD(wParam)); Int16 delta = static_cast<Int16>(HIWORD(wParam));
Event event; Event event;
event.type = Event::MouseWheelHorizontalMoved; event.type = Event::MouseWheelScrolled;
event.mouseWheelHorizontal.delta = -static_cast<float>(delta) / 120.f; event.mouseWheelScroll.wheel = Mouse::HorizontalWheel;
event.mouseWheelHorizontal.x = position.x; event.mouseWheelScroll.delta = -static_cast<float>(delta) / 120.f;
event.mouseWheelHorizontal.y = position.y; event.mouseWheelScroll.x = position.x;
event.mouseWheelScroll.y = position.y;
pushEvent(event); pushEvent(event);
break; break;
} }