diff --git a/include/SFML/Window/Event.hpp b/include/SFML/Window/Event.hpp index 9138b04e2..c901e4dfc 100644 --- a/include/SFML/Window/Event.hpp +++ b/include/SFML/Window/Event.hpp @@ -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,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) - 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 + 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 }; //////////////////////////////////////////////////////////// @@ -196,32 +186,31 @@ public: //////////////////////////////////////////////////////////// enum EventType { - Closed, ///< The window requested to be closed (no data) - Resized, ///< The window was resized (data in event.size) - LostFocus, ///< The window lost the focus (no data) - GainedFocus, ///< The window gained the focus (no data) - TextEntered, ///< A character was entered (data in event.text) - 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) - 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) - MouseEntered, ///< The mouse cursor entered 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) - JoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton) - JoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove) - JoystickConnected, ///< A joystick was connected (data in event.joystickConnect) - JoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect) - TouchBegan, ///< A touch event began (data in event.touch) - TouchMoved, ///< A touch moved (data in event.touch) - TouchEnded, ///< A touch event ended (data in event.touch) - SensorChanged, ///< A sensor value changed (data in event.sensor) + Closed, ///< The window requested to be closed (no data) + Resized, ///< The window was resized (data in event.size) + LostFocus, ///< The window lost the focus (no data) + GainedFocus, ///< The window gained the focus (no data) + TextEntered, ///< A character was entered (data in event.text) + 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) + 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) + MouseEntered, ///< The mouse cursor entered 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) + JoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton) + JoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove) + JoystickConnected, ///< A joystick was connected (data in event.joystickConnect) + JoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect) + TouchBegan, ///< A touch event began (data in event.touch) + TouchMoved, ///< A touch moved (data in event.touch) + TouchEnded, ///< A touch event ended (data in event.touch) + 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 { - SizeEvent size; ///< Size event parameters (Event::Resized) - KeyEvent key; ///< Key event parameters (Event::KeyPressed, Event::KeyReleased) - TextEvent text; ///< Text event parameters (Event::TextEntered) - 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) - 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) - TouchEvent touch; ///< Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded) - SensorEvent sensor; ///< Sensor event parameters (Event::SensorChanged) + SizeEvent size; ///< Size event parameters (Event::Resized) + KeyEvent key; ///< Key event parameters (Event::KeyPressed, Event::KeyReleased) + TextEvent text; ///< Text event parameters (Event::TextEntered) + 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) + 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) + TouchEvent touch; ///< Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded) + SensorEvent sensor; ///< Sensor event parameters (Event::SensorChanged) }; }; diff --git a/include/SFML/Window/Mouse.hpp b/include/SFML/Window/Mouse.hpp index 0f5f8fece..0056f8ca0 100644 --- a/include/SFML/Window/Mouse.hpp +++ b/include/SFML/Window/Mouse.hpp @@ -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 /// diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index 9fe17b288..927d5b427 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -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); } diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 4431a0671..40d511cc0 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -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; diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 903cc0b27..8bf86ab81 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -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(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(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(HIWORD(wParam)); Event event; - event.type = Event::MouseWheelHorizontalMoved; - event.mouseWheelHorizontal.delta = -static_cast(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(delta) / 120.f; + event.mouseWheelScroll.x = position.x; + event.mouseWheelScroll.y = position.y; pushEvent(event); break; }