Fixed MouseMove event sometimes not generated when holding left button on Windows (#225)

This commit is contained in:
Laurent Gomila 2013-07-11 23:02:33 +02:00
parent 5c431b4b93
commit 9528fbc893
2 changed files with 36 additions and 27 deletions

View File

@ -71,7 +71,6 @@ m_callback (0),
m_cursor (NULL), m_cursor (NULL),
m_icon (NULL), m_icon (NULL),
m_keyRepeatEnabled(true), m_keyRepeatEnabled(true),
m_isCursorIn (false),
m_lastSize (0, 0), m_lastSize (0, 0),
m_resizing (false), m_resizing (false),
m_surrogate (0) m_surrogate (0)
@ -92,7 +91,6 @@ m_callback (0),
m_cursor (NULL), m_cursor (NULL),
m_icon (NULL), m_icon (NULL),
m_keyRepeatEnabled(true), m_keyRepeatEnabled(true),
m_isCursorIn (false),
m_lastSize (mode.width, mode.height), m_lastSize (mode.width, mode.height),
m_resizing (false), m_resizing (false),
m_surrogate (0) m_surrogate (0)
@ -712,39 +710,51 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
// Mouse move event // Mouse move event
case WM_MOUSEMOVE : case WM_MOUSEMOVE :
{ {
// Check if we need to generate a MouseEntered event // Extract the mouse local coordinates
if (!m_isCursorIn) int x = static_cast<Int16>(LOWORD(lParam));
int y = static_cast<Int16>(HIWORD(lParam));
// Get the client area of the window
RECT area;
GetClientRect(m_handle, &area);
// Check the mouse position against the window
if ((x < area.left) || (x > area.right) || (y < area.top) || (y > area.bottom))
{ {
TRACKMOUSEEVENT mouseEvent; // Mouse is outside
mouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
mouseEvent.hwndTrack = m_handle;
mouseEvent.dwFlags = TME_LEAVE;
TrackMouseEvent(&mouseEvent);
m_isCursorIn = true; // Release the mouse capture
ReleaseCapture();
// Generate a MouseLeft event
Event event; Event event;
event.type = Event::MouseEntered; event.type = Event::MouseLeft;
pushEvent(event); pushEvent(event);
} }
else
{
// Mouse is inside
if (GetCapture() != m_handle)
{
// Mouse was previously outside the window
Event event; // Capture the mouse
event.type = Event::MouseMoved; SetCapture(m_handle);
event.mouseMove.x = static_cast<Int16>(LOWORD(lParam));
event.mouseMove.y = static_cast<Int16>(HIWORD(lParam));
pushEvent(event);
break;
}
// Mouse leave event // Generate a MouseEntered event
case WM_MOUSELEAVE : Event event;
{ event.type = Event::MouseEntered;
m_isCursorIn = false; pushEvent(event);
}
Event event; // Generate a MouseMove event
event.type = Event::MouseLeft; Event event;
pushEvent(event); event.type = Event::MouseMoved;
break; event.mouseMove.x = x;
event.mouseMove.y = y;
pushEvent(event);
break;
}
} }
} }
} }

View File

@ -236,7 +236,6 @@ private :
HCURSOR m_cursor; ///< The system cursor to display into the window HCURSOR m_cursor; ///< The system cursor to display into the window
HICON m_icon; ///< Custom icon assigned to the window HICON m_icon; ///< Custom icon assigned to the window
bool m_keyRepeatEnabled; ///< Automatic key-repeat state for keydown events bool m_keyRepeatEnabled; ///< Automatic key-repeat state for keydown events
bool m_isCursorIn; ///< Is the mouse cursor in the window's area ?
Vector2u m_lastSize; ///< The last handled size of the window Vector2u m_lastSize; ///< The last handled size of the window
bool m_resizing; ///< Is the window being resized ? bool m_resizing; ///< Is the window being resized ?
Uint16 m_surrogate; ///< First half of the surrogate pair, in case we're receiving a Unicode character in two events Uint16 m_surrogate; ///< First half of the surrogate pair, in case we're receiving a Unicode character in two events