Added NzWindow::SetCursor
Moved window flags to global scope (nzWindowStyle) Removed NzWindow::ShowMouseCursor (superseded by SetCursor)
This commit is contained in:
parent
71cf7876c5
commit
d851e35a56
|
|
@ -24,14 +24,14 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
|
|||
{
|
||||
public:
|
||||
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());
|
||||
virtual ~NzRenderWindow();
|
||||
|
||||
bool CopyToImage(NzImage* image); ///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());
|
||||
|
||||
void Display();
|
||||
|
|
|
|||
|
|
@ -27,32 +27,55 @@
|
|||
class NzUtility;
|
||||
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
|
||||
{
|
||||
friend class NzUtility;
|
||||
friend class NzWindowImpl;
|
||||
|
||||
public:
|
||||
enum Style
|
||||
{
|
||||
None = 0x0,
|
||||
Fullscreen = 0x1,
|
||||
|
||||
Closable = 0x2,
|
||||
Resizable = 0x4,
|
||||
Titlebar = 0x8,
|
||||
|
||||
Default = Closable | Resizable | Titlebar
|
||||
};
|
||||
|
||||
NzWindow();
|
||||
NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = Default);
|
||||
NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default);
|
||||
NzWindow(NzWindowHandle handle);
|
||||
virtual ~NzWindow();
|
||||
|
||||
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);
|
||||
|
||||
void EnableKeyRepeat(bool enable);
|
||||
|
|
@ -73,6 +96,7 @@ class NAZARA_API NzWindow : NzNonCopyable
|
|||
|
||||
bool PollEvent(NzEvent* event);
|
||||
|
||||
void SetCursor(nzWindowCursor cursor);
|
||||
void SetEventListener(bool listener);
|
||||
void SetFocus();
|
||||
void SetMaximumSize(const NzVector2i& maxSize);
|
||||
|
|
@ -86,8 +110,6 @@ class NAZARA_API NzWindow : NzNonCopyable
|
|||
void SetTitle(const NzString& title);
|
||||
void SetVisible(bool visible);
|
||||
|
||||
void ShowMouseCursor(bool show);
|
||||
|
||||
void StayOnTop(bool stayOnTop);
|
||||
|
||||
bool WaitEvent(NzEvent* event);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue