Window: Fix Threaded flag, seems to be working fine now

This commit is contained in:
Jérôme Leclercq 2016-11-07 10:51:23 +01:00
parent 94631e1a01
commit ffe748b8c3
3 changed files with 35 additions and 30 deletions

View File

@ -148,6 +148,11 @@ namespace Nz
m_callback = 0; m_callback = 0;
m_eventListener = true;
m_ownsWindow = true;
m_sizemove = false;
m_style = style;
if (async) if (async)
{ {
Mutex mutex; Mutex mutex;
@ -156,7 +161,7 @@ namespace Nz
// On attend que la fenêtre soit créée // On attend que la fenêtre soit créée
mutex.Lock(); 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); condition.Wait(&mutex);
mutex.Unlock(); mutex.Unlock();
} }
@ -169,24 +174,8 @@ namespace Nz
return false; return false;
} }
if (fullscreen) if (!async)
{ PrepareWindow(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);
return true; return true;
} }
@ -321,11 +310,7 @@ namespace Nz
if (m_ownsWindow) if (m_ownsWindow)
{ {
if (block) if (block)
{
NazaraNotice("WaitMessage");
WaitMessage(); WaitMessage();
NazaraNotice("~WaitMessage");
}
MSG message; MSG message;
while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE)) while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE))
@ -977,6 +962,23 @@ namespace Nz
return false; 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() bool WindowImpl::Initialize()
{ {
// Nous devons faire un type Unicode pour que la fenêtre le soit également // Nous devons faire un type Unicode pour que la fenêtre le soit également
@ -1191,10 +1193,13 @@ namespace Nz
return style; 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; 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(); mutex->Lock();
condition->Signal(); condition->Signal();
@ -1203,10 +1208,8 @@ namespace Nz
if (!winHandle) if (!winHandle)
return; return;
NazaraNotice("In");
while (window->m_threadActive) while (window->m_threadActive)
window->ProcessEvents(true); window->ProcessEvents(true);
NazaraNotice("Out");
DestroyWindow(winHandle); DestroyWindow(winHandle);
} }

View File

@ -12,6 +12,7 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Core/Thread.hpp> #include <Nazara/Core/Thread.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Config.hpp> #include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Keyboard.hpp> #include <Nazara/Utility/Keyboard.hpp>
@ -82,11 +83,12 @@ namespace Nz
private: private:
bool HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam); bool HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
void PrepareWindow(bool fullscreen);
static Keyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags); static Keyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags);
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
static UInt32 RetrieveStyle(HWND window); 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; HCURSOR m_cursor;
HWND m_handle; HWND m_handle;

View File

@ -109,6 +109,7 @@ namespace Nz
{ {
Destroy(); Destroy();
m_asyncWindow = false;
m_impl = new WindowImpl(this); m_impl = new WindowImpl(this);
if (!m_impl->Create(handle)) if (!m_impl->Create(handle))
{ {
@ -343,7 +344,7 @@ namespace Nz
LockGuard eventLock(m_eventMutex); LockGuard eventLock(m_eventMutex);
for (const WindowEvent& event : m_pendingEvents) for (const WindowEvent& event : m_pendingEvents)
PushEvent(event); HandleEvent(event);
m_pendingEvents.clear(); m_pendingEvents.clear();
} }
@ -395,7 +396,6 @@ namespace Nz
if (!listener) if (!listener)
{ {
// Empty the event queue // Empty the event queue
LockGuard lock(m_eventMutex);
while (!m_events.empty()) while (!m_events.empty())
m_events.pop(); m_events.pop();
} }