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

View File

@ -236,7 +236,6 @@ private :
HCURSOR m_cursor; ///< The system cursor to display into the window
HICON m_icon; ///< Custom icon assigned to the window
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
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