mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Implemented support for horizontal mouse wheel scrolling as well as high-precision scrolling on Windows and OS X.
This commit is contained in:
parent
81a8e4e4ca
commit
e17cc520d6
@ -102,6 +102,9 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Mouse wheel events parameters (MouseWheelMoved)
|
/// \brief Mouse wheel events parameters (MouseWheelMoved)
|
||||||
///
|
///
|
||||||
|
/// \deprecated This event is deprecated and potentially inaccurate.
|
||||||
|
/// Use MouseWheelVerticalEvent instead.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct MouseWheelEvent
|
struct MouseWheelEvent
|
||||||
{
|
{
|
||||||
@ -110,6 +113,28 @@ public:
|
|||||||
int y; ///< Y position of the mouse pointer, relative to the top of the owner window
|
int y; ///< Y position of the mouse pointer, relative to the top of the owner window
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Mouse wheel horizontal events parameters (MouseWheelHorizontalMoved)
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
struct MouseWheelHorizontalEvent
|
||||||
|
{
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Joystick connection events parameters
|
/// \brief Joystick connection events parameters
|
||||||
/// (JoystickConnected, JoystickDisconnected)
|
/// (JoystickConnected, JoystickDisconnected)
|
||||||
@ -178,7 +203,9 @@ public:
|
|||||||
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)
|
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)
|
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)
|
||||||
@ -209,7 +236,9 @@ public:
|
|||||||
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)
|
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)
|
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)
|
||||||
|
@ -474,7 +474,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
|||||||
if (m_requester != 0)
|
if (m_requester != 0)
|
||||||
{
|
{
|
||||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||||
m_requester->mouseWheelScrolledAt([theEvent deltaY], loc.x, loc.y);
|
m_requester->mouseWheelScrolledAt([theEvent deltaX], [theEvent deltaY], loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transmit to non-SFML responder
|
// Transmit to non-SFML responder
|
||||||
|
@ -164,12 +164,13 @@ public:
|
|||||||
///
|
///
|
||||||
/// Send the event to SFML WindowImpl class.
|
/// Send the event to SFML WindowImpl class.
|
||||||
///
|
///
|
||||||
/// \param delta scrolling delta
|
/// \param deltaX horizontal scrolling delta
|
||||||
|
/// \param deltaY vertical scrolling delta
|
||||||
/// \param x mouse x position
|
/// \param x mouse x position
|
||||||
/// \param y mouse y position
|
/// \param y mouse y position
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void mouseWheelScrolledAt(float delta, int x, int y);
|
void mouseWheelScrolledAt(float deltaX, float deltaY, int x, int y);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Mouse In Event - called by the cocoa view object
|
/// \brief Mouse In Event - called by the cocoa view object
|
||||||
|
@ -370,15 +370,29 @@ void WindowImplCocoa::mouseMovedAt(int x, int y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void WindowImplCocoa::mouseWheelScrolledAt(float delta, int x, int y)
|
void WindowImplCocoa::mouseWheelScrolledAt(float deltaX, float deltaY, int x, int y)
|
||||||
{
|
{
|
||||||
Event event;
|
Event event;
|
||||||
|
|
||||||
event.type = Event::MouseWheelMoved;
|
event.type = Event::MouseWheelMoved;
|
||||||
event.mouseWheel.delta = delta;
|
event.mouseWheel.delta = deltaY;
|
||||||
event.mouseWheel.x = x;
|
event.mouseWheel.x = x;
|
||||||
event.mouseWheel.y = y;
|
event.mouseWheel.y = y;
|
||||||
scaleOutXY(event.mouseWheel, m_delegate);
|
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);
|
||||||
|
pushEvent(event);
|
||||||
|
|
||||||
|
event.type = Event::MouseWheelHorizontalMoved;
|
||||||
|
event.mouseWheelHorizontal.delta = deltaX;
|
||||||
|
event.mouseWheelHorizontal.x = x;
|
||||||
|
event.mouseWheelHorizontal.y = y;
|
||||||
|
scaleOutXY(event.mouseWheelHorizontal, m_delegate);
|
||||||
pushEvent(event);
|
pushEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1154,6 +1154,7 @@ bool WindowImplX11::processEvent(xcb_generic_event_t* windowEvent)
|
|||||||
xcb_button_press_event_t* e = reinterpret_cast<xcb_button_press_event_t*>(windowEvent);
|
xcb_button_press_event_t* e = reinterpret_cast<xcb_button_press_event_t*>(windowEvent);
|
||||||
|
|
||||||
// XXX: Why button 8 and 9?
|
// XXX: Why button 8 and 9?
|
||||||
|
// Because 4 and 5 are the vertical wheel and 6 and 7 are horizontal wheel ;)
|
||||||
xcb_button_t button = e->detail;
|
xcb_button_t button = e->detail;
|
||||||
if ((button == XCB_BUTTON_INDEX_1) ||
|
if ((button == XCB_BUTTON_INDEX_1) ||
|
||||||
(button == XCB_BUTTON_INDEX_2) ||
|
(button == XCB_BUTTON_INDEX_2) ||
|
||||||
@ -1207,11 +1208,27 @@ bool WindowImplX11::processEvent(xcb_generic_event_t* windowEvent)
|
|||||||
else if ((button == XCB_BUTTON_INDEX_4) || (button == XCB_BUTTON_INDEX_5))
|
else if ((button == XCB_BUTTON_INDEX_4) || (button == XCB_BUTTON_INDEX_5))
|
||||||
{
|
{
|
||||||
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.mouseWheelVertical.delta = button == XCB_BUTTON_INDEX_4 ? 1 : -1;
|
||||||
|
event.mouseWheelVertical.x = e->event_x;
|
||||||
|
event.mouseWheelVertical.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;
|
||||||
|
pushEvent(event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,9 @@
|
|||||||
#ifndef XBUTTON2
|
#ifndef XBUTTON2
|
||||||
#define XBUTTON2 0x0002
|
#define XBUTTON2 0x0002
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef WM_MOUSEHWHEEL
|
||||||
|
#define WM_MOUSEHWHEEL 0x020E
|
||||||
|
#endif
|
||||||
#ifndef MAPVK_VK_TO_VSC
|
#ifndef MAPVK_VK_TO_VSC
|
||||||
#define MAPVK_VK_TO_VSC (0)
|
#define MAPVK_VK_TO_VSC (0)
|
||||||
#endif
|
#endif
|
||||||
@ -671,12 +674,42 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
position.y = static_cast<Int16>(HIWORD(lParam));
|
position.y = static_cast<Int16>(HIWORD(lParam));
|
||||||
ScreenToClient(m_handle, &position);
|
ScreenToClient(m_handle, &position);
|
||||||
|
|
||||||
|
Int16 delta = static_cast<Int16>(HIWORD(wParam));
|
||||||
|
|
||||||
Event event;
|
Event event;
|
||||||
|
|
||||||
event.type = Event::MouseWheelMoved;
|
event.type = Event::MouseWheelMoved;
|
||||||
event.mouseWheel.delta = static_cast<Int16>(HIWORD(wParam)) / 120;
|
event.mouseWheel.delta = delta / 120;
|
||||||
event.mouseWheel.x = position.x;
|
event.mouseWheel.x = position.x;
|
||||||
event.mouseWheel.y = position.y;
|
event.mouseWheel.y = position.y;
|
||||||
pushEvent(event);
|
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;
|
||||||
|
pushEvent(event);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mouse wheel event
|
||||||
|
case WM_MOUSEHWHEEL:
|
||||||
|
{
|
||||||
|
// Mouse position is in screen coordinates, convert it to window coordinates
|
||||||
|
POINT position;
|
||||||
|
position.x = static_cast<Int16>(LOWORD(lParam));
|
||||||
|
position.y = static_cast<Int16>(HIWORD(lParam));
|
||||||
|
ScreenToClient(m_handle, &position);
|
||||||
|
|
||||||
|
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;
|
||||||
|
pushEvent(event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user