Upgrade Platform
This commit is contained in:
@@ -3,24 +3,43 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Platform/Cursor.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Platform/SDL2/CursorImpl.hpp>
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Cursor::Cursor() = default;
|
||||
|
||||
Cursor::Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder)
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
Create(cursor, hotSpot, placeholder);
|
||||
}
|
||||
|
||||
Cursor::Cursor(SystemCursor systemCursor)
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
Create(systemCursor);
|
||||
}
|
||||
|
||||
Cursor::Cursor(Cursor&&) noexcept = default;
|
||||
Cursor::~Cursor() = default;
|
||||
|
||||
bool Cursor::Create(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
std::unique_ptr<CursorImpl> impl(new CursorImpl);
|
||||
if (!impl->Create(cursor, hotSpot.x, hotSpot.y))
|
||||
try
|
||||
{
|
||||
NazaraError("Failed to create cursor implementation");
|
||||
m_impl = std::make_unique<CursorImpl>(cursor, hotSpot);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError(e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_cursorImage = cursor;
|
||||
m_impl = impl.release();
|
||||
m_systemCursor = placeholder;
|
||||
|
||||
return true;
|
||||
@@ -28,52 +47,46 @@ namespace Nz
|
||||
|
||||
void Cursor::Destroy()
|
||||
{
|
||||
m_cursorImage.Destroy();
|
||||
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Destroy();
|
||||
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
m_impl.reset();
|
||||
}
|
||||
|
||||
bool Cursor::Create(SystemCursor cursor)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
std::unique_ptr<CursorImpl> impl(new CursorImpl);
|
||||
if (!impl->Create(cursor))
|
||||
try
|
||||
{
|
||||
NazaraError("Failed to create cursor implementation");
|
||||
m_impl = std::make_unique<CursorImpl>(cursor);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError(e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_impl = impl.release();
|
||||
m_systemCursor = cursor;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Cursor& Cursor::operator=(Cursor&&) noexcept = default;
|
||||
|
||||
bool Cursor::Initialize()
|
||||
{
|
||||
if (!CursorImpl::Initialize())
|
||||
return false;
|
||||
|
||||
for (std::size_t i = 0; i <= SystemCursor_Max; ++i)
|
||||
s_systemCursors[i].Create(static_cast<SystemCursor>(i));
|
||||
for (std::size_t i = 0; i < SystemCursorCount; ++i)
|
||||
{
|
||||
s_systemCursors[i] = std::make_shared<Cursor>();
|
||||
s_systemCursors[i]->Create(static_cast<SystemCursor>(i));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Cursor::Uninitialize()
|
||||
{
|
||||
for (Cursor& cursor : s_systemCursors)
|
||||
cursor.Destroy();
|
||||
|
||||
CursorImpl::Uninitialize();
|
||||
for (std::shared_ptr<Cursor>& cursor : s_systemCursors)
|
||||
cursor.reset();
|
||||
}
|
||||
|
||||
std::array<Cursor, SystemCursor_Max + 1> Cursor::s_systemCursors;
|
||||
std::array<std::shared_ptr<Cursor>, SystemCursorCount> Cursor::s_systemCursors;
|
||||
}
|
||||
|
||||
@@ -8,30 +8,38 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Icon::Icon() = default;
|
||||
|
||||
Icon::Icon(const Image& icon)
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
Create(icon);
|
||||
}
|
||||
|
||||
Icon::Icon(Icon&&) noexcept = default;
|
||||
Icon::~Icon() = default;
|
||||
|
||||
bool Icon::Create(const Image& icon)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
std::unique_ptr<IconImpl> impl(new IconImpl);
|
||||
if (!impl->Create(icon))
|
||||
try
|
||||
{
|
||||
NazaraError("Failed to create icon implementation");
|
||||
m_impl = std::make_unique<IconImpl>(icon);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError(e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_impl = impl.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Icon::Destroy()
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Destroy();
|
||||
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
m_impl.reset();
|
||||
}
|
||||
|
||||
Icon& Icon::operator=(Icon&&) noexcept = default;
|
||||
}
|
||||
|
||||
@@ -2,67 +2,87 @@
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
#include <Nazara/Platform/SDL2/CursorImpl.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <array>
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
bool CursorImpl::Create(const Image& cursor, int hotSpotX, int hotSpotY)
|
||||
namespace
|
||||
{
|
||||
m_iconImage = cursor;
|
||||
if (!m_iconImage.Convert(PixelFormat_BGRA8))
|
||||
std::array<SDL_SystemCursor, SystemCursorCount> s_systemCursorIds =
|
||||
{
|
||||
NazaraError("Failed to convert icon to BGRA8");
|
||||
return false;
|
||||
}
|
||||
SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor::Crosshair
|
||||
SDL_SYSTEM_CURSOR_ARROW, // SystemCursor::Default
|
||||
SDL_SYSTEM_CURSOR_HAND, // SystemCursor::Hand
|
||||
SDL_SYSTEM_CURSOR_ARROW, // SystemCursor::Help
|
||||
SDL_SYSTEM_CURSOR_SIZEALL, // SystemCursor::Move
|
||||
SDL_NUM_SYSTEM_CURSORS, // SystemCursor::None
|
||||
SDL_SYSTEM_CURSOR_HAND, // SystemCursor::Pointer
|
||||
SDL_SYSTEM_CURSOR_WAITARROW, // SystemCursor::Progress
|
||||
SDL_SYSTEM_CURSOR_SIZEWE, // SystemCursor::ResizeE
|
||||
SDL_SYSTEM_CURSOR_SIZENS, // SystemCursor::ResizeN
|
||||
SDL_SYSTEM_CURSOR_SIZENESW, // SystemCursor::ResizeNE
|
||||
SDL_SYSTEM_CURSOR_SIZENWSE, // SystemCursor::ResizeNW
|
||||
SDL_SYSTEM_CURSOR_SIZENS, // SystemCursor::ResizeS
|
||||
SDL_SYSTEM_CURSOR_SIZENWSE, // SystemCursor::ResizeSE
|
||||
SDL_SYSTEM_CURSOR_SIZENESW, // SystemCursor::ResizeSW
|
||||
SDL_SYSTEM_CURSOR_SIZEWE, // SystemCursor::ResizeW
|
||||
SDL_SYSTEM_CURSOR_IBEAM, // SystemCursor::Text
|
||||
SDL_SYSTEM_CURSOR_WAIT // SystemCursor::Wait
|
||||
};
|
||||
|
||||
m_icon = SDL_CreateRGBSurfaceWithFormatFrom(
|
||||
m_iconImage.GetPixels(),
|
||||
m_iconImage.GetWidth(),
|
||||
m_iconImage.GetHeight(),
|
||||
static_assert(SystemCursorCount == 18, "System cursor array is incomplete");
|
||||
}
|
||||
|
||||
CursorImpl::CursorImpl(const Image& cursor, const Vector2i& hotSpot)
|
||||
{
|
||||
ErrorFlags errFlags(ErrorFlag_ThrowException);
|
||||
|
||||
m_cursorImage = cursor;
|
||||
if (!m_cursorImage.Convert(PixelFormat::BGRA8))
|
||||
NazaraError("Failed to convert icon to BGRA8");
|
||||
|
||||
m_surface = SDL_CreateRGBSurfaceWithFormatFrom(
|
||||
m_cursorImage.GetPixels(),
|
||||
m_cursorImage.GetWidth(),
|
||||
m_cursorImage.GetHeight(),
|
||||
32,
|
||||
4 * m_iconImage.GetWidth(),
|
||||
4 * m_cursorImage.GetWidth(),
|
||||
SDL_PIXELFORMAT_BGRA32
|
||||
);
|
||||
|
||||
if (!m_icon)
|
||||
{
|
||||
NazaraError(SDL_GetError());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_cursor = SDL_CreateColorCursor(m_icon, hotSpotX, hotSpotY);
|
||||
if (!m_surface)
|
||||
NazaraError("failed to create SDL Surface for cursor: " + std::string(SDL_GetError()));
|
||||
|
||||
m_cursor = SDL_CreateColorCursor(m_surface, hotSpot.x, hotSpot.y);
|
||||
if (!m_cursor)
|
||||
{
|
||||
NazaraError(SDL_GetError());
|
||||
if (m_surface) //< Just in case exceptions were disabled
|
||||
SDL_FreeSurface(m_surface);
|
||||
|
||||
return false;
|
||||
NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CursorImpl::Create(SystemCursor cursor)
|
||||
CursorImpl::CursorImpl(SystemCursor cursor)
|
||||
{
|
||||
if (cursor != SystemCursor_None)
|
||||
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]);
|
||||
else
|
||||
m_cursor = nullptr;
|
||||
ErrorFlags errFlags(ErrorFlag_ThrowException);
|
||||
|
||||
m_icon = nullptr;
|
||||
|
||||
return true;
|
||||
if (cursor != SystemCursor::None)
|
||||
{
|
||||
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[UnderlyingCast(cursor)]);
|
||||
if (!m_cursor)
|
||||
NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError()));
|
||||
}
|
||||
}
|
||||
|
||||
void CursorImpl::Destroy()
|
||||
CursorImpl::~CursorImpl()
|
||||
{
|
||||
if (m_icon)
|
||||
SDL_FreeSurface(m_icon);
|
||||
if (m_surface)
|
||||
SDL_FreeSurface(m_surface);
|
||||
|
||||
if (m_cursor)
|
||||
SDL_FreeCursor(m_cursor);
|
||||
@@ -72,37 +92,4 @@ namespace Nz
|
||||
{
|
||||
return m_cursor;
|
||||
}
|
||||
|
||||
bool CursorImpl::Initialize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CursorImpl::Uninitialize()
|
||||
{
|
||||
}
|
||||
|
||||
std::array<SDL_SystemCursor, SystemCursor_Max + 1> CursorImpl::s_systemCursorIds =
|
||||
{
|
||||
SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor_Crosshair
|
||||
SDL_SYSTEM_CURSOR_ARROW, // SystemCursor_Default
|
||||
SDL_SYSTEM_CURSOR_HAND, // SystemCursor_Hand
|
||||
SDL_SYSTEM_CURSOR_ARROW, // SystemCursor_Help
|
||||
SDL_SYSTEM_CURSOR_SIZEALL, // SystemCursor_Move
|
||||
SDL_NUM_SYSTEM_CURSORS, // SystemCursor_None
|
||||
SDL_SYSTEM_CURSOR_HAND, // SystemCursor_Pointer
|
||||
SDL_SYSTEM_CURSOR_WAITARROW, // SystemCursor_Progress
|
||||
SDL_SYSTEM_CURSOR_SIZEWE, // SystemCursor_ResizeE
|
||||
SDL_SYSTEM_CURSOR_SIZENS, // SystemCursor_ResizeN
|
||||
SDL_SYSTEM_CURSOR_SIZENESW, // SystemCursor_ResizeNE
|
||||
SDL_SYSTEM_CURSOR_SIZENWSE, // SystemCursor_ResizeNW
|
||||
SDL_SYSTEM_CURSOR_SIZENS, // SystemCursor_ResizeS
|
||||
SDL_SYSTEM_CURSOR_SIZENWSE, // SystemCursor_ResizeSE
|
||||
SDL_SYSTEM_CURSOR_SIZENESW, // SystemCursor_ResizeSW
|
||||
SDL_SYSTEM_CURSOR_SIZEWE, // SystemCursor_ResizeW
|
||||
SDL_SYSTEM_CURSOR_IBEAM, // SystemCursor_Text
|
||||
SDL_SYSTEM_CURSOR_WAIT // SystemCursor_Wait
|
||||
};
|
||||
|
||||
static_assert(SystemCursor_Max + 1 == 18, "System cursor array is incomplete");
|
||||
}
|
||||
|
||||
@@ -7,38 +7,33 @@
|
||||
#ifndef NAZARA_CURSORIMPL_HPP
|
||||
#define NAZARA_CURSORIMPL_HPP
|
||||
|
||||
#include <array>
|
||||
#include <Nazara/Platform/Enums.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Platform/Enums.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
|
||||
#include <SDL2/SDL_mouse.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Image;
|
||||
|
||||
class CursorImpl
|
||||
{
|
||||
friend class Cursor;
|
||||
|
||||
public:
|
||||
bool Create(const Image& image, int hotSpotX, int hotSpotY);
|
||||
bool Create(SystemCursor cursor);
|
||||
|
||||
void Destroy();
|
||||
CursorImpl(const Image& image, const Vector2i& hotSpot);
|
||||
CursorImpl(SystemCursor cursor);
|
||||
CursorImpl(const CursorImpl&) = delete;
|
||||
CursorImpl(CursorImpl&&) noexcept = default;
|
||||
~CursorImpl();
|
||||
|
||||
SDL_Cursor* GetCursor();
|
||||
|
||||
CursorImpl& operator=(const CursorImpl&) = delete;
|
||||
CursorImpl& operator=(CursorImpl&&) noexcept = default;
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
SDL_Cursor* m_cursor = nullptr;
|
||||
SDL_Surface* m_icon = nullptr;
|
||||
Image m_iconImage;
|
||||
|
||||
static std::array<SDL_SystemCursor, SystemCursor_Max + 1> s_systemCursorIds;
|
||||
MovablePtr<SDL_Cursor> m_cursor;
|
||||
MovablePtr<SDL_Surface> m_surface;
|
||||
Image m_cursorImage;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Platform/SDL2/IconImpl.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
bool IconImpl::Create(const Image& icon)
|
||||
IconImpl::IconImpl(const Image& icon)
|
||||
{
|
||||
ErrorFlags errFlags(ErrorFlag_ThrowException);
|
||||
|
||||
m_iconImage = icon;
|
||||
if (!m_iconImage.Convert(PixelFormat_BGRA8))
|
||||
{
|
||||
if (!m_iconImage.Convert(PixelFormat::BGRA8))
|
||||
NazaraError("Failed to convert icon to BGRA8");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_icon = SDL_CreateRGBSurfaceWithFormatFrom(
|
||||
m_iconImage.GetPixels(),
|
||||
@@ -25,21 +25,16 @@ namespace Nz
|
||||
32,
|
||||
32 * m_iconImage.GetWidth(),
|
||||
SDL_PIXELFORMAT_BGRA8888
|
||||
);
|
||||
);
|
||||
|
||||
if (!m_icon)
|
||||
{
|
||||
NazaraError(SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
NazaraError("failed to create SDL Surface for icon: " + std::string(SDL_GetError()));
|
||||
}
|
||||
|
||||
void IconImpl::Destroy()
|
||||
IconImpl::~IconImpl()
|
||||
{
|
||||
SDL_FreeSurface(m_icon);
|
||||
m_iconImage.Destroy();
|
||||
if (m_icon)
|
||||
SDL_FreeSurface(m_icon);
|
||||
}
|
||||
|
||||
SDL_Surface* IconImpl::GetIcon()
|
||||
|
||||
@@ -8,25 +8,28 @@
|
||||
#define NAZARA_ICONIMPL_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Image;
|
||||
|
||||
class IconImpl
|
||||
{
|
||||
public:
|
||||
bool Create(const Image& image);
|
||||
void Destroy();
|
||||
IconImpl(const Image& image);
|
||||
IconImpl(const IconImpl&) = delete;
|
||||
IconImpl(IconImpl&&) noexcept = default;
|
||||
~IconImpl();
|
||||
|
||||
SDL_Surface* GetIcon();
|
||||
|
||||
private:
|
||||
IconImpl& operator=(const IconImpl&) = default;
|
||||
IconImpl& operator=(IconImpl&&) noexcept = default;
|
||||
|
||||
SDL_Surface* m_icon = nullptr;
|
||||
private:
|
||||
Image m_iconImage;
|
||||
MovablePtr<SDL_Surface> m_icon;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Nz
|
||||
|
||||
bool WindowImpl::Create(const VideoMode& mode, const std::string& title, WindowStyleFlags style)
|
||||
{
|
||||
bool async = (style & WindowStyle_Threaded) != 0;
|
||||
bool async = (style & WindowStyle::Threaded) != 0;
|
||||
if (async)
|
||||
{
|
||||
NazaraError("SDL2 backend doesn't support asyn window for now");
|
||||
@@ -74,7 +74,7 @@ namespace Nz
|
||||
}
|
||||
|
||||
|
||||
bool fullscreen = (style & WindowStyle_Fullscreen) != 0;
|
||||
bool fullscreen = (style & WindowStyle::Fullscreen) != 0;
|
||||
|
||||
Uint32 winStyle = 0;
|
||||
|
||||
@@ -94,16 +94,16 @@ namespace Nz
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(style & WindowStyle_Titlebar))
|
||||
if (!(style & WindowStyle::Titlebar))
|
||||
winStyle |= SDL_WINDOW_BORDERLESS;
|
||||
|
||||
x = SDL_WINDOWPOS_CENTERED;
|
||||
y = SDL_WINDOWPOS_CENTERED;
|
||||
}
|
||||
|
||||
if (style & WindowStyle_Resizable)
|
||||
if (style & WindowStyle::Resizable)
|
||||
winStyle |= SDL_WINDOW_RESIZABLE;
|
||||
if (style & WindowStyle_Max)
|
||||
if (style & WindowStyle::Max)
|
||||
winStyle |= SDL_WINDOW_MAXIMIZED;
|
||||
|
||||
m_eventListener = true;
|
||||
@@ -313,7 +313,7 @@ namespace Nz
|
||||
auto window = static_cast<WindowImpl*>(userdata);
|
||||
|
||||
WindowEvent evt;
|
||||
evt.type = WindowEventType::WindowEventType_Max;
|
||||
evt.type = WindowEventType::Max;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
@@ -324,10 +324,10 @@ namespace Nz
|
||||
switch (event->window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
evt.type = Nz::WindowEventType::WindowEventType_Quit;
|
||||
evt.type = WindowEventType::Quit;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
evt.type = Nz::WindowEventType::WindowEventType_Resized;
|
||||
evt.type = WindowEventType::Resized;
|
||||
|
||||
evt.size.width = static_cast<unsigned int>(std::max(0, event->window.data1));
|
||||
evt.size.height = static_cast<unsigned int>(std::max(0, event->window.data2));
|
||||
@@ -336,7 +336,7 @@ namespace Nz
|
||||
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
evt.type = Nz::WindowEventType::WindowEventType_Moved;
|
||||
evt.type = WindowEventType::Moved;
|
||||
|
||||
evt.position.x = event->window.data1;
|
||||
evt.position.y = event->window.data2;
|
||||
@@ -345,19 +345,19 @@ namespace Nz
|
||||
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
evt.type = Nz::WindowEventType::WindowEventType_GainedFocus;
|
||||
evt.type = WindowEventType::GainedFocus;
|
||||
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
evt.type = Nz::WindowEventType::WindowEventType_LostFocus;
|
||||
evt.type = WindowEventType::LostFocus;
|
||||
|
||||
break;
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
evt.type = Nz::WindowEventType::WindowEventType_MouseEntered;
|
||||
evt.type = WindowEventType::MouseEntered;
|
||||
|
||||
break;
|
||||
case SDL_WINDOWEVENT_LEAVE:
|
||||
evt.type = Nz::WindowEventType::WindowEventType_MouseLeft;
|
||||
evt.type = WindowEventType::MouseLeft;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -374,7 +374,7 @@ namespace Nz
|
||||
return 0;
|
||||
}
|
||||
|
||||
evt.type = Nz::WindowEventType::WindowEventType_MouseMoved;
|
||||
evt.type = WindowEventType::MouseMoved;
|
||||
|
||||
evt.mouseMove.x = event->motion.x;
|
||||
evt.mouseMove.y = event->motion.y;
|
||||
@@ -393,12 +393,12 @@ namespace Nz
|
||||
|
||||
if (event->button.clicks % 2 == 0)
|
||||
{
|
||||
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonDoubleClicked;
|
||||
evt.type = WindowEventType::MouseButtonDoubleClicked;
|
||||
|
||||
window->m_parent->PushEvent(evt);
|
||||
}
|
||||
|
||||
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonPressed;
|
||||
evt.type = WindowEventType::MouseButtonPressed;
|
||||
|
||||
break;
|
||||
|
||||
@@ -410,7 +410,7 @@ namespace Nz
|
||||
evt.mouseButton.x = event->button.x;
|
||||
evt.mouseButton.y = event->button.y;
|
||||
|
||||
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonReleased;
|
||||
evt.type = WindowEventType::MouseButtonReleased;
|
||||
|
||||
break;
|
||||
|
||||
@@ -418,7 +418,7 @@ namespace Nz
|
||||
if (SDL_GetWindowID(window->m_handle) != event->wheel.windowID)
|
||||
return 0;
|
||||
|
||||
evt.type = Nz::WindowEventType::WindowEventType_MouseWheelMoved;
|
||||
evt.type = WindowEventType::MouseWheelMoved;
|
||||
|
||||
evt.mouseWheel.delta = event->wheel.y;
|
||||
|
||||
@@ -428,7 +428,7 @@ namespace Nz
|
||||
if (SDL_GetWindowID(window->m_handle) != event->key.windowID)
|
||||
return 0;
|
||||
|
||||
evt.type = WindowEventType_KeyPressed;
|
||||
evt.type = WindowEventType::KeyPressed;
|
||||
|
||||
evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode);
|
||||
evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym);
|
||||
@@ -446,7 +446,7 @@ namespace Nz
|
||||
break;
|
||||
window->m_parent->PushEvent(evt);
|
||||
|
||||
evt.type = WindowEventType_TextEntered;
|
||||
evt.type = WindowEventType::TextEntered;
|
||||
|
||||
evt.text.character = U'\n';
|
||||
evt.text.repeated = event->key.repeat != 0;
|
||||
@@ -457,7 +457,7 @@ namespace Nz
|
||||
case Nz::Keyboard::VKey::Backspace:
|
||||
window->m_parent->PushEvent(evt);
|
||||
|
||||
evt.type = WindowEventType_TextEntered;
|
||||
evt.type = WindowEventType::TextEntered;
|
||||
|
||||
evt.text.character = U'\b';
|
||||
evt.text.repeated = event->key.repeat != 0;
|
||||
@@ -475,7 +475,7 @@ namespace Nz
|
||||
if (SDL_GetWindowID(window->m_handle) != event->key.windowID)
|
||||
return 0;
|
||||
|
||||
evt.type = WindowEventType_KeyReleased;
|
||||
evt.type = WindowEventType::KeyReleased;
|
||||
|
||||
evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode);
|
||||
evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym);
|
||||
@@ -492,7 +492,7 @@ namespace Nz
|
||||
if (SDL_GetWindowID(window->m_handle) != event->text.windowID)
|
||||
return 0;
|
||||
|
||||
evt.type = WindowEventType_TextEntered;
|
||||
evt.type = WindowEventType::TextEntered;
|
||||
evt.text.repeated = false;
|
||||
|
||||
utf8::unchecked::iterator<const char*> it(event->text.text);
|
||||
@@ -504,7 +504,7 @@ namespace Nz
|
||||
} while (*it++);
|
||||
|
||||
// prevent post switch event
|
||||
evt.type = WindowEventType::WindowEventType_Max;
|
||||
evt.type = WindowEventType::Max;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -513,7 +513,7 @@ namespace Nz
|
||||
if (SDL_GetWindowID(window->m_handle) != event->edit.windowID)
|
||||
return 0;
|
||||
|
||||
evt.type = WindowEventType_TextEdited;
|
||||
evt.type = WindowEventType::TextEdited;
|
||||
evt.edit.length = event->edit.length;
|
||||
window->m_lastEditEventLength = evt.edit.length;
|
||||
|
||||
@@ -525,7 +525,7 @@ namespace Nz
|
||||
break;
|
||||
}
|
||||
|
||||
if (evt.type != WindowEventType::WindowEventType_Max)
|
||||
if (evt.type != WindowEventType::Max)
|
||||
window->m_parent->PushEvent(evt);
|
||||
}
|
||||
catch (std::exception e)
|
||||
|
||||
@@ -61,12 +61,12 @@ namespace Nz
|
||||
Destroy();
|
||||
|
||||
// Inspired by the code of the SFML by Laurent Gomila (and its team)
|
||||
if (style & WindowStyle_Fullscreen)
|
||||
if (style & WindowStyle::Fullscreen)
|
||||
{
|
||||
if (fullscreenWindow)
|
||||
{
|
||||
NazaraError("Window " + PointerToString(fullscreenWindow) + " already in fullscreen mode");
|
||||
style &= ~WindowStyle_Fullscreen;
|
||||
style &= ~WindowStyle::Fullscreen;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,10 +79,10 @@ namespace Nz
|
||||
fullscreenWindow = this;
|
||||
}
|
||||
}
|
||||
else if (style & WindowStyle_Closable || style & WindowStyle_Resizable)
|
||||
style |= WindowStyle_Titlebar;
|
||||
else if (style & WindowStyle::Closable || style & WindowStyle::Resizable)
|
||||
style |= WindowStyle::Titlebar;
|
||||
|
||||
m_asyncWindow = (style & WindowStyle_Threaded) != 0;
|
||||
m_asyncWindow = (style & WindowStyle::Threaded) != 0;
|
||||
|
||||
std::unique_ptr<WindowImpl> impl = std::make_unique<WindowImpl>(this);
|
||||
if (!impl->Create(mode, title, style))
|
||||
@@ -152,7 +152,7 @@ namespace Nz
|
||||
|
||||
void Window::Destroy()
|
||||
{
|
||||
m_cursor.Reset();
|
||||
m_cursor.reset();
|
||||
|
||||
if (m_impl)
|
||||
{
|
||||
@@ -341,7 +341,7 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
void Window::SetCursor(CursorRef cursor)
|
||||
void Window::SetCursor(std::shared_ptr<Cursor> cursor)
|
||||
{
|
||||
NazaraAssert(m_impl, "Window not created");
|
||||
NazaraAssert(cursor && cursor->IsValid(), "Invalid cursor");
|
||||
@@ -382,10 +382,10 @@ namespace Nz
|
||||
m_impl->SetFocus();
|
||||
}
|
||||
|
||||
void Window::SetIcon(IconRef icon)
|
||||
void Window::SetIcon(std::shared_ptr<Icon> icon)
|
||||
{
|
||||
NazaraAssert(m_impl, "Window not created");
|
||||
NazaraAssert(icon && icon.IsValid(), "Invalid icon");
|
||||
NazaraAssert(icon, "Invalid icon");
|
||||
|
||||
m_icon = std::move(icon);
|
||||
m_impl->SetIcon(*m_icon);
|
||||
@@ -629,7 +629,7 @@ namespace Nz
|
||||
|
||||
void Window::ConnectSlots()
|
||||
{
|
||||
m_cursorUpdateSlot.Connect(m_cursorController.OnCursorUpdated, [this](const CursorController*, const CursorRef& cursor)
|
||||
m_cursorUpdateSlot.Connect(m_cursorController.OnCursorUpdated, [this](const CursorController*, const std::shared_ptr<Cursor>& cursor)
|
||||
{
|
||||
if (IsValid())
|
||||
SetCursor(cursor);
|
||||
@@ -663,15 +663,15 @@ namespace Nz
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case WindowEventType_MouseEntered:
|
||||
case WindowEventType::MouseEntered:
|
||||
m_impl->RefreshCursor();
|
||||
break;
|
||||
|
||||
case WindowEventType_Resized:
|
||||
case WindowEventType::Resized:
|
||||
OnWindowResized();
|
||||
break;
|
||||
|
||||
case WindowEventType_Quit:
|
||||
case WindowEventType::Quit:
|
||||
if (m_closeOnQuit)
|
||||
Close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user