From ffe748b8c38061b4033ad9c404dad12e95879001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Mon, 7 Nov 2016 10:51:23 +0100 Subject: [PATCH] Window: Fix Threaded flag, seems to be working fine now --- src/Nazara/Utility/Win32/WindowImpl.cpp | 57 +++++++++++++------------ src/Nazara/Utility/Win32/WindowImpl.hpp | 4 +- src/Nazara/Utility/Window.cpp | 4 +- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index 4a7f7eb9b..558a44ddb 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -148,6 +148,11 @@ namespace Nz m_callback = 0; + m_eventListener = true; + m_ownsWindow = true; + m_sizemove = false; + m_style = style; + if (async) { Mutex mutex; @@ -156,7 +161,7 @@ namespace Nz // On attend que la fenêtre soit créée mutex.Lock(); - m_thread = Thread(WindowThread, &m_handle, win32StyleEx, title, win32Style, x, y, width, height, this, &mutex, &condition); + m_thread = Thread(WindowThread, &m_handle, win32StyleEx, title, win32Style, fullscreen, Rectui(x, y, width, height), this, &mutex, &condition); condition.Wait(&mutex); mutex.Unlock(); } @@ -169,24 +174,8 @@ namespace Nz return false; } - if (fullscreen) - { - SetForegroundWindow(m_handle); - ShowWindow(m_handle, SW_SHOW); - } - - m_eventListener = true; - m_ownsWindow = true; - m_sizemove = false; - m_style = style; - - // Récupération de la position/taille de la fenêtre (Après sa création) - RECT clientRect, windowRect; - GetClientRect(m_handle, &clientRect); - GetWindowRect(m_handle, &windowRect); - - m_position.Set(windowRect.left, windowRect.top); - m_size.Set(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); + if (!async) + PrepareWindow(fullscreen); return true; } @@ -321,11 +310,7 @@ namespace Nz if (m_ownsWindow) { if (block) - { - NazaraNotice("WaitMessage"); WaitMessage(); - NazaraNotice("~WaitMessage"); - } MSG message; while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE)) @@ -977,6 +962,23 @@ namespace Nz return false; } + void WindowImpl::PrepareWindow(bool fullscreen) + { + if (fullscreen) + { + SetForegroundWindow(m_handle); + ShowWindow(m_handle, SW_SHOW); + } + + // Cache window position/size after creation + RECT clientRect, windowRect; + GetClientRect(m_handle, &clientRect); + GetWindowRect(m_handle, &windowRect); + + m_position.Set(windowRect.left, windowRect.top); + m_size.Set(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); + } + bool WindowImpl::Initialize() { // Nous devons faire un type Unicode pour que la fenêtre le soit également @@ -1191,10 +1193,13 @@ namespace Nz return style; } - void WindowImpl::WindowThread(HWND* handle, DWORD styleEx, const String& title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, WindowImpl* window, Mutex* mutex, ConditionVariable* condition) + void WindowImpl::WindowThread(HWND* handle, DWORD styleEx, const String& title, DWORD style, bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition) { HWND& winHandle = *handle; - winHandle = CreateWindowExW(styleEx, className, title.GetWideString().data(), style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), window); + winHandle = CreateWindowExW(styleEx, className, title.GetWideString().data(), style, dimensions.x, dimensions.y, dimensions.width, dimensions.height, nullptr, nullptr, GetModuleHandle(nullptr), window); + + if (winHandle) + window->PrepareWindow(fullscreen); mutex->Lock(); condition->Signal(); @@ -1203,10 +1208,8 @@ namespace Nz if (!winHandle) return; - NazaraNotice("In"); while (window->m_threadActive) window->ProcessEvents(true); - NazaraNotice("Out"); DestroyWindow(winHandle); } diff --git a/src/Nazara/Utility/Win32/WindowImpl.hpp b/src/Nazara/Utility/Win32/WindowImpl.hpp index a8a764319..bb718738a 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.hpp +++ b/src/Nazara/Utility/Win32/WindowImpl.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -82,11 +83,12 @@ namespace Nz private: bool HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam); + void PrepareWindow(bool fullscreen); static Keyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags); static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam); static UInt32 RetrieveStyle(HWND window); - static void WindowThread(HWND* handle, DWORD styleEx, const String& title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, WindowImpl* window, Mutex* mutex, ConditionVariable* condition); + static void WindowThread(HWND* handle, DWORD styleEx, const String& title, DWORD style, bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition); HCURSOR m_cursor; HWND m_handle; diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index b7f519ce6..803badb85 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -109,6 +109,7 @@ namespace Nz { Destroy(); + m_asyncWindow = false; m_impl = new WindowImpl(this); if (!m_impl->Create(handle)) { @@ -343,7 +344,7 @@ namespace Nz LockGuard eventLock(m_eventMutex); for (const WindowEvent& event : m_pendingEvents) - PushEvent(event); + HandleEvent(event); m_pendingEvents.clear(); } @@ -395,7 +396,6 @@ namespace Nz if (!listener) { // Empty the event queue - LockGuard lock(m_eventMutex); while (!m_events.empty()) m_events.pop(); }