Upgrade Platform
This commit is contained in:
parent
8b0b5295f7
commit
ba7c56ddfa
|
|
@ -8,7 +8,6 @@
|
||||||
#define NAZARA_CURSOR_HPP
|
#define NAZARA_CURSOR_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Core/ObjectRef.hpp>
|
|
||||||
#include <Nazara/Math/Vector2.hpp>
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
#include <Nazara/Platform/Config.hpp>
|
#include <Nazara/Platform/Config.hpp>
|
||||||
#include <Nazara/Platform/Enums.hpp>
|
#include <Nazara/Platform/Enums.hpp>
|
||||||
|
|
@ -19,51 +18,42 @@ namespace Nz
|
||||||
{
|
{
|
||||||
class CursorImpl;
|
class CursorImpl;
|
||||||
|
|
||||||
class Cursor;
|
class NAZARA_PLATFORM_API Cursor
|
||||||
|
|
||||||
using CursorConstRef = ObjectRef<const Cursor>;
|
|
||||||
using CursorRef = ObjectRef<Cursor>;
|
|
||||||
|
|
||||||
class NAZARA_PLATFORM_API Cursor : public RefCounted
|
|
||||||
{
|
{
|
||||||
friend class Platform;
|
friend class Platform;
|
||||||
friend class WindowImpl;
|
friend class WindowImpl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Cursor();
|
Cursor();
|
||||||
inline Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
|
Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
|
||||||
Cursor(const Cursor&) = delete;
|
Cursor(const Cursor&) = delete;
|
||||||
Cursor(Cursor&&) = delete;
|
Cursor(Cursor&&) noexcept;
|
||||||
inline ~Cursor();
|
~Cursor();
|
||||||
|
|
||||||
bool Create(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
|
bool Create(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
inline const Image& GetImage() const;
|
|
||||||
inline SystemCursor GetSystemCursor() const;
|
inline SystemCursor GetSystemCursor() const;
|
||||||
|
|
||||||
inline bool IsValid() const;
|
inline bool IsValid() const;
|
||||||
|
|
||||||
Cursor& operator=(const Cursor&) = delete;
|
Cursor& operator=(const Cursor&) = delete;
|
||||||
Cursor& operator=(Cursor&&) = delete;
|
Cursor& operator=(Cursor&&) noexcept;
|
||||||
|
|
||||||
static inline Cursor* Get(SystemCursor cursor);
|
static inline std::shared_ptr<Cursor>& Get(SystemCursor cursor);
|
||||||
template<typename... Args> static CursorRef New(Args&&... args);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline explicit Cursor(SystemCursor systemCursor);
|
explicit Cursor(SystemCursor systemCursor);
|
||||||
|
|
||||||
bool Create(SystemCursor cursor);
|
bool Create(SystemCursor cursor);
|
||||||
|
|
||||||
static bool Initialize();
|
static bool Initialize();
|
||||||
static void Uninitialize();
|
static void Uninitialize();
|
||||||
|
|
||||||
Image m_cursorImage;
|
|
||||||
SystemCursor m_systemCursor;
|
SystemCursor m_systemCursor;
|
||||||
CursorImpl* m_impl;
|
std::unique_ptr<CursorImpl> m_impl;
|
||||||
|
|
||||||
static std::array<Cursor, SystemCursor_Max + 1> s_systemCursors;
|
static std::array<std::shared_ptr<Cursor>, SystemCursorCount> s_systemCursors;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,47 +2,11 @@
|
||||||
// This file is part of the "Nazara Engine - Platform module"
|
// This file is part of the "Nazara Engine - Platform module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
#include <Nazara/Platform/Cursor.hpp>
|
||||||
#include <Nazara/Platform/Debug.hpp>
|
#include <Nazara/Platform/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline Cursor::Cursor() :
|
|
||||||
m_impl(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Cursor::Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder)
|
|
||||||
{
|
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
|
||||||
Create(cursor, hotSpot, placeholder);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Cursor* Cursor::Get(SystemCursor cursor)
|
|
||||||
{
|
|
||||||
return &s_systemCursors[cursor];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Cursor::Cursor(SystemCursor systemCursor) :
|
|
||||||
Cursor()
|
|
||||||
{
|
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
|
||||||
Create(systemCursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Cursor::~Cursor()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const Image& Cursor::GetImage() const
|
|
||||||
{
|
|
||||||
NazaraAssert(IsValid(), "Invalid cursor");
|
|
||||||
NazaraAssert(m_cursorImage.IsValid(), "System cursors have no image");
|
|
||||||
|
|
||||||
return m_cursorImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SystemCursor Cursor::GetSystemCursor() const
|
inline SystemCursor Cursor::GetSystemCursor() const
|
||||||
{
|
{
|
||||||
NazaraAssert(IsValid(), "Invalid cursor");
|
NazaraAssert(IsValid(), "Invalid cursor");
|
||||||
|
|
@ -55,13 +19,9 @@ namespace Nz
|
||||||
return m_impl != nullptr;
|
return m_impl != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
inline std::shared_ptr<Cursor>& Cursor::Get(SystemCursor cursor)
|
||||||
CursorRef Cursor::New(Args&&... args)
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<Cursor> object(new Cursor(std::forward<Args>(args)...));
|
return s_systemCursors[UnderlyingCast(cursor)];
|
||||||
object->SetPersistent(false);
|
|
||||||
|
|
||||||
return object.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@ namespace Nz
|
||||||
CursorController(CursorController&&) noexcept = default;
|
CursorController(CursorController&&) noexcept = default;
|
||||||
~CursorController() = default;
|
~CursorController() = default;
|
||||||
|
|
||||||
inline void UpdateCursor(const CursorRef& cursor);
|
inline void UpdateCursor(const std::shared_ptr<Cursor>& cursor);
|
||||||
|
|
||||||
CursorController& operator=(const CursorController&) = delete;
|
CursorController& operator=(const CursorController&) = delete;
|
||||||
CursorController& operator=(CursorController&&) noexcept = default;
|
CursorController& operator=(CursorController&&) noexcept = default;
|
||||||
|
|
||||||
NazaraSignal(OnCursorUpdated, const CursorController* /*cursorController*/, const CursorRef& /*cursor*/);
|
NazaraSignal(OnCursorUpdated, const CursorController* /*cursorController*/, const std::shared_ptr<Cursor>& /*cursor*/);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline void CursorController::UpdateCursor(const CursorRef& cursor)
|
inline void CursorController::UpdateCursor(const std::shared_ptr<Cursor>& cursor)
|
||||||
{
|
{
|
||||||
OnCursorUpdated(this, cursor);
|
OnCursorUpdated(this, cursor);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,75 +11,81 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
enum SystemCursor
|
enum class SystemCursor
|
||||||
{
|
{
|
||||||
SystemCursor_Crosshair,
|
Crosshair,
|
||||||
SystemCursor_Default,
|
Default,
|
||||||
SystemCursor_Hand,
|
Hand,
|
||||||
SystemCursor_Help,
|
Help,
|
||||||
SystemCursor_Move,
|
Move,
|
||||||
SystemCursor_None,
|
None,
|
||||||
SystemCursor_Pointer,
|
Pointer,
|
||||||
SystemCursor_Progress,
|
Progress,
|
||||||
SystemCursor_ResizeE,
|
ResizeE,
|
||||||
SystemCursor_ResizeN,
|
ResizeN,
|
||||||
SystemCursor_ResizeNE,
|
ResizeNE,
|
||||||
SystemCursor_ResizeNW,
|
ResizeNW,
|
||||||
SystemCursor_ResizeS,
|
ResizeS,
|
||||||
SystemCursor_ResizeSE,
|
ResizeSE,
|
||||||
SystemCursor_ResizeSW,
|
ResizeSW,
|
||||||
SystemCursor_ResizeW,
|
ResizeW,
|
||||||
SystemCursor_Text,
|
Text,
|
||||||
SystemCursor_Wait,
|
Wait,
|
||||||
|
|
||||||
SystemCursor_Max = SystemCursor_Wait
|
Max = Wait
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WindowEventType
|
constexpr std::size_t SystemCursorCount = static_cast<std::size_t>(SystemCursor::Max) + 1;
|
||||||
{
|
|
||||||
WindowEventType_GainedFocus,
|
|
||||||
WindowEventType_LostFocus,
|
|
||||||
WindowEventType_KeyPressed,
|
|
||||||
WindowEventType_KeyReleased,
|
|
||||||
WindowEventType_MouseButtonDoubleClicked,
|
|
||||||
WindowEventType_MouseButtonPressed,
|
|
||||||
WindowEventType_MouseButtonReleased,
|
|
||||||
WindowEventType_MouseEntered,
|
|
||||||
WindowEventType_MouseLeft,
|
|
||||||
WindowEventType_MouseMoved,
|
|
||||||
WindowEventType_MouseWheelMoved,
|
|
||||||
WindowEventType_Moved,
|
|
||||||
WindowEventType_Quit,
|
|
||||||
WindowEventType_Resized,
|
|
||||||
WindowEventType_TextEdited,
|
|
||||||
WindowEventType_TextEntered,
|
|
||||||
|
|
||||||
WindowEventType_Max = WindowEventType_TextEntered
|
enum class WindowEventType
|
||||||
|
{
|
||||||
|
GainedFocus,
|
||||||
|
LostFocus,
|
||||||
|
KeyPressed,
|
||||||
|
KeyReleased,
|
||||||
|
MouseButtonDoubleClicked,
|
||||||
|
MouseButtonPressed,
|
||||||
|
MouseButtonReleased,
|
||||||
|
MouseEntered,
|
||||||
|
MouseLeft,
|
||||||
|
MouseMoved,
|
||||||
|
MouseWheelMoved,
|
||||||
|
Moved,
|
||||||
|
Quit,
|
||||||
|
Resized,
|
||||||
|
TextEdited,
|
||||||
|
TextEntered,
|
||||||
|
|
||||||
|
Max = TextEntered
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WindowStyle
|
constexpr std::size_t WindowEventTypeCount = static_cast<std::size_t>(WindowEventType::Max) + 1;
|
||||||
|
|
||||||
|
enum class WindowStyle
|
||||||
{
|
{
|
||||||
WindowStyle_None, ///< Window has no border nor titlebar.
|
None, ///< Window has no border nor titlebar.
|
||||||
WindowStyle_Fullscreen, ///< At the window creation, the OS tries to set it in fullscreen.
|
Fullscreen, ///< At the window creation, the OS tries to set it in fullscreen.
|
||||||
|
|
||||||
WindowStyle_Closable, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
|
Closable, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
|
||||||
WindowStyle_Resizable, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
|
Resizable, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
|
||||||
WindowStyle_Titlebar, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
|
Titlebar, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
|
||||||
|
|
||||||
WindowStyle_Threaded, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
|
Threaded, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
|
||||||
|
|
||||||
WindowStyle_Max = WindowStyle_Threaded
|
Max = Threaded
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr std::size_t WindowStyleCount = static_cast<std::size_t>(WindowStyle::Max) + 1;
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct EnumAsFlags<WindowStyle>
|
struct EnumAsFlags<WindowStyle>
|
||||||
{
|
{
|
||||||
static constexpr WindowStyle max = WindowStyle_Max;
|
static constexpr WindowStyle max = WindowStyle::Max;
|
||||||
};
|
};
|
||||||
|
|
||||||
using WindowStyleFlags = Flags<WindowStyle>;
|
using WindowStyleFlags = Flags<WindowStyle>;
|
||||||
|
|
||||||
constexpr WindowStyleFlags WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar;
|
constexpr WindowStyleFlags WindowStyle_Default = WindowStyle::Closable | WindowStyle::Resizable | WindowStyle::Titlebar;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NAZARA_ENUMS_PLATFORM_HPP
|
#endif // NAZARA_ENUMS_PLATFORM_HPP
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ namespace Nz
|
||||||
struct WindowEvent
|
struct WindowEvent
|
||||||
{
|
{
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_KeyPressed
|
// -WindowEventType::KeyPressed
|
||||||
// -WindowEventType_KeyReleased
|
// -WindowEventType::KeyReleased
|
||||||
struct KeyEvent
|
struct KeyEvent
|
||||||
{
|
{
|
||||||
Keyboard::Scancode scancode;
|
Keyboard::Scancode scancode;
|
||||||
|
|
@ -34,8 +34,8 @@ namespace Nz
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_MouseButtonDoubleClicked
|
// -WindowEventType::MouseButtonDoubleClicked
|
||||||
// -WindowEventType_MouseButtonPressed
|
// -WindowEventType::MouseButtonPressed
|
||||||
struct MouseButtonEvent
|
struct MouseButtonEvent
|
||||||
{
|
{
|
||||||
Mouse::Button button;
|
Mouse::Button button;
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Nz
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_MouseMoved
|
// -WindowEventType::MouseMoved
|
||||||
struct MouseMoveEvent
|
struct MouseMoveEvent
|
||||||
{
|
{
|
||||||
int deltaX;
|
int deltaX;
|
||||||
|
|
@ -54,7 +54,7 @@ namespace Nz
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_MouseWheelMoved
|
// -WindowEventType::MouseWheelMoved
|
||||||
struct MouseWheelEvent
|
struct MouseWheelEvent
|
||||||
{
|
{
|
||||||
float delta;
|
float delta;
|
||||||
|
|
@ -63,7 +63,7 @@ namespace Nz
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_Moved
|
// -WindowEventType::Moved
|
||||||
struct PositionEvent
|
struct PositionEvent
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
@ -71,7 +71,7 @@ namespace Nz
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_Resized
|
// -WindowEventType::Resized
|
||||||
struct SizeEvent
|
struct SizeEvent
|
||||||
{
|
{
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
|
|
@ -79,7 +79,7 @@ namespace Nz
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_TextEntered
|
// -WindowEventType::TextEntered
|
||||||
struct TextEvent
|
struct TextEvent
|
||||||
{
|
{
|
||||||
bool repeated;
|
bool repeated;
|
||||||
|
|
@ -87,7 +87,7 @@ namespace Nz
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_TextEdited
|
// -WindowEventType::TextEdited
|
||||||
struct EditEvent
|
struct EditEvent
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
|
|
@ -99,37 +99,37 @@ namespace Nz
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_KeyPressed
|
// -WindowEventType::KeyPressed
|
||||||
// -WindowEventType_KeyReleased
|
// -WindowEventType::KeyReleased
|
||||||
KeyEvent key;
|
KeyEvent key;
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_MouseButtonDoubleClicked
|
// -WindowEventType::MouseButtonDoubleClicked
|
||||||
// -WindowEventType_MouseButtonPressed
|
// -WindowEventType::MouseButtonPressed
|
||||||
MouseButtonEvent mouseButton;
|
MouseButtonEvent mouseButton;
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_MouseMoved
|
// -WindowEventType::MouseMoved
|
||||||
MouseMoveEvent mouseMove;
|
MouseMoveEvent mouseMove;
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_MouseWheelMoved
|
// -WindowEventType::MouseWheelMoved
|
||||||
MouseWheelEvent mouseWheel;
|
MouseWheelEvent mouseWheel;
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_Moved
|
// -WindowEventType::Moved
|
||||||
PositionEvent position;
|
PositionEvent position;
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_Resized
|
// -WindowEventType::Resized
|
||||||
SizeEvent size;
|
SizeEvent size;
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_TextEntered
|
// -WindowEventType::TextEntered
|
||||||
TextEvent text;
|
TextEvent text;
|
||||||
|
|
||||||
// Used by:
|
// Used by:
|
||||||
// -WindowEventType_TextEntered
|
// -WindowEventType::TextEntered
|
||||||
EditEvent edit;
|
EditEvent edit;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -19,67 +19,67 @@ namespace Nz
|
||||||
|
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case WindowEventType_GainedFocus:
|
case WindowEventType::GainedFocus:
|
||||||
OnGainedFocus(this);
|
OnGainedFocus(this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_KeyPressed:
|
case WindowEventType::KeyPressed:
|
||||||
OnKeyPressed(this, event.key);
|
OnKeyPressed(this, event.key);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_KeyReleased:
|
case WindowEventType::KeyReleased:
|
||||||
OnKeyReleased(this, event.key);
|
OnKeyReleased(this, event.key);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_LostFocus:
|
case WindowEventType::LostFocus:
|
||||||
OnLostFocus(this);
|
OnLostFocus(this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_MouseButtonDoubleClicked:
|
case WindowEventType::MouseButtonDoubleClicked:
|
||||||
OnMouseButtonDoubleClicked(this, event.mouseButton);
|
OnMouseButtonDoubleClicked(this, event.mouseButton);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_MouseButtonPressed:
|
case WindowEventType::MouseButtonPressed:
|
||||||
OnMouseButtonPressed(this, event.mouseButton);
|
OnMouseButtonPressed(this, event.mouseButton);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_MouseButtonReleased:
|
case WindowEventType::MouseButtonReleased:
|
||||||
OnMouseButtonReleased(this, event.mouseButton);
|
OnMouseButtonReleased(this, event.mouseButton);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_MouseEntered:
|
case WindowEventType::MouseEntered:
|
||||||
OnMouseEntered(this);
|
OnMouseEntered(this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_MouseLeft:
|
case WindowEventType::MouseLeft:
|
||||||
OnMouseLeft(this);
|
OnMouseLeft(this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_MouseMoved:
|
case WindowEventType::MouseMoved:
|
||||||
OnMouseMoved(this, event.mouseMove);
|
OnMouseMoved(this, event.mouseMove);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_MouseWheelMoved:
|
case WindowEventType::MouseWheelMoved:
|
||||||
OnMouseWheelMoved(this, event.mouseWheel);
|
OnMouseWheelMoved(this, event.mouseWheel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_Moved:
|
case WindowEventType::Moved:
|
||||||
OnMoved(this, event.position);
|
OnMoved(this, event.position);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_Quit:
|
case WindowEventType::Quit:
|
||||||
OnQuit(this);
|
OnQuit(this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_Resized:
|
case WindowEventType::Resized:
|
||||||
OnResized(this, event.size);
|
OnResized(this, event.size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_TextEntered:
|
case WindowEventType::TextEntered:
|
||||||
OnTextEntered(this, event.text);
|
OnTextEntered(this, event.text);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_TextEdited:
|
case WindowEventType::TextEdited:
|
||||||
OnTextEdited(this, event.edit);
|
OnTextEdited(this, event.edit);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,36 +8,35 @@
|
||||||
#define NAZARA_ICON_HPP
|
#define NAZARA_ICON_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Core/ObjectRef.hpp>
|
|
||||||
#include <Nazara/Platform/Config.hpp>
|
#include <Nazara/Platform/Config.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class Image;
|
class Image;
|
||||||
class IconImpl;
|
class IconImpl;
|
||||||
|
|
||||||
class Icon;
|
class NAZARA_PLATFORM_API Icon
|
||||||
|
|
||||||
using IconRef = ObjectRef<Icon>;
|
|
||||||
|
|
||||||
class NAZARA_PLATFORM_API Icon : public RefCounted
|
|
||||||
{
|
{
|
||||||
friend class WindowImpl;
|
friend class WindowImpl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Icon();
|
Icon();
|
||||||
inline explicit Icon(const Image& icon);
|
explicit Icon(const Image& icon);
|
||||||
inline ~Icon();
|
Icon(const Icon&) = delete;
|
||||||
|
Icon(Icon&&) noexcept;
|
||||||
|
~Icon();
|
||||||
|
|
||||||
bool Create(const Image& icon);
|
bool Create(const Image& icon);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
inline bool IsValid() const;
|
inline bool IsValid() const;
|
||||||
|
|
||||||
template<typename... Args> static IconRef New(Args&&... args);
|
Icon& operator=(const Icon&) = delete;
|
||||||
|
Icon& operator=(Icon&&) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IconImpl* m_impl;
|
std::unique_ptr<IconImpl> m_impl;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,35 +7,10 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
Icon::Icon() :
|
|
||||||
m_impl(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Icon::Icon(const Image& icon)
|
|
||||||
{
|
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
|
||||||
Create(icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
Icon::~Icon()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Icon::IsValid() const
|
bool Icon::IsValid() const
|
||||||
{
|
{
|
||||||
return m_impl != nullptr;
|
return m_impl != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
IconRef Icon::New(Args&&... args)
|
|
||||||
{
|
|
||||||
std::unique_ptr<Icon> object(new Icon(std::forward<Args>(args)...));
|
|
||||||
object->SetPersistent(false);
|
|
||||||
|
|
||||||
return object.release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Platform/DebugOff.hpp>
|
#include <Nazara/Platform/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Nz
|
||||||
void EnableKeyRepeat(bool enable);
|
void EnableKeyRepeat(bool enable);
|
||||||
void EnableSmoothScrolling(bool enable);
|
void EnableSmoothScrolling(bool enable);
|
||||||
|
|
||||||
inline const CursorRef& GetCursor() const;
|
inline const std::shared_ptr<Cursor>& GetCursor() const;
|
||||||
inline CursorController& GetCursorController();
|
inline CursorController& GetCursorController();
|
||||||
inline EventHandler& GetEventHandler();
|
inline EventHandler& GetEventHandler();
|
||||||
Vector2i GetPosition() const;
|
Vector2i GetPosition() const;
|
||||||
|
|
@ -82,11 +82,11 @@ namespace Nz
|
||||||
|
|
||||||
void ProcessEvents(bool block = false);
|
void ProcessEvents(bool block = false);
|
||||||
|
|
||||||
void SetCursor(CursorRef cursor);
|
void SetCursor(std::shared_ptr<Cursor> cursor);
|
||||||
inline void SetCursor(SystemCursor systemCursor);
|
inline void SetCursor(SystemCursor systemCursor);
|
||||||
void SetEventListener(bool listener);
|
void SetEventListener(bool listener);
|
||||||
void SetFocus();
|
void SetFocus();
|
||||||
void SetIcon(IconRef icon);
|
void SetIcon(std::shared_ptr<Icon> icon);
|
||||||
void SetMaximumSize(const Vector2i& maxSize);
|
void SetMaximumSize(const Vector2i& maxSize);
|
||||||
void SetMaximumSize(int width, int height);
|
void SetMaximumSize(int width, int height);
|
||||||
void SetMinimumSize(const Vector2i& minSize);
|
void SetMinimumSize(const Vector2i& minSize);
|
||||||
|
|
@ -133,9 +133,9 @@ namespace Nz
|
||||||
std::vector<WindowEvent> m_pendingEvents;
|
std::vector<WindowEvent> m_pendingEvents;
|
||||||
std::condition_variable m_eventCondition;
|
std::condition_variable m_eventCondition;
|
||||||
CursorController m_cursorController;
|
CursorController m_cursorController;
|
||||||
CursorRef m_cursor;
|
std::shared_ptr<Cursor> m_cursor;
|
||||||
EventHandler m_eventHandler;
|
EventHandler m_eventHandler;
|
||||||
IconRef m_icon;
|
std::shared_ptr<Icon> m_icon;
|
||||||
std::mutex m_eventMutex;
|
std::mutex m_eventMutex;
|
||||||
std::mutex m_eventConditionMutex;
|
std::mutex m_eventConditionMutex;
|
||||||
bool m_asyncWindow;
|
bool m_asyncWindow;
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const CursorRef& Window::GetCursor() const
|
inline const std::shared_ptr<Cursor>& Window::GetCursor() const
|
||||||
{
|
{
|
||||||
return m_cursor;
|
return m_cursor;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,43 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Platform/Cursor.hpp>
|
#include <Nazara/Platform/Cursor.hpp>
|
||||||
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
#include <Nazara/Platform/SDL2/CursorImpl.hpp>
|
#include <Nazara/Platform/SDL2/CursorImpl.hpp>
|
||||||
#include <Nazara/Platform/Debug.hpp>
|
#include <Nazara/Platform/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
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)
|
bool Cursor::Create(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder)
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
std::unique_ptr<CursorImpl> impl(new CursorImpl);
|
try
|
||||||
if (!impl->Create(cursor, hotSpot.x, hotSpot.y))
|
|
||||||
{
|
{
|
||||||
NazaraError("Failed to create cursor implementation");
|
m_impl = std::make_unique<CursorImpl>(cursor, hotSpot);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
NazaraError(e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cursorImage = cursor;
|
|
||||||
m_impl = impl.release();
|
|
||||||
m_systemCursor = placeholder;
|
m_systemCursor = placeholder;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -28,52 +47,46 @@ namespace Nz
|
||||||
|
|
||||||
void Cursor::Destroy()
|
void Cursor::Destroy()
|
||||||
{
|
{
|
||||||
m_cursorImage.Destroy();
|
m_impl.reset();
|
||||||
|
|
||||||
if (m_impl)
|
|
||||||
{
|
|
||||||
m_impl->Destroy();
|
|
||||||
|
|
||||||
delete m_impl;
|
|
||||||
m_impl = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Cursor::Create(SystemCursor cursor)
|
bool Cursor::Create(SystemCursor cursor)
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
std::unique_ptr<CursorImpl> impl(new CursorImpl);
|
try
|
||||||
if (!impl->Create(cursor))
|
|
||||||
{
|
{
|
||||||
NazaraError("Failed to create cursor implementation");
|
m_impl = std::make_unique<CursorImpl>(cursor);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
NazaraError(e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_impl = impl.release();
|
|
||||||
m_systemCursor = cursor;
|
m_systemCursor = cursor;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cursor& Cursor::operator=(Cursor&&) noexcept = default;
|
||||||
|
|
||||||
bool Cursor::Initialize()
|
bool Cursor::Initialize()
|
||||||
{
|
{
|
||||||
if (!CursorImpl::Initialize())
|
for (std::size_t i = 0; i < SystemCursorCount; ++i)
|
||||||
return false;
|
{
|
||||||
|
s_systemCursors[i] = std::make_shared<Cursor>();
|
||||||
for (std::size_t i = 0; i <= SystemCursor_Max; ++i)
|
s_systemCursors[i]->Create(static_cast<SystemCursor>(i));
|
||||||
s_systemCursors[i].Create(static_cast<SystemCursor>(i));
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cursor::Uninitialize()
|
void Cursor::Uninitialize()
|
||||||
{
|
{
|
||||||
for (Cursor& cursor : s_systemCursors)
|
for (std::shared_ptr<Cursor>& cursor : s_systemCursors)
|
||||||
cursor.Destroy();
|
cursor.reset();
|
||||||
|
|
||||||
CursorImpl::Uninitialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
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)
|
bool Icon::Create(const Image& icon)
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
std::unique_ptr<IconImpl> impl(new IconImpl);
|
try
|
||||||
if (!impl->Create(icon))
|
|
||||||
{
|
{
|
||||||
NazaraError("Failed to create icon implementation");
|
m_impl = std::make_unique<IconImpl>(icon);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
NazaraError(e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_impl = impl.release();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Icon::Destroy()
|
void Icon::Destroy()
|
||||||
{
|
{
|
||||||
if (m_impl)
|
m_impl.reset();
|
||||||
{
|
}
|
||||||
m_impl->Destroy();
|
|
||||||
|
|
||||||
delete m_impl;
|
Icon& Icon::operator=(Icon&&) noexcept = default;
|
||||||
m_impl = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,67 +2,87 @@
|
||||||
// This file is part of the "Nazara Engine - Platform module"
|
// This file is part of the "Nazara Engine - Platform module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// 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/Platform/SDL2/CursorImpl.hpp>
|
||||||
#include <Nazara/Utility/Image.hpp>
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
#include <Nazara/Utility/PixelFormat.hpp>
|
#include <Nazara/Utility/PixelFormat.hpp>
|
||||||
|
#include <array>
|
||||||
|
#include <Nazara/Platform/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
bool CursorImpl::Create(const Image& cursor, int hotSpotX, int hotSpotY)
|
namespace
|
||||||
{
|
{
|
||||||
m_iconImage = cursor;
|
std::array<SDL_SystemCursor, SystemCursorCount> s_systemCursorIds =
|
||||||
if (!m_iconImage.Convert(PixelFormat_BGRA8))
|
|
||||||
{
|
{
|
||||||
NazaraError("Failed to convert icon to BGRA8");
|
SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor::Crosshair
|
||||||
return false;
|
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(SystemCursorCount == 18, "System cursor array is incomplete");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_icon = SDL_CreateRGBSurfaceWithFormatFrom(
|
CursorImpl::CursorImpl(const Image& cursor, const Vector2i& hotSpot)
|
||||||
m_iconImage.GetPixels(),
|
{
|
||||||
m_iconImage.GetWidth(),
|
ErrorFlags errFlags(ErrorFlag_ThrowException);
|
||||||
m_iconImage.GetHeight(),
|
|
||||||
|
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,
|
32,
|
||||||
4 * m_iconImage.GetWidth(),
|
4 * m_cursorImage.GetWidth(),
|
||||||
SDL_PIXELFORMAT_BGRA32
|
SDL_PIXELFORMAT_BGRA32
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!m_icon)
|
if (!m_surface)
|
||||||
{
|
NazaraError("failed to create SDL Surface for cursor: " + std::string(SDL_GetError()));
|
||||||
NazaraError(SDL_GetError());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_cursor = SDL_CreateColorCursor(m_icon, hotSpotX, hotSpotY);
|
|
||||||
|
|
||||||
|
m_cursor = SDL_CreateColorCursor(m_surface, hotSpot.x, hotSpot.y);
|
||||||
if (!m_cursor)
|
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;
|
CursorImpl::CursorImpl(SystemCursor cursor)
|
||||||
}
|
|
||||||
|
|
||||||
bool CursorImpl::Create(SystemCursor cursor)
|
|
||||||
{
|
{
|
||||||
if (cursor != SystemCursor_None)
|
ErrorFlags errFlags(ErrorFlag_ThrowException);
|
||||||
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]);
|
|
||||||
else
|
|
||||||
m_cursor = nullptr;
|
|
||||||
|
|
||||||
m_icon = nullptr;
|
if (cursor != SystemCursor::None)
|
||||||
|
{
|
||||||
return true;
|
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)
|
if (m_surface)
|
||||||
SDL_FreeSurface(m_icon);
|
SDL_FreeSurface(m_surface);
|
||||||
|
|
||||||
if (m_cursor)
|
if (m_cursor)
|
||||||
SDL_FreeCursor(m_cursor);
|
SDL_FreeCursor(m_cursor);
|
||||||
|
|
@ -72,37 +92,4 @@ namespace Nz
|
||||||
{
|
{
|
||||||
return m_cursor;
|
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
|
#ifndef NAZARA_CURSORIMPL_HPP
|
||||||
#define NAZARA_CURSORIMPL_HPP
|
#define NAZARA_CURSORIMPL_HPP
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <Nazara/Platform/Enums.hpp>
|
|
||||||
#include <Nazara/Prerequisites.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 <Nazara/Utility/Image.hpp>
|
||||||
|
|
||||||
#include <SDL2/SDL_mouse.h>
|
#include <SDL2/SDL_mouse.h>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class Image;
|
|
||||||
|
|
||||||
class CursorImpl
|
class CursorImpl
|
||||||
{
|
{
|
||||||
friend class Cursor;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool Create(const Image& image, int hotSpotX, int hotSpotY);
|
CursorImpl(const Image& image, const Vector2i& hotSpot);
|
||||||
bool Create(SystemCursor cursor);
|
CursorImpl(SystemCursor cursor);
|
||||||
|
CursorImpl(const CursorImpl&) = delete;
|
||||||
void Destroy();
|
CursorImpl(CursorImpl&&) noexcept = default;
|
||||||
|
~CursorImpl();
|
||||||
|
|
||||||
SDL_Cursor* GetCursor();
|
SDL_Cursor* GetCursor();
|
||||||
|
|
||||||
|
CursorImpl& operator=(const CursorImpl&) = delete;
|
||||||
|
CursorImpl& operator=(CursorImpl&&) noexcept = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool Initialize();
|
MovablePtr<SDL_Cursor> m_cursor;
|
||||||
static void Uninitialize();
|
MovablePtr<SDL_Surface> m_surface;
|
||||||
|
Image m_cursorImage;
|
||||||
SDL_Cursor* m_cursor = nullptr;
|
|
||||||
SDL_Surface* m_icon = nullptr;
|
|
||||||
Image m_iconImage;
|
|
||||||
|
|
||||||
static std::array<SDL_SystemCursor, SystemCursor_Max + 1> s_systemCursorIds;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,20 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Platform/Debug.hpp>
|
#include <Nazara/Platform/Debug.hpp>
|
||||||
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
#include <Nazara/Platform/SDL2/IconImpl.hpp>
|
#include <Nazara/Platform/SDL2/IconImpl.hpp>
|
||||||
#include <Nazara/Utility/Image.hpp>
|
#include <Nazara/Utility/Image.hpp>
|
||||||
#include <Nazara/Utility/PixelFormat.hpp>
|
#include <Nazara/Utility/PixelFormat.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
bool IconImpl::Create(const Image& icon)
|
IconImpl::IconImpl(const Image& icon)
|
||||||
{
|
{
|
||||||
|
ErrorFlags errFlags(ErrorFlag_ThrowException);
|
||||||
|
|
||||||
m_iconImage = icon;
|
m_iconImage = icon;
|
||||||
if (!m_iconImage.Convert(PixelFormat_BGRA8))
|
if (!m_iconImage.Convert(PixelFormat::BGRA8))
|
||||||
{
|
|
||||||
NazaraError("Failed to convert icon to BGRA8");
|
NazaraError("Failed to convert icon to BGRA8");
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_icon = SDL_CreateRGBSurfaceWithFormatFrom(
|
m_icon = SDL_CreateRGBSurfaceWithFormatFrom(
|
||||||
m_iconImage.GetPixels(),
|
m_iconImage.GetPixels(),
|
||||||
|
|
@ -28,18 +28,13 @@ namespace Nz
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!m_icon)
|
if (!m_icon)
|
||||||
{
|
NazaraError("failed to create SDL Surface for icon: " + std::string(SDL_GetError()));
|
||||||
NazaraError(SDL_GetError());
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
IconImpl::~IconImpl()
|
||||||
}
|
|
||||||
|
|
||||||
void IconImpl::Destroy()
|
|
||||||
{
|
{
|
||||||
|
if (m_icon)
|
||||||
SDL_FreeSurface(m_icon);
|
SDL_FreeSurface(m_icon);
|
||||||
m_iconImage.Destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface* IconImpl::GetIcon()
|
SDL_Surface* IconImpl::GetIcon()
|
||||||
|
|
|
||||||
|
|
@ -8,25 +8,28 @@
|
||||||
#define NAZARA_ICONIMPL_HPP
|
#define NAZARA_ICONIMPL_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
|
#include <Nazara/Core/MovablePtr.hpp>
|
||||||
#include <Nazara/Utility/Image.hpp>
|
#include <Nazara/Utility/Image.hpp>
|
||||||
#include <SDL2/SDL_surface.h>
|
#include <SDL2/SDL_surface.h>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class Image;
|
|
||||||
|
|
||||||
class IconImpl
|
class IconImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool Create(const Image& image);
|
IconImpl(const Image& image);
|
||||||
void Destroy();
|
IconImpl(const IconImpl&) = delete;
|
||||||
|
IconImpl(IconImpl&&) noexcept = default;
|
||||||
|
~IconImpl();
|
||||||
|
|
||||||
SDL_Surface* GetIcon();
|
SDL_Surface* GetIcon();
|
||||||
|
|
||||||
private:
|
IconImpl& operator=(const IconImpl&) = default;
|
||||||
|
IconImpl& operator=(IconImpl&&) noexcept = default;
|
||||||
|
|
||||||
SDL_Surface* m_icon = nullptr;
|
private:
|
||||||
Image m_iconImage;
|
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 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)
|
if (async)
|
||||||
{
|
{
|
||||||
NazaraError("SDL2 backend doesn't support asyn window for now");
|
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;
|
Uint32 winStyle = 0;
|
||||||
|
|
||||||
|
|
@ -94,16 +94,16 @@ namespace Nz
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!(style & WindowStyle_Titlebar))
|
if (!(style & WindowStyle::Titlebar))
|
||||||
winStyle |= SDL_WINDOW_BORDERLESS;
|
winStyle |= SDL_WINDOW_BORDERLESS;
|
||||||
|
|
||||||
x = SDL_WINDOWPOS_CENTERED;
|
x = SDL_WINDOWPOS_CENTERED;
|
||||||
y = SDL_WINDOWPOS_CENTERED;
|
y = SDL_WINDOWPOS_CENTERED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style & WindowStyle_Resizable)
|
if (style & WindowStyle::Resizable)
|
||||||
winStyle |= SDL_WINDOW_RESIZABLE;
|
winStyle |= SDL_WINDOW_RESIZABLE;
|
||||||
if (style & WindowStyle_Max)
|
if (style & WindowStyle::Max)
|
||||||
winStyle |= SDL_WINDOW_MAXIMIZED;
|
winStyle |= SDL_WINDOW_MAXIMIZED;
|
||||||
|
|
||||||
m_eventListener = true;
|
m_eventListener = true;
|
||||||
|
|
@ -313,7 +313,7 @@ namespace Nz
|
||||||
auto window = static_cast<WindowImpl*>(userdata);
|
auto window = static_cast<WindowImpl*>(userdata);
|
||||||
|
|
||||||
WindowEvent evt;
|
WindowEvent evt;
|
||||||
evt.type = WindowEventType::WindowEventType_Max;
|
evt.type = WindowEventType::Max;
|
||||||
|
|
||||||
switch (event->type)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
|
|
@ -324,10 +324,10 @@ namespace Nz
|
||||||
switch (event->window.event)
|
switch (event->window.event)
|
||||||
{
|
{
|
||||||
case SDL_WINDOWEVENT_CLOSE:
|
case SDL_WINDOWEVENT_CLOSE:
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_Quit;
|
evt.type = WindowEventType::Quit;
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
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.width = static_cast<unsigned int>(std::max(0, event->window.data1));
|
||||||
evt.size.height = static_cast<unsigned int>(std::max(0, event->window.data2));
|
evt.size.height = static_cast<unsigned int>(std::max(0, event->window.data2));
|
||||||
|
|
@ -336,7 +336,7 @@ namespace Nz
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_MOVED:
|
case SDL_WINDOWEVENT_MOVED:
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_Moved;
|
evt.type = WindowEventType::Moved;
|
||||||
|
|
||||||
evt.position.x = event->window.data1;
|
evt.position.x = event->window.data1;
|
||||||
evt.position.y = event->window.data2;
|
evt.position.y = event->window.data2;
|
||||||
|
|
@ -345,19 +345,19 @@ namespace Nz
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_GainedFocus;
|
evt.type = WindowEventType::GainedFocus;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_LostFocus;
|
evt.type = WindowEventType::LostFocus;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_ENTER:
|
case SDL_WINDOWEVENT_ENTER:
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_MouseEntered;
|
evt.type = WindowEventType::MouseEntered;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_LEAVE:
|
case SDL_WINDOWEVENT_LEAVE:
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_MouseLeft;
|
evt.type = WindowEventType::MouseLeft;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -374,7 +374,7 @@ namespace Nz
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_MouseMoved;
|
evt.type = WindowEventType::MouseMoved;
|
||||||
|
|
||||||
evt.mouseMove.x = event->motion.x;
|
evt.mouseMove.x = event->motion.x;
|
||||||
evt.mouseMove.y = event->motion.y;
|
evt.mouseMove.y = event->motion.y;
|
||||||
|
|
@ -393,12 +393,12 @@ namespace Nz
|
||||||
|
|
||||||
if (event->button.clicks % 2 == 0)
|
if (event->button.clicks % 2 == 0)
|
||||||
{
|
{
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonDoubleClicked;
|
evt.type = WindowEventType::MouseButtonDoubleClicked;
|
||||||
|
|
||||||
window->m_parent->PushEvent(evt);
|
window->m_parent->PushEvent(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonPressed;
|
evt.type = WindowEventType::MouseButtonPressed;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -410,7 +410,7 @@ namespace Nz
|
||||||
evt.mouseButton.x = event->button.x;
|
evt.mouseButton.x = event->button.x;
|
||||||
evt.mouseButton.y = event->button.y;
|
evt.mouseButton.y = event->button.y;
|
||||||
|
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonReleased;
|
evt.type = WindowEventType::MouseButtonReleased;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -418,7 +418,7 @@ namespace Nz
|
||||||
if (SDL_GetWindowID(window->m_handle) != event->wheel.windowID)
|
if (SDL_GetWindowID(window->m_handle) != event->wheel.windowID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
evt.type = Nz::WindowEventType::WindowEventType_MouseWheelMoved;
|
evt.type = WindowEventType::MouseWheelMoved;
|
||||||
|
|
||||||
evt.mouseWheel.delta = event->wheel.y;
|
evt.mouseWheel.delta = event->wheel.y;
|
||||||
|
|
||||||
|
|
@ -428,7 +428,7 @@ namespace Nz
|
||||||
if (SDL_GetWindowID(window->m_handle) != event->key.windowID)
|
if (SDL_GetWindowID(window->m_handle) != event->key.windowID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
evt.type = WindowEventType_KeyPressed;
|
evt.type = WindowEventType::KeyPressed;
|
||||||
|
|
||||||
evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode);
|
evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode);
|
||||||
evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym);
|
evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym);
|
||||||
|
|
@ -446,7 +446,7 @@ namespace Nz
|
||||||
break;
|
break;
|
||||||
window->m_parent->PushEvent(evt);
|
window->m_parent->PushEvent(evt);
|
||||||
|
|
||||||
evt.type = WindowEventType_TextEntered;
|
evt.type = WindowEventType::TextEntered;
|
||||||
|
|
||||||
evt.text.character = U'\n';
|
evt.text.character = U'\n';
|
||||||
evt.text.repeated = event->key.repeat != 0;
|
evt.text.repeated = event->key.repeat != 0;
|
||||||
|
|
@ -457,7 +457,7 @@ namespace Nz
|
||||||
case Nz::Keyboard::VKey::Backspace:
|
case Nz::Keyboard::VKey::Backspace:
|
||||||
window->m_parent->PushEvent(evt);
|
window->m_parent->PushEvent(evt);
|
||||||
|
|
||||||
evt.type = WindowEventType_TextEntered;
|
evt.type = WindowEventType::TextEntered;
|
||||||
|
|
||||||
evt.text.character = U'\b';
|
evt.text.character = U'\b';
|
||||||
evt.text.repeated = event->key.repeat != 0;
|
evt.text.repeated = event->key.repeat != 0;
|
||||||
|
|
@ -475,7 +475,7 @@ namespace Nz
|
||||||
if (SDL_GetWindowID(window->m_handle) != event->key.windowID)
|
if (SDL_GetWindowID(window->m_handle) != event->key.windowID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
evt.type = WindowEventType_KeyReleased;
|
evt.type = WindowEventType::KeyReleased;
|
||||||
|
|
||||||
evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode);
|
evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode);
|
||||||
evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym);
|
evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym);
|
||||||
|
|
@ -492,7 +492,7 @@ namespace Nz
|
||||||
if (SDL_GetWindowID(window->m_handle) != event->text.windowID)
|
if (SDL_GetWindowID(window->m_handle) != event->text.windowID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
evt.type = WindowEventType_TextEntered;
|
evt.type = WindowEventType::TextEntered;
|
||||||
evt.text.repeated = false;
|
evt.text.repeated = false;
|
||||||
|
|
||||||
utf8::unchecked::iterator<const char*> it(event->text.text);
|
utf8::unchecked::iterator<const char*> it(event->text.text);
|
||||||
|
|
@ -504,7 +504,7 @@ namespace Nz
|
||||||
} while (*it++);
|
} while (*it++);
|
||||||
|
|
||||||
// prevent post switch event
|
// prevent post switch event
|
||||||
evt.type = WindowEventType::WindowEventType_Max;
|
evt.type = WindowEventType::Max;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -513,7 +513,7 @@ namespace Nz
|
||||||
if (SDL_GetWindowID(window->m_handle) != event->edit.windowID)
|
if (SDL_GetWindowID(window->m_handle) != event->edit.windowID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
evt.type = WindowEventType_TextEdited;
|
evt.type = WindowEventType::TextEdited;
|
||||||
evt.edit.length = event->edit.length;
|
evt.edit.length = event->edit.length;
|
||||||
window->m_lastEditEventLength = evt.edit.length;
|
window->m_lastEditEventLength = evt.edit.length;
|
||||||
|
|
||||||
|
|
@ -525,7 +525,7 @@ namespace Nz
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.type != WindowEventType::WindowEventType_Max)
|
if (evt.type != WindowEventType::Max)
|
||||||
window->m_parent->PushEvent(evt);
|
window->m_parent->PushEvent(evt);
|
||||||
}
|
}
|
||||||
catch (std::exception e)
|
catch (std::exception e)
|
||||||
|
|
|
||||||
|
|
@ -61,12 +61,12 @@ namespace Nz
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
// Inspired by the code of the SFML by Laurent Gomila (and its team)
|
// Inspired by the code of the SFML by Laurent Gomila (and its team)
|
||||||
if (style & WindowStyle_Fullscreen)
|
if (style & WindowStyle::Fullscreen)
|
||||||
{
|
{
|
||||||
if (fullscreenWindow)
|
if (fullscreenWindow)
|
||||||
{
|
{
|
||||||
NazaraError("Window " + PointerToString(fullscreenWindow) + " already in fullscreen mode");
|
NazaraError("Window " + PointerToString(fullscreenWindow) + " already in fullscreen mode");
|
||||||
style &= ~WindowStyle_Fullscreen;
|
style &= ~WindowStyle::Fullscreen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -79,10 +79,10 @@ namespace Nz
|
||||||
fullscreenWindow = this;
|
fullscreenWindow = this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (style & WindowStyle_Closable || style & WindowStyle_Resizable)
|
else if (style & WindowStyle::Closable || style & WindowStyle::Resizable)
|
||||||
style |= WindowStyle_Titlebar;
|
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);
|
std::unique_ptr<WindowImpl> impl = std::make_unique<WindowImpl>(this);
|
||||||
if (!impl->Create(mode, title, style))
|
if (!impl->Create(mode, title, style))
|
||||||
|
|
@ -152,7 +152,7 @@ namespace Nz
|
||||||
|
|
||||||
void Window::Destroy()
|
void Window::Destroy()
|
||||||
{
|
{
|
||||||
m_cursor.Reset();
|
m_cursor.reset();
|
||||||
|
|
||||||
if (m_impl)
|
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(m_impl, "Window not created");
|
||||||
NazaraAssert(cursor && cursor->IsValid(), "Invalid cursor");
|
NazaraAssert(cursor && cursor->IsValid(), "Invalid cursor");
|
||||||
|
|
@ -382,10 +382,10 @@ namespace Nz
|
||||||
m_impl->SetFocus();
|
m_impl->SetFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::SetIcon(IconRef icon)
|
void Window::SetIcon(std::shared_ptr<Icon> icon)
|
||||||
{
|
{
|
||||||
NazaraAssert(m_impl, "Window not created");
|
NazaraAssert(m_impl, "Window not created");
|
||||||
NazaraAssert(icon && icon.IsValid(), "Invalid icon");
|
NazaraAssert(icon, "Invalid icon");
|
||||||
|
|
||||||
m_icon = std::move(icon);
|
m_icon = std::move(icon);
|
||||||
m_impl->SetIcon(*m_icon);
|
m_impl->SetIcon(*m_icon);
|
||||||
|
|
@ -629,7 +629,7 @@ namespace Nz
|
||||||
|
|
||||||
void Window::ConnectSlots()
|
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())
|
if (IsValid())
|
||||||
SetCursor(cursor);
|
SetCursor(cursor);
|
||||||
|
|
@ -663,15 +663,15 @@ namespace Nz
|
||||||
|
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case WindowEventType_MouseEntered:
|
case WindowEventType::MouseEntered:
|
||||||
m_impl->RefreshCursor();
|
m_impl->RefreshCursor();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_Resized:
|
case WindowEventType::Resized:
|
||||||
OnWindowResized();
|
OnWindowResized();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowEventType_Quit:
|
case WindowEventType::Quit:
|
||||||
if (m_closeOnQuit)
|
if (m_closeOnQuit)
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,22 @@
|
||||||
#include <Nazara/Core/ObjectRef.hpp>
|
#include <Nazara/Core/ObjectRef.hpp>
|
||||||
#include <Catch/catch.hpp>
|
#include <Catch/catch.hpp>
|
||||||
|
|
||||||
#include <Nazara/Utility/Font.hpp>
|
class Test : public Nz::RefCounted
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
SCENARIO("ObjectRef", "[CORE][OBJECTREF]")
|
SCENARIO("ObjectRef", "[CORE][OBJECTREF]")
|
||||||
{
|
{
|
||||||
GIVEN("A ObjectRef")
|
GIVEN("A ObjectRef")
|
||||||
{
|
{
|
||||||
Nz::ObjectRef<Nz::Font> objectRef;
|
Nz::ObjectRef<Test> objectRef;
|
||||||
|
|
||||||
WHEN("We have two objectRef handling the same object")
|
WHEN("We have two objectRef handling the same object")
|
||||||
{
|
{
|
||||||
Nz::Font font;
|
Test test;
|
||||||
|
|
||||||
objectRef = &font;
|
objectRef = &test;
|
||||||
Nz::ObjectRef<Nz::Font> otherRef(&font);
|
Nz::ObjectRef<Test> otherRef(&test);
|
||||||
|
|
||||||
THEN("Pointers the same")
|
THEN("Pointers the same")
|
||||||
{
|
{
|
||||||
|
|
@ -27,11 +29,11 @@ SCENARIO("ObjectRef", "[CORE][OBJECTREF]")
|
||||||
|
|
||||||
WHEN("We assign it to a simple font")
|
WHEN("We assign it to a simple font")
|
||||||
{
|
{
|
||||||
Nz::Font font;
|
Test test;
|
||||||
|
|
||||||
THEN("Release suppress the reference to the object")
|
THEN("Release suppress the reference to the object")
|
||||||
{
|
{
|
||||||
objectRef.Reset(&font);
|
objectRef.Reset(&test);
|
||||||
objectRef.Release();
|
objectRef.Release();
|
||||||
|
|
||||||
REQUIRE(!objectRef.IsValid());
|
REQUIRE(!objectRef.IsValid());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue