Window's subsystem is now initialized by NzUtility
Optimized Image
This commit is contained in:
parent
f55cf96713
commit
7659fdf460
|
|
@ -24,10 +24,12 @@
|
|||
#include <Nazara/Core/ThreadCondition.hpp>
|
||||
#endif
|
||||
|
||||
class NzUtility;
|
||||
class NzWindowImpl;
|
||||
|
||||
class NAZARA_API NzWindow : NzNonCopyable
|
||||
{
|
||||
friend class NzUtility;
|
||||
friend class NzWindowImpl;
|
||||
|
||||
public:
|
||||
|
|
@ -99,6 +101,9 @@ class NAZARA_API NzWindow : NzNonCopyable
|
|||
private:
|
||||
void PushEvent(const NzEvent& event);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::queue<NzEvent> m_events;
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
NzMutex m_eventMutex;
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ bool NzImage::Update(const nzUInt8* pixels)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (IsCubemap())
|
||||
if (m_sharedImage->type == nzImageType_Cubemap)
|
||||
{
|
||||
NazaraError("Update is not designed for cubemaps, use UpdateFace instead");
|
||||
return false;
|
||||
|
|
@ -327,7 +327,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (IsCubemap())
|
||||
if (m_sharedImage->type == nzImageType_Cubemap)
|
||||
{
|
||||
NazaraError("Update is not designed for cubemaps, use UpdateFace instead");
|
||||
return false;
|
||||
|
|
@ -380,7 +380,7 @@ bool NzImage::UpdateFace(nzCubemapFace face, const nzUInt8* pixels)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!IsCubemap())
|
||||
if (m_sharedImage->type != nzImageType_Cubemap)
|
||||
{
|
||||
NazaraError("Update is only designed for cubemaps, use Update instead");
|
||||
return false;
|
||||
|
|
@ -410,7 +410,7 @@ bool NzImage::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRect
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!IsCubemap())
|
||||
if (m_sharedImage->type != nzImageType_Cubemap)
|
||||
{
|
||||
NazaraError("Update is only designed for cubemaps, use Update instead");
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -14,22 +14,22 @@ namespace
|
|||
{
|
||||
inline nzUInt8 c4to8(nzUInt8 c)
|
||||
{
|
||||
return c * 255.f/15.f;
|
||||
return c * (255.f/15.f);
|
||||
}
|
||||
|
||||
inline nzUInt8 c5to8(nzUInt8 c)
|
||||
{
|
||||
return c * 255.f/31.f;
|
||||
return c * (255.f/31.f);
|
||||
}
|
||||
|
||||
inline nzUInt8 c8to4(nzUInt8 c)
|
||||
{
|
||||
return c * 15.f/255.f;
|
||||
return c * (15.f/255.f);
|
||||
}
|
||||
|
||||
inline nzUInt8 c8to5(nzUInt8 c)
|
||||
{
|
||||
return c * 31.f/255.f;
|
||||
return c * (31.f/255.f);
|
||||
}
|
||||
|
||||
template<nzPixelFormat from, nzPixelFormat to>
|
||||
|
|
@ -215,7 +215,7 @@ namespace
|
|||
*ptr++ = (static_cast<nzUInt16>(c8to5(start[2])) << 11) |
|
||||
(static_cast<nzUInt16>(c8to5(start[1])) << 6) |
|
||||
(static_cast<nzUInt16>(c8to5(start[0])) << 1) |
|
||||
((start[3] == 0xFF) ? 1 : 0);
|
||||
((start[3] == 0xFF) ? 1 : 0);
|
||||
|
||||
start += 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <Nazara/Utility/Loaders/PCX.hpp>
|
||||
#include <Nazara/Utility/Loaders/STB.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzUtility::NzUtility()
|
||||
|
|
@ -36,6 +37,14 @@ bool NzUtility::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!NzWindow::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize window's system");
|
||||
NzPixelFormat::Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Loaders spécialisés
|
||||
NzLoaders_PCX_Register(); // Loader de fichiers .PCX (1, 4, 8, 24)
|
||||
|
||||
|
|
@ -60,6 +69,8 @@ void NzUtility::Uninitialize()
|
|||
NzLoaders_STB_Unregister();
|
||||
NzLoaders_PCX_Unregister();
|
||||
|
||||
NzWindow::Uninitialize();
|
||||
|
||||
NzPixelFormat::Uninitialize();
|
||||
|
||||
s_initialized = false;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ namespace
|
|||
{
|
||||
const wchar_t* className = L"Nazara Window";
|
||||
NzWindowImpl* fullscreenWindow = nullptr;
|
||||
unsigned int windowCount = 0;
|
||||
}
|
||||
|
||||
NzWindowImpl::NzWindowImpl(NzWindow* parent) :
|
||||
|
|
@ -62,19 +61,10 @@ void NzWindowImpl::Close()
|
|||
}
|
||||
else
|
||||
SetEventListener(false);
|
||||
|
||||
if (--windowCount == 0)
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 style)
|
||||
{
|
||||
if (windowCount++ == 0 && !Initialize())
|
||||
{
|
||||
NazaraError("Unable to initialize window implementation");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool fullscreen = (style & NzWindow::Fullscreen) != 0;
|
||||
DWORD win32Style, win32StyleEx;
|
||||
unsigned int x, y;
|
||||
|
|
@ -165,15 +155,7 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
|
|||
m_eventListener = true;
|
||||
m_ownsWindow = true;
|
||||
|
||||
if (m_handle != nullptr)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
if (--windowCount == 0)
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
return m_handle != nullptr;
|
||||
}
|
||||
|
||||
bool NzWindowImpl::Create(NzWindowHandle handle)
|
||||
|
|
@ -776,6 +758,30 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA
|
|||
return false;
|
||||
}
|
||||
|
||||
bool NzWindowImpl::Initialize()
|
||||
{
|
||||
// Nous devons faire un type Unicode pour que la fenêtre le soit également
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633574(v=vs.85).aspx
|
||||
WNDCLASSW windowClass;
|
||||
windowClass.cbClsExtra = 0;
|
||||
windowClass.cbWndExtra = 0;
|
||||
windowClass.hbrBackground = nullptr;
|
||||
windowClass.hCursor = nullptr; // Le curseur est définit dynamiquement
|
||||
windowClass.hIcon = nullptr; // L'icône est définie dynamiquement
|
||||
windowClass.hInstance = GetModuleHandle(nullptr);
|
||||
windowClass.lpfnWndProc = MessageHandler;
|
||||
windowClass.lpszClassName = className;
|
||||
windowClass.lpszMenuName = nullptr;
|
||||
windowClass.style = CS_DBLCLKS; // Gestion du double-clic
|
||||
|
||||
return RegisterClassW(&windowClass);
|
||||
}
|
||||
|
||||
void NzWindowImpl::Uninitialize()
|
||||
{
|
||||
UnregisterClassW(className, GetModuleHandle(nullptr));
|
||||
}
|
||||
|
||||
LRESULT CALLBACK NzWindowImpl::MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
NzWindowImpl* me;
|
||||
|
|
@ -798,25 +804,6 @@ LRESULT CALLBACK NzWindowImpl::MessageHandler(HWND window, UINT message, WPARAM
|
|||
return DefWindowProcW(window, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool NzWindowImpl::Initialize()
|
||||
{
|
||||
// Nous devons faire un type Unicode pour que la fenêtre le soit également
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633574(v=vs.85).aspx
|
||||
WNDCLASSW windowClass;
|
||||
windowClass.cbClsExtra = 0;
|
||||
windowClass.cbWndExtra = 0;
|
||||
windowClass.hbrBackground = nullptr;
|
||||
windowClass.hCursor = nullptr; // Le curseur est définit dynamiquement
|
||||
windowClass.hIcon = nullptr; // L'icône est définie dynamiquement
|
||||
windowClass.hInstance = GetModuleHandle(nullptr);
|
||||
windowClass.lpfnWndProc = MessageHandler;
|
||||
windowClass.lpszClassName = className;
|
||||
windowClass.lpszMenuName = nullptr;
|
||||
windowClass.style = CS_DBLCLKS; // Gestion du double-clic
|
||||
|
||||
return RegisterClassW(&windowClass);
|
||||
}
|
||||
|
||||
NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
||||
{
|
||||
switch (key)
|
||||
|
|
@ -949,11 +936,6 @@ NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
|||
}
|
||||
}
|
||||
|
||||
void NzWindowImpl::Uninitialize()
|
||||
{
|
||||
UnregisterClassW(className, GetModuleHandle(nullptr));
|
||||
}
|
||||
|
||||
#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, NzThreadCondition* condition)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ class NzMutex;
|
|||
class NzThread;
|
||||
class NzThreadCondition;
|
||||
#endif
|
||||
class NzWindow;
|
||||
|
||||
#undef IsMinimized // Conflit avec la méthode du même nom
|
||||
|
||||
|
|
@ -67,13 +68,14 @@ class NzWindowImpl : NzNonCopyable
|
|||
void ShowMouseCursor(bool show);
|
||||
void StayOnTop(bool stayOnTop);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
bool HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
static bool Initialize();
|
||||
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
static NzKeyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags);
|
||||
static void Uninitialize();
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
static void 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, NzThreadCondition* condition);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -473,3 +473,13 @@ void NzWindow::PushEvent(const NzEvent& event)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool NzWindow::Initialize()
|
||||
{
|
||||
return NzWindowImpl::Initialize();
|
||||
}
|
||||
|
||||
void NzWindow::Uninitialize()
|
||||
{
|
||||
NzWindowImpl::Uninitialize();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue