From 75fee5675a1de536668859c09287adea1308d627 Mon Sep 17 00:00:00 2001 From: kimci86 Date: Fri, 6 Jul 2012 18:44:45 +0200 Subject: [PATCH] Better behavior of sf::Event::Resized on Windows --- src/SFML/Window/Win32/WindowImplWin32.cpp | 52 ++++++++++++++++++----- src/SFML/Window/Win32/WindowImplWin32.hpp | 2 + 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 8440dc529..77dd0f9ad 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -72,7 +72,9 @@ m_callback (0), m_cursor (NULL), m_icon (NULL), m_keyRepeatEnabled(true), -m_isCursorIn (false) +m_isCursorIn (false), +m_lastSize (0, 0), +m_resizing (false) { if (m_handle) { @@ -90,7 +92,9 @@ m_callback (0), m_cursor (NULL), m_icon (NULL), m_keyRepeatEnabled(true), -m_isCursorIn (false) +m_isCursorIn (false), +m_lastSize (mode.width, mode.height), +m_resizing (false) { // Register the window class at first call if (windowCount == 0) @@ -436,20 +440,48 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Resize event case WM_SIZE : { - // Ignore size events triggered by a minimize (size == 0 in this case) - if (wParam != SIZE_MINIMIZED) + // Consider only events triggered by a maximize or a un-maximize + if (wParam != SIZE_MINIMIZED && !m_resizing && m_lastSize != getSize()) { - // Get the new size - RECT rectangle; - GetClientRect(m_handle, &rectangle); + // Update the last handled size + m_lastSize = getSize(); + // Push a resize event Event event; event.type = Event::Resized; - event.size.width = rectangle.right - rectangle.left; - event.size.height = rectangle.bottom - rectangle.top; + event.size.width = m_lastSize.x; + event.size.height = m_lastSize.y; pushEvent(event); - break; } + break; + } + + // Start resizing + case WM_ENTERSIZEMOVE: + { + m_resizing = true; + break; + } + + // Stop resizing + case WM_EXITSIZEMOVE: + { + m_resizing = false; + + // Ignore cases where the window has only been moved + if(m_lastSize != getSize()) + { + // Update the last handled size + m_lastSize = getSize(); + + // Push a resize event + Event event; + event.type = Event::Resized; + event.size.width = m_lastSize.x; + event.size.height = m_lastSize.y; + pushEvent(event); + } + break; } // Gain focus event diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index 542c57dcf..88d1a3ed1 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -236,6 +236,8 @@ private : 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 ? }; } // namespace priv