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

@ -24,14 +24,14 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
{ {
public: public:
NzRenderWindow(); NzRenderWindow();
NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = NzWindow::Default, const NzContextParameters& parameters = NzContextParameters()); NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters());
NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
virtual ~NzRenderWindow(); virtual ~NzRenderWindow();
bool CopyToImage(NzImage* image); ///TODO: Const bool CopyToImage(NzImage* image); ///TODO: Const
bool CopyToTexture(NzTexture* texture); ///TODO: Const bool CopyToTexture(NzTexture* texture); ///TODO: Const
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = NzWindow::Default, const NzContextParameters& parameters = NzContextParameters()); bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters());
bool Create(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); bool Create(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
void Display(); void Display();

View File

@ -27,32 +27,55 @@
class NzUtility; class NzUtility;
class NzWindowImpl; class NzWindowImpl;
enum nzWindowCursor
{
nzWindowCursor_None,
nzWindowCursor_Default,
nzWindowCursor_Crosshair,
nzWindowCursor_Hand,
nzWindowCursor_Help,
nzWindowCursor_Move,
nzWindowCursor_Pointer,
nzWindowCursor_Progress,
nzWindowCursor_ResizeE,
nzWindowCursor_ResizeN,
nzWindowCursor_ResizeNE,
nzWindowCursor_ResizeNW,
nzWindowCursor_ResizeS,
nzWindowCursor_ResizeSE,
nzWindowCursor_ResizeSW,
nzWindowCursor_ResizeW,
nzWindowCursor_Text,
nzWindowCursor_Wait
};
enum nzWindowStyle
{
nzWindowStyle_None = 0x0,
nzWindowStyle_Fullscreen = 0x1,
nzWindowStyle_Closable = 0x2,
nzWindowStyle_Resizable = 0x4,
nzWindowStyle_Titlebar = 0x4,
nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar
};
class NAZARA_API NzWindow : NzNonCopyable class NAZARA_API NzWindow : NzNonCopyable
{ {
friend class NzUtility; friend class NzUtility;
friend class NzWindowImpl; friend class NzWindowImpl;
public: public:
enum Style
{
None = 0x0,
Fullscreen = 0x1,
Closable = 0x2,
Resizable = 0x4,
Titlebar = 0x8,
Default = Closable | Resizable | Titlebar
};
NzWindow(); NzWindow();
NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = Default); NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default);
NzWindow(NzWindowHandle handle); NzWindow(NzWindowHandle handle);
virtual ~NzWindow(); virtual ~NzWindow();
void Close(); void Close();
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = Default); bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default);
bool Create(NzWindowHandle handle); bool Create(NzWindowHandle handle);
void EnableKeyRepeat(bool enable); void EnableKeyRepeat(bool enable);
@ -73,6 +96,7 @@ class NAZARA_API NzWindow : NzNonCopyable
bool PollEvent(NzEvent* event); bool PollEvent(NzEvent* event);
void SetCursor(nzWindowCursor cursor);
void SetEventListener(bool listener); void SetEventListener(bool listener);
void SetFocus(); void SetFocus();
void SetMaximumSize(const NzVector2i& maxSize); void SetMaximumSize(const NzVector2i& maxSize);
@ -86,8 +110,6 @@ class NAZARA_API NzWindow : NzNonCopyable
void SetTitle(const NzString& title); void SetTitle(const NzString& title);
void SetVisible(bool visible); void SetVisible(bool visible);
void ShowMouseCursor(bool show);
void StayOnTop(bool stayOnTop); void StayOnTop(bool stayOnTop);
bool WaitEvent(NzEvent* event); bool WaitEvent(NzEvent* event);

View File

@ -17,8 +17,8 @@
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
#ifdef _WIN64 #ifdef _WIN64
#define GWL_USERDATA GWLP_USERDATA
#define GCL_HCURSOR GCLP_HCURSOR #define GCL_HCURSOR GCLP_HCURSOR
#define GWL_USERDATA GWLP_USERDATA
#endif #endif
// N'est pas définit avec MinGW apparemment // 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 NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
{ {
bool fullscreen = (style & NzWindow::Fullscreen) != 0; bool fullscreen = (style & nzWindowStyle_Fullscreen) != 0;
DWORD win32Style, win32StyleEx; DWORD win32Style, win32StyleEx;
unsigned int x, y; unsigned int x, y;
unsigned int width = mode.width; unsigned int width = mode.width;
@ -109,13 +109,13 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
else else
{ {
win32Style = WS_VISIBLE; win32Style = WS_VISIBLE;
if (style & NzWindow::Titlebar) if (style & nzWindowStyle_Titlebar)
{ {
win32Style |= WS_CAPTION | WS_MINIMIZEBOX; win32Style |= WS_CAPTION | WS_MINIMIZEBOX;
if (style & NzWindow::Closable) if (style & nzWindowStyle_Closable)
win32Style |= WS_SYSMENU; win32Style |= WS_SYSMENU;
if (style & NzWindow::Resizable) if (style & nzWindowStyle_Resizable)
win32Style |= WS_MAXIMIZEBOX | WS_SIZEBOX; win32Style |= WS_MAXIMIZEBOX | WS_SIZEBOX;
} }
else else
@ -272,6 +272,74 @@ bool NzWindowImpl::IsVisible() const
return IsWindowVisible(m_handle); 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) void NzWindowImpl::SetEventListener(bool listener)
{ {
if (m_ownsWindow) if (m_ownsWindow)
@ -355,19 +423,6 @@ void NzWindowImpl::SetVisible(bool visible)
ShowWindow(m_handle, (visible) ? SW_SHOW : SW_HIDE); 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) void NzWindowImpl::StayOnTop(bool stayOnTop)
{ {
SetWindowPos(m_handle, (stayOnTop) ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 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: case WM_SETCURSOR:
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx // http://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx
if (LOWORD(lParam) == HTCLIENT) if (LOWORD(lParam) == HTCLIENT)
SetCursor(m_cursor); ::SetCursor(m_cursor);
break; break;

View File

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

View File

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