Optimized WindowImpl::Get[Height|Position|Size|Width]
Former-commit-id: e482fc04a632e5338601627f7dd7c6f0fe18d135
This commit is contained in:
parent
b9b572c60c
commit
1e6fe40707
|
|
@ -137,6 +137,9 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
|
||||||
m_handle = CreateWindowExW(win32StyleEx, className, wtitle.get(), win32Style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), this);
|
m_handle = CreateWindowExW(win32StyleEx, className, wtitle.get(), win32Style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!m_handle)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
{
|
{
|
||||||
SetForegroundWindow(m_handle);
|
SetForegroundWindow(m_handle);
|
||||||
|
|
@ -150,7 +153,15 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
|
||||||
#endif
|
#endif
|
||||||
m_style = style;
|
m_style = style;
|
||||||
|
|
||||||
return m_handle != nullptr;
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzWindowImpl::Create(NzWindowHandle handle)
|
bool NzWindowImpl::Create(NzWindowHandle handle)
|
||||||
|
|
@ -170,6 +181,13 @@ bool NzWindowImpl::Create(NzWindowHandle handle)
|
||||||
#endif
|
#endif
|
||||||
m_style = RetrieveStyle(m_handle);
|
m_style = RetrieveStyle(m_handle);
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,23 +230,17 @@ NzWindowHandle NzWindowImpl::GetHandle() const
|
||||||
|
|
||||||
unsigned int NzWindowImpl::GetHeight() const
|
unsigned int NzWindowImpl::GetHeight() const
|
||||||
{
|
{
|
||||||
RECT rect;
|
return m_size.y;
|
||||||
GetClientRect(m_handle, &rect);
|
|
||||||
return rect.bottom-rect.top;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NzVector2i NzWindowImpl::GetPosition() const
|
NzVector2i NzWindowImpl::GetPosition() const
|
||||||
{
|
{
|
||||||
RECT rect;
|
return m_position;
|
||||||
GetWindowRect(m_handle, &rect);
|
|
||||||
return NzVector2i(rect.left, rect.top);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NzVector2ui NzWindowImpl::GetSize() const
|
NzVector2ui NzWindowImpl::GetSize() const
|
||||||
{
|
{
|
||||||
RECT rect;
|
return m_size;
|
||||||
GetClientRect(m_handle, &rect);
|
|
||||||
return NzVector2ui(rect.right-rect.left, rect.bottom-rect.top);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nzUInt32 NzWindowImpl::GetStyle() const
|
nzUInt32 NzWindowImpl::GetStyle() const
|
||||||
|
|
@ -252,9 +264,7 @@ NzString NzWindowImpl::GetTitle() const
|
||||||
|
|
||||||
unsigned int NzWindowImpl::GetWidth() const
|
unsigned int NzWindowImpl::GetWidth() const
|
||||||
{
|
{
|
||||||
RECT rect;
|
return m_size.x;
|
||||||
GetClientRect(m_handle, &rect);
|
|
||||||
return rect.right-rect.left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzWindowImpl::HasFocus() const
|
bool NzWindowImpl::HasFocus() const
|
||||||
|
|
@ -549,7 +559,11 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||||
m_sizemove = false;
|
m_sizemove = false;
|
||||||
|
|
||||||
// On vérifie ce qui a changé
|
// On vérifie ce qui a changé
|
||||||
NzVector2i position = GetPosition();
|
RECT clientRect, windowRect;
|
||||||
|
GetClientRect(m_handle, &clientRect);
|
||||||
|
GetWindowRect(m_handle, &windowRect);
|
||||||
|
|
||||||
|
NzVector2i position(windowRect.left, windowRect.top);
|
||||||
if (m_position != position)
|
if (m_position != position)
|
||||||
{
|
{
|
||||||
m_position = position;
|
m_position = position;
|
||||||
|
|
@ -561,7 +575,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||||
m_parent->PushEvent(event);
|
m_parent->PushEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
NzVector2ui size = GetSize();
|
NzVector2ui size(clientRect.right-clientRect.left, clientRect.bottom-clientRect.top);
|
||||||
if (m_size != size)
|
if (m_size != size)
|
||||||
{
|
{
|
||||||
m_size = size;
|
m_size = size;
|
||||||
|
|
@ -797,12 +811,13 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||||
|
|
||||||
case WM_MOVE:
|
case WM_MOVE:
|
||||||
{
|
{
|
||||||
NzVector2i position = GetPosition();
|
RECT windowRect;
|
||||||
|
GetWindowRect(m_handle, &windowRect);
|
||||||
|
|
||||||
NzEvent event;
|
NzEvent event;
|
||||||
event.type = nzEventType_Moved;
|
event.type = nzEventType_Moved;
|
||||||
event.position.x = position.x;
|
event.position.x = windowRect.left;
|
||||||
event.position.y = position.y;
|
event.position.y = windowRect.top;
|
||||||
m_parent->PushEvent(event);
|
m_parent->PushEvent(event);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -865,13 +880,14 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
||||||
if (!m_sizemove && wParam != SIZE_MINIMIZED)
|
if (!m_sizemove && wParam != SIZE_MINIMIZED)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
NzVector2ui size = GetSize(); // On récupère uniquement la taille de la zone client
|
RECT rect;
|
||||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
GetClientRect(m_handle, &rect);
|
||||||
|
|
||||||
|
NzVector2ui size(rect.right-rect.left, rect.bottom-rect.top); // On récupère uniquement la taille de la zone client
|
||||||
if (m_size == size)
|
if (m_size == size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
m_size = size;
|
m_size = size;
|
||||||
#endif
|
|
||||||
|
|
||||||
NzEvent event;
|
NzEvent event;
|
||||||
event.type = nzEventType_Resized;
|
event.type = nzEventType_Resized;
|
||||||
|
|
@ -1185,12 +1201,16 @@ nzUInt32 NzWindowImpl::RetrieveStyle(HWND handle)
|
||||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||||
void NzWindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzConditionVariable* condition)
|
void NzWindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzConditionVariable* condition)
|
||||||
{
|
{
|
||||||
*handle = CreateWindowExW(styleEx, className, title, style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), window);
|
HWND& winHandle = *handle;
|
||||||
|
winHandle = CreateWindowExW(styleEx, className, title, style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), window);
|
||||||
|
|
||||||
mutex->Lock();
|
mutex->Lock();
|
||||||
condition->Signal();
|
condition->Signal();
|
||||||
mutex->Unlock(); // mutex et condition sont considérés invalides à partir d'ici
|
mutex->Unlock(); // mutex et condition sont considérés invalides à partir d'ici
|
||||||
|
|
||||||
|
if (!winHandle)
|
||||||
|
return;
|
||||||
|
|
||||||
while (window->m_threadActive)
|
while (window->m_threadActive)
|
||||||
window->ProcessEvents(true);
|
window->ProcessEvents(true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,9 @@ class NzWindowImpl : NzNonCopyable
|
||||||
NzVector2i m_maxSize;
|
NzVector2i m_maxSize;
|
||||||
NzVector2i m_minSize;
|
NzVector2i m_minSize;
|
||||||
NzVector2i m_mousePos;
|
NzVector2i m_mousePos;
|
||||||
#if !NAZARA_UTILITY_THREADED_WINDOW
|
|
||||||
NzVector2i m_position;
|
NzVector2i m_position;
|
||||||
NzVector2ui m_size;
|
NzVector2ui m_size;
|
||||||
#else
|
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||||
NzThread* m_thread;
|
NzThread* m_thread;
|
||||||
#endif
|
#endif
|
||||||
NzWindow* m_parent;
|
NzWindow* m_parent;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue