mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51: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)
|
||||||
@ -171,30 +196,32 @@ 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)
|
MouseWheelMoved, ///< The mouse wheel was scrolled (data in event.mouseWheel) (deprecated)
|
||||||
MouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton)
|
MouseWheelHorizontalMoved, ///< The mouse wheel was tilted horizontally (data in event.mouseWheelHorizontal)
|
||||||
MouseButtonReleased, ///< A mouse button was released (data in event.mouseButton)
|
MouseWheelVerticalMoved, ///< The mouse wheel was scrolled vertically (data in event.mouseWheelVertical)
|
||||||
MouseMoved, ///< The mouse cursor moved (data in event.mouseMove)
|
MouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton)
|
||||||
MouseEntered, ///< The mouse cursor entered the area of the window (no data)
|
MouseButtonReleased, ///< A mouse button was released (data in event.mouseButton)
|
||||||
MouseLeft, ///< The mouse cursor left the area of the window (no data)
|
MouseMoved, ///< The mouse cursor moved (data in event.mouseMove)
|
||||||
JoystickButtonPressed, ///< A joystick button was pressed (data in event.joystickButton)
|
MouseEntered, ///< The mouse cursor entered the area of the window (no data)
|
||||||
JoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton)
|
MouseLeft, ///< The mouse cursor left the area of the window (no data)
|
||||||
JoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove)
|
JoystickButtonPressed, ///< A joystick button was pressed (data in event.joystickButton)
|
||||||
JoystickConnected, ///< A joystick was connected (data in event.joystickConnect)
|
JoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton)
|
||||||
JoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect)
|
JoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove)
|
||||||
TouchBegan, ///< A touch event began (data in event.touch)
|
JoystickConnected, ///< A joystick was connected (data in event.joystickConnect)
|
||||||
TouchMoved, ///< A touch moved (data in event.touch)
|
JoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect)
|
||||||
TouchEnded, ///< A touch event ended (data in event.touch)
|
TouchBegan, ///< A touch event began (data in event.touch)
|
||||||
SensorChanged, ///< A sensor value changed (data in event.sensor)
|
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
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -204,17 +231,19 @@ 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)
|
MouseWheelEvent mouseWheel; ///< Mouse wheel event parameters (Event::MouseWheelMoved) (deprecated)
|
||||||
JoystickMoveEvent joystickMove; ///< Joystick move event parameters (Event::JoystickMoved)
|
MouseWheelHorizontalEvent mouseWheelHorizontal; ///< Mouse wheel horizontal event parameters (Event::MouseWheelHorizontalMoved)
|
||||||
JoystickButtonEvent joystickButton; ///< Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased)
|
MouseWheelVerticalEvent mouseWheelVertical; ///< Mouse wheel vertical event parameters (Event::MouseWheelVerticalMoved)
|
||||||
JoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected)
|
JoystickMoveEvent joystickMove; ///< Joystick move event parameters (Event::JoystickMoved)
|
||||||
TouchEvent touch; ///< Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded)
|
JoystickButtonEvent joystickButton; ///< Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased)
|
||||||
SensorEvent sensor; ///< Sensor event parameters (Event::SensorChanged)
|
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)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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,11 +674,41 @@ 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.mouseWheel.delta = static_cast<Int16>(HIWORD(wParam)) / 120;
|
event.type = Event::MouseWheelMoved;
|
||||||
event.mouseWheel.x = position.x;
|
event.mouseWheel.delta = delta / 120;
|
||||||
event.mouseWheel.y = position.y;
|
event.mouseWheel.x = position.x;
|
||||||
|
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;
|
||||||
|
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);
|
pushEvent(event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user