diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 6f6d743b9..093f80535 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -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(LOWORD(lParam)); + int y = static_cast(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::MouseEntered; + event.type = Event::MouseLeft; pushEvent(event); } + else + { + // Mouse is inside + if (GetCapture() != m_handle) + { + // Mouse was previously outside the window - Event event; - event.type = Event::MouseMoved; - event.mouseMove.x = static_cast(LOWORD(lParam)); - event.mouseMove.y = static_cast(HIWORD(lParam)); - pushEvent(event); - break; - } + // Capture the mouse + SetCapture(m_handle); - // Mouse leave event - case WM_MOUSELEAVE : - { - m_isCursorIn = false; + // Generate a MouseEntered event + Event event; + event.type = Event::MouseEntered; + pushEvent(event); + } - Event event; - event.type = Event::MouseLeft; - pushEvent(event); - break; + // Generate a MouseMove event + Event event; + event.type = Event::MouseMoved; + event.mouseMove.x = x; + event.mouseMove.y = y; + pushEvent(event); + break; + } } } } diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index b6ca9751c..a0ccc6128 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -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