Utility/Icon: Make Icon a RefCounted object
This commit is contained in:
parent
439f8d0033
commit
e4b6f8e126
|
|
@ -8,6 +8,7 @@
|
|||
#define NAZARA_ICON_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
|
||||
|
|
@ -16,22 +17,29 @@ namespace Nz
|
|||
class Image;
|
||||
class IconImpl;
|
||||
|
||||
class NAZARA_UTILITY_API Icon
|
||||
class Icon;
|
||||
|
||||
using IconRef = ObjectRef<Icon>;
|
||||
|
||||
class NAZARA_UTILITY_API Icon : public RefCounted
|
||||
{
|
||||
friend class WindowImpl;
|
||||
|
||||
public:
|
||||
Icon();
|
||||
~Icon();
|
||||
inline Icon();
|
||||
inline explicit Icon(const Image& icon);
|
||||
inline ~Icon();
|
||||
|
||||
bool Create(const Image& icon);
|
||||
void Destroy();
|
||||
|
||||
bool IsValid() const;
|
||||
inline bool IsValid() const;
|
||||
|
||||
private:
|
||||
IconImpl* m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/Icon.inl>
|
||||
|
||||
#endif // NAZARA_ICON_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Cursor.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
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
|
||||
{
|
||||
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/Utility/DebugOff.hpp>
|
||||
|
|
@ -15,18 +15,18 @@
|
|||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Cursor.hpp>
|
||||
#include <Nazara/Utility/CursorController.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/EventHandler.hpp>
|
||||
#include <Nazara/Utility/Icon.hpp>
|
||||
#include <Nazara/Utility/VideoMode.hpp>
|
||||
#include <Nazara/Utility/WindowHandle.hpp>
|
||||
#include <queue>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Cursor;
|
||||
class Image;
|
||||
class Icon;
|
||||
class WindowImpl;
|
||||
|
||||
class NAZARA_UTILITY_API Window
|
||||
|
|
@ -86,7 +86,7 @@ namespace Nz
|
|||
inline void SetCursor(SystemCursor systemCursor);
|
||||
void SetEventListener(bool listener);
|
||||
void SetFocus();
|
||||
void SetIcon(const Icon& icon);
|
||||
void SetIcon(IconRef icon);
|
||||
void SetMaximumSize(const Vector2i& maxSize);
|
||||
void SetMaximumSize(int width, int height);
|
||||
void SetMinimumSize(const Vector2i& minSize);
|
||||
|
|
@ -126,6 +126,7 @@ namespace Nz
|
|||
CursorController m_cursorController;
|
||||
CursorRef m_cursor;
|
||||
EventHandler m_eventHandler;
|
||||
IconRef m_icon;
|
||||
Mutex m_eventMutex;
|
||||
Mutex m_eventConditionMutex;
|
||||
bool m_asyncWindow;
|
||||
|
|
|
|||
|
|
@ -16,30 +16,19 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
Icon::Icon() :
|
||||
m_impl(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Icon::~Icon()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool Icon::Create(const Image& icon)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_impl = new IconImpl;
|
||||
if (!m_impl->Create(icon))
|
||||
std::unique_ptr<IconImpl> impl(new IconImpl);
|
||||
if (!impl->Create(icon))
|
||||
{
|
||||
NazaraError("Failed to create icon implementation");
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_impl = impl.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -53,9 +42,4 @@ namespace Nz
|
|||
m_impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool Icon::IsValid() const
|
||||
{
|
||||
return m_impl != nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -408,23 +408,13 @@ namespace Nz
|
|||
m_impl->SetFocus();
|
||||
}
|
||||
|
||||
void Window::SetIcon(const Icon& icon)
|
||||
void Window::SetIcon(IconRef icon)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Window not created");
|
||||
return;
|
||||
}
|
||||
NazaraAssert(m_impl, "Window not created");
|
||||
NazaraAssert(icon && icon.IsValid(), "Invalid icon");
|
||||
|
||||
if (!icon.IsValid())
|
||||
{
|
||||
NazaraError("Icon is not valid");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_impl->SetIcon(icon);
|
||||
m_icon = std::move(icon);
|
||||
m_impl->SetIcon(*m_icon);
|
||||
}
|
||||
|
||||
void Window::SetMaximumSize(const Vector2i& maxSize)
|
||||
|
|
|
|||
Loading…
Reference in New Issue