From 21c6f976176fb572be6133f4d1006075074a2c07 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 10 Feb 2010 13:54:38 +0000 Subject: [PATCH 1/3] Removed all references to sf::RenderImage, which doesn't exist in SFML 1.x git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1398 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Graphics/Image.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index 0c6538e0..c2f5c898 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -37,7 +37,6 @@ namespace sf { -class RenderImage; class RenderWindow; //////////////////////////////////////////////////////////// @@ -281,8 +280,6 @@ public : private : - friend class RenderImage; - //////////////////////////////////////////////////////////// /// Create the OpenGL texture /// From 3621cb10f796413ee12af0277ca1ac61f2f09522 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 10 Feb 2010 23:35:01 +0000 Subject: [PATCH 2/3] Fixed bugs with the LShift and RShift keys git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1400 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Win32/WindowImplWin32.cpp | 81 ++++++----------------- src/SFML/Window/Win32/WindowImplWin32.hpp | 11 --- 2 files changed, 20 insertions(+), 72 deletions(-) diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index f59f4021..526ad566 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -765,26 +765,15 @@ void WindowImplWin32::ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam) case WM_KEYDOWN : case WM_SYSKEYDOWN : { - if (myKeyRepeatEnabled || ((LParam & (1 << 30)) == 0)) + if (myKeyRepeatEnabled || ((HIWORD(LParam) & KF_REPEAT) == 0)) { Event Evt; Evt.Type = Event::KeyPressed; Evt.Key.Alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0; Evt.Key.Control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0; Evt.Key.Shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0; - - if (WParam != VK_SHIFT) - { - Evt.Key.Code = VirtualKeyCodeToSF(WParam, LParam); - SendEvent(Evt); - } - else - { - // Special case for shift, its state can't be retrieved directly - Evt.Key.Code = GetShiftState(true); - if (Evt.Key.Code != 0) - SendEvent(Evt); - } + Evt.Key.Code = VirtualKeyCodeToSF(WParam, LParam); + SendEvent(Evt); } break; } @@ -798,19 +787,8 @@ void WindowImplWin32::ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam) Evt.Key.Alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0; Evt.Key.Control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0; Evt.Key.Shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0; - - if (WParam != VK_SHIFT) - { - Evt.Key.Code = VirtualKeyCodeToSF(WParam, LParam); - SendEvent(Evt); - } - else - { - // Special case for shift, its state can't be retrieved directly - Evt.Key.Code = GetShiftState(false); - if (Evt.Key.Code != 0) - SendEvent(Evt); - } + Evt.Key.Code = VirtualKeyCodeToSF(WParam, LParam); + SendEvent(Evt); break; } @@ -962,37 +940,6 @@ void WindowImplWin32::ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam) } -//////////////////////////////////////////////////////////// -/// Check the state of the shift keys on a key event, -/// and return the corresponding SF key code -//////////////////////////////////////////////////////////// -Key::Code WindowImplWin32::GetShiftState(bool KeyDown) -{ - static bool LShiftPrevDown = false; - static bool RShiftPrevDown = false; - - bool LShiftDown = (HIWORD(GetAsyncKeyState(VK_LSHIFT)) != 0); - bool RShiftDown = (HIWORD(GetAsyncKeyState(VK_RSHIFT)) != 0); - - Key::Code Code = Key::Code(0); - if (KeyDown) - { - if (!LShiftPrevDown && LShiftDown) Code = Key::LShift; - else if (!RShiftPrevDown && RShiftDown) Code = Key::RShift; - } - else - { - if (LShiftPrevDown && !LShiftDown) Code = Key::LShift; - else if (RShiftPrevDown && !RShiftDown) Code = Key::RShift; - } - - LShiftPrevDown = LShiftDown; - RShiftPrevDown = RShiftDown; - - return Code; -} - - //////////////////////////////////////////////////////////// /// Convert a Win32 virtual key code to a SFML key code //////////////////////////////////////////////////////////// @@ -1000,9 +947,21 @@ Key::Code WindowImplWin32::VirtualKeyCodeToSF(WPARAM VirtualKey, LPARAM Flags) { switch (VirtualKey) { - // VK_SHIFT is handled by the GetShiftState function - case VK_MENU : return (Flags & (1 << 24)) ? Key::RAlt : Key::LAlt; - case VK_CONTROL : return (Flags & (1 << 24)) ? Key::RControl : Key::LControl; + // Check the scancode to distinguish between left and right shift + case VK_SHIFT : + { + static UINT LShift = MapVirtualKey(VK_LSHIFT, MAPVK_VK_TO_VSC); + UINT scancode = (Flags & (0xFF << 16)) >> 16; + return scancode == LShift ? Key::LShift : Key::RShift; + } + + // Check the "extended" flag to distinguish between left and right alt + case VK_MENU : return (HIWORD(Flags) & KF_EXTENDED) ? Key::RAlt : Key::LAlt; + + // Check the "extended" flag to distinguish between left and right control + case VK_CONTROL : return (HIWORD(Flags) & KF_EXTENDED) ? Key::RControl : Key::LControl; + + // Other keys are reported properly case VK_LWIN : return Key::LSystem; case VK_RWIN : return Key::RSystem; case VK_APPS : return Key::Menu; diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index 75c1c59e..20557dcd 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -193,17 +193,6 @@ private : //////////////////////////////////////////////////////////// void ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam); - //////////////////////////////////////////////////////////// - /// Check the state of the shift keys on a key event, - /// and return the corresponding SF key code - /// - /// \param KeyDown : True for a keydown event, false for a keyup event - /// - /// \return SFML key code corresponding to the shift key - /// - //////////////////////////////////////////////////////////// - static Key::Code GetShiftState(bool KeyDown); - //////////////////////////////////////////////////////////// /// Convert a Win32 virtual key code to a SFML key code /// From cdc1346612ab5dca28fcc63e6437fb1822790290 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Thu, 11 Feb 2010 08:31:52 +0000 Subject: [PATCH 3/3] FS#152 - Fix crash with the default font at global exit on Windows git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1401 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Graphics/Font.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index df2e5633..36c4c280 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -158,14 +158,28 @@ const Image& Font::GetImage() const //////////////////////////////////////////////////////////// const Font& Font::GetDefaultFont() { - static Font DefaultFont; - static bool DefaultFontLoaded = false; +#if defined(SFML_SYSTEM_WINDOWS) && defined(SFML_DYNAMIC) + + // On Windows dynamic build, the default font causes a crash at global exit. + // This is a temporary workaround that turns the crash into a memory leak. + // Note that this bug doesn't exist anymore in SFML 2. + static Font* DefaultFontPtr = new Font; + Font& DefaultFont = *DefaultFontPtr; + +#else + + static Font DefaultFont; + +#endif + + // Get the raw data of the Arial font file into an array, so that we can load it into the font static const char DefaultFontData[] = { #include }; // Load the default font on first call + static bool DefaultFontLoaded = false; if (!DefaultFontLoaded) { DefaultFont.LoadFromMemory(DefaultFontData, sizeof(DefaultFontData), 30);