Added NzWindow::SetCursor

Moved window flags to global scope (nzWindowStyle)
Removed NzWindow::ShowMouseCursor (superseded by SetCursor)
This commit is contained in:
Lynix
2012-06-23 15:02:17 +02:00
parent 71cf7876c5
commit d851e35a56
5 changed files with 126 additions and 49 deletions

View File

@@ -17,8 +17,8 @@
#include <Nazara/Utility/Debug.hpp>
#ifdef _WIN64
#define GWL_USERDATA GWLP_USERDATA
#define GCL_HCURSOR GCLP_HCURSOR
#define GWL_USERDATA GWLP_USERDATA
#endif
// N'est pas définit avec MinGW apparemment
@@ -72,7 +72,7 @@ void NzWindowImpl::Close()
bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
{
bool fullscreen = (style & NzWindow::Fullscreen) != 0;
bool fullscreen = (style & nzWindowStyle_Fullscreen) != 0;
DWORD win32Style, win32StyleEx;
unsigned int x, y;
unsigned int width = mode.width;
@@ -109,13 +109,13 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
else
{
win32Style = WS_VISIBLE;
if (style & NzWindow::Titlebar)
if (style & nzWindowStyle_Titlebar)
{
win32Style |= WS_CAPTION | WS_MINIMIZEBOX;
if (style & NzWindow::Closable)
if (style & nzWindowStyle_Closable)
win32Style |= WS_SYSMENU;
if (style & NzWindow::Resizable)
if (style & nzWindowStyle_Resizable)
win32Style |= WS_MAXIMIZEBOX | WS_SIZEBOX;
}
else
@@ -272,6 +272,74 @@ bool NzWindowImpl::IsVisible() const
return IsWindowVisible(m_handle);
}
void NzWindowImpl::SetCursor(nzWindowCursor cursor)
{
// Pas besoin de libérer le curseur par la suite s'il est partagé
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx
switch (cursor)
{
case nzWindowCursor_Crosshair:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_CROSS, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_Default:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_Hand:
case nzWindowCursor_Pointer:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_HAND, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_Help:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_HELP, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_Move:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZEALL, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_None:
m_cursor = nullptr;
break;
case nzWindowCursor_Progress:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_APPSTARTING, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_ResizeN:
case nzWindowCursor_ResizeS:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZENS, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_ResizeNW:
case nzWindowCursor_ResizeSE:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZENESW, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_ResizeNE:
case nzWindowCursor_ResizeSW:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZENWSE, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_ResizeE:
case nzWindowCursor_ResizeW:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_SIZEWE, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_Text:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_IBEAM, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
case nzWindowCursor_Wait:
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, IDC_WAIT, IMAGE_CURSOR, 0, 0, LR_SHARED));
break;
}
::SetCursor(m_cursor);
}
void NzWindowImpl::SetEventListener(bool listener)
{
if (m_ownsWindow)
@@ -355,19 +423,6 @@ void NzWindowImpl::SetVisible(bool visible)
ShowWindow(m_handle, (visible) ? SW_SHOW : SW_HIDE);
}
void NzWindowImpl::ShowMouseCursor(bool show)
{
// Pas besoin de libérer le curseur par la suite s'il est partagé
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx
if (show)
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, MAKEINTRESOURCE(OCR_NORMAL), IMAGE_CURSOR, 0, 0, LR_SHARED));
else
m_cursor = nullptr;
SetCursor(m_cursor);
}
void NzWindowImpl::StayOnTop(bool stayOnTop)
{
SetWindowPos(m_handle, (stayOnTop) ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
@@ -390,7 +445,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
case WM_SETCURSOR:
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx
if (LOWORD(lParam) == HTCLIENT)
SetCursor(m_cursor);
::SetCursor(m_cursor);
break;

View File

@@ -56,6 +56,7 @@ class NzWindowImpl : NzNonCopyable
bool IsMinimized() const;
bool IsVisible() const;
void SetCursor(nzWindowCursor cursor);
void SetEventListener(bool listener);
void SetFocus();
void SetMaximumSize(int width, int height);
@@ -65,7 +66,6 @@ class NzWindowImpl : NzNonCopyable
void SetTitle(const NzString& title);
void SetVisible(bool visible);
void ShowMouseCursor(bool show);
void StayOnTop(bool stayOnTop);
static bool Initialize();

View File

@@ -103,12 +103,12 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
Close();
// Inspiré du code de la SFML par Laurent Gomila
if (style & Fullscreen)
if (style & nzWindowStyle_Fullscreen)
{
if (fullscreenWindow)
{
NazaraError("Window (" + NzString::Pointer(fullscreenWindow) + ") already in fullscreen mode");
style &= ~Fullscreen;
style &= ~nzWindowStyle_Fullscreen;
}
else
{
@@ -121,8 +121,8 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
fullscreenWindow = this;
}
}
else if (style & Closable || style & Resizable)
style |= Titlebar;
else if (style & nzWindowStyle_Closable || style & nzWindowStyle_Resizable)
style |= nzWindowStyle_Titlebar;
m_impl = new NzWindowImpl(this);
if (!m_impl->Create(mode, title, style))
@@ -147,10 +147,10 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
m_impl->EnableKeyRepeat(true);
m_impl->EnableSmoothScrolling(false);
m_impl->SetCursor(nzWindowCursor_Default);
m_impl->SetMaximumSize(-1, -1);
m_impl->SetMinimumSize(-1, -1);
m_impl->SetVisible(true);
m_impl->ShowMouseCursor(true);
if (opened)
m_impl->SetPosition(position.x, position.y);
@@ -299,6 +299,12 @@ bool NzWindow::PollEvent(NzEvent* event)
return false;
}
void NzWindow::SetCursor(nzWindowCursor cursor)
{
if (m_impl)
m_impl->SetCursor(cursor);
}
void NzWindow::SetEventListener(bool listener)
{
if (!m_impl)
@@ -391,12 +397,6 @@ void NzWindow::SetVisible(bool visible)
m_impl->SetVisible(visible);
}
void NzWindow::ShowMouseCursor(bool show)
{
if (m_impl)
m_impl->ShowMouseCursor(show);
}
void NzWindow::StayOnTop(bool stayOnTop)
{
if (m_impl)