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)
///
/// \deprecated This event is deprecated and potentially inaccurate.
/// Use MouseWheelVerticalEvent instead.
/// Use MouseWheelScrollEvent instead.
///
////////////////////////////////////////////////////////////
struct MouseWheelEvent
@ -114,23 +114,13 @@ 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)
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)
Mouse::Wheel wheel; ///< Which wheel (for mice with multiple ones)
float delta; ///< Wheel offset (positive is up/left, negative is down/right). High-precision mice may use non-integral offsets.
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
};
@ -204,8 +194,7 @@ public:
KeyPressed, ///< A key was pressed (data in event.key)
KeyReleased, ///< A key was released (data in event.key)
MouseWheelMoved, ///< The mouse wheel was scrolled (data in event.mouseWheel) (deprecated)
MouseWheelHorizontalMoved, ///< The mouse wheel was tilted horizontally (data in event.mouseWheelHorizontal)
MouseWheelVerticalMoved, ///< The mouse wheel was scrolled vertically (data in event.mouseWheelVertical)
MouseWheelScrolled, ///< The mouse wheel was scrolled (data in event.mouseWheelScroll)
MouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton)
MouseButtonReleased, ///< A mouse button was released (data in event.mouseButton)
MouseMoved, ///< The mouse cursor moved (data in event.mouseMove)
@ -237,8 +226,7 @@ public:
MouseMoveEvent mouseMove; ///< Mouse move event parameters (Event::MouseMoved)
MouseButtonEvent mouseButton; ///< Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased)
MouseWheelEvent mouseWheel; ///< Mouse wheel event parameters (Event::MouseWheelMoved) (deprecated)
MouseWheelHorizontalEvent mouseWheelHorizontal; ///< Mouse wheel horizontal event parameters (Event::MouseWheelHorizontalMoved)
MouseWheelVerticalEvent mouseWheelVertical; ///< Mouse wheel vertical event parameters (Event::MouseWheelVerticalMoved)
MouseWheelScrollEvent mouseWheelScroll; ///< Mouse wheel event parameters (Event::MouseWheelScrolled)
JoystickMoveEvent joystickMove; ///< Joystick move event parameters (Event::JoystickMoved)
JoystickButtonEvent joystickButton; ///< Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased)
JoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected)

View File

@ -59,6 +59,16 @@ public:
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
///

View File

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

View File

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

View File

@ -665,7 +665,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
break;
}
// Mouse wheel event
// Vertical mouse wheel event
case WM_MOUSEWHEEL:
{
// 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;
pushEvent(event);
event.type = Event::MouseWheelVerticalMoved;
event.mouseWheelVertical.delta = static_cast<float>(delta) / 120.f;
event.mouseWheelVertical.x = position.x;
event.mouseWheelVertical.y = position.y;
event.type = Event::MouseWheelScrolled;
event.mouseWheelScroll.wheel = Mouse::VerticalWheel;
event.mouseWheelScroll.delta = static_cast<float>(delta) / 120.f;
event.mouseWheelScroll.x = position.x;
event.mouseWheelScroll.y = position.y;
pushEvent(event);
break;
}
// Mouse wheel event
// Horizontal mouse wheel event
case WM_MOUSEHWHEEL:
{
// 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));
Event event;
event.type = Event::MouseWheelHorizontalMoved;
event.mouseWheelHorizontal.delta = -static_cast<float>(delta) / 120.f;
event.mouseWheelHorizontal.x = position.x;
event.mouseWheelHorizontal.y = position.y;
event.type = Event::MouseWheelScrolled;
event.mouseWheelScroll.wheel = Mouse::HorizontalWheel;
event.mouseWheelScroll.delta = -static_cast<float>(delta) / 120.f;
event.mouseWheelScroll.x = position.x;
event.mouseWheelScroll.y = position.y;
pushEvent(event);
break;
}