add Sprite::FrameProperty
This commit is contained in:
parent
439cd29026
commit
ea67276033
|
|
@ -502,6 +502,13 @@ public:
|
|||
return Property<Point, FlagUint8>(&transform_.skew, &dirty_flag_, DirtyFlag::DirtyTransform);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取Z轴顺序属性
|
||||
inline Property<int, Function<void()>> ZOrderProperty()
|
||||
{
|
||||
return Property<int, Function<void()>>(&z_order_, Closure(this, &Actor::Reorder));
|
||||
}
|
||||
|
||||
protected:
|
||||
/// \~chinese
|
||||
/// @brief 更新自身和所有子角色
|
||||
|
|
|
|||
|
|
@ -128,13 +128,25 @@ void Sprite::SetFrame(FramePtr frame, bool autoresize)
|
|||
if (frame_ != frame)
|
||||
{
|
||||
frame_ = frame;
|
||||
if (frame_ && autoresize)
|
||||
if (autoresize)
|
||||
{
|
||||
SetSize(frame_->GetSize());
|
||||
ResetSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::ResetSize()
|
||||
{
|
||||
if (frame_)
|
||||
{
|
||||
SetSize(frame_->GetSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
SetSize(Size());
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::OnRender(RenderContext& ctx)
|
||||
{
|
||||
if (frame_ && frame_->IsValid())
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
KGE_DECLARE_SMART_PTR(Sprite);
|
||||
|
||||
/**
|
||||
|
|
@ -112,6 +113,17 @@ public:
|
|||
/// @param autoresize 是否自动调整自身大小为图像大小
|
||||
void SetFrame(FramePtr frame, bool autoresize = true);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重置精灵大小为图像帧大小
|
||||
void ResetSize();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取图像帧属性
|
||||
inline Property<FramePtr, Function<void()>> FrameProperty()
|
||||
{
|
||||
return Property<FramePtr, Function<void()>>(std::addressof(frame_), Closure(this, &Sprite::ResetSize));
|
||||
}
|
||||
|
||||
void OnRender(RenderContext& ctx) override;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -80,155 +80,4 @@ typedef Flag<int16_t> FlagInt16;
|
|||
typedef Flag<int32_t> FlagInt32;
|
||||
typedef Flag<int64_t> FlagInt64;
|
||||
|
||||
namespace bits
|
||||
{
|
||||
|
||||
template <>
|
||||
inline void Set<FlagUint8>(FlagUint8& old, FlagUint8 flag)
|
||||
{
|
||||
old.Set(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Set<FlagUint16>(FlagUint16& old, FlagUint16 flag)
|
||||
{
|
||||
old.Set(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Set<FlagUint32>(FlagUint32& old, FlagUint32 flag)
|
||||
{
|
||||
old.Set(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Set<FlagUint64>(FlagUint64& old, FlagUint64 flag)
|
||||
{
|
||||
old.Set(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Set<FlagInt8>(FlagInt8& old, FlagInt8 flag)
|
||||
{
|
||||
old.Set(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Set<FlagInt16>(FlagInt16& old, FlagInt16 flag)
|
||||
{
|
||||
old.Set(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Set<FlagInt32>(FlagInt32& old, FlagInt32 flag)
|
||||
{
|
||||
old.Set(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Set<FlagInt64>(FlagInt64& old, FlagInt64 flag)
|
||||
{
|
||||
old.Set(flag.value);
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
inline void Unset<FlagUint8>(FlagUint8& old, FlagUint8 flag)
|
||||
{
|
||||
old.Unset(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Unset<FlagUint16>(FlagUint16& old, FlagUint16 flag)
|
||||
{
|
||||
old.Unset(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Unset<FlagUint32>(FlagUint32& old, FlagUint32 flag)
|
||||
{
|
||||
old.Unset(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Unset<FlagUint64>(FlagUint64& old, FlagUint64 flag)
|
||||
{
|
||||
old.Unset(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Unset<FlagInt8>(FlagInt8& old, FlagInt8 flag)
|
||||
{
|
||||
old.Unset(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Unset<FlagInt16>(FlagInt16& old, FlagInt16 flag)
|
||||
{
|
||||
old.Unset(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Unset<FlagInt32>(FlagInt32& old, FlagInt32 flag)
|
||||
{
|
||||
old.Unset(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Unset<FlagInt64>(FlagInt64& old, FlagInt64 flag)
|
||||
{
|
||||
old.Unset(flag.value);
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
inline bool Has<FlagUint8>(FlagUint8 old, FlagUint8 flag)
|
||||
{
|
||||
return old.Has(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool Has<FlagUint16>(FlagUint16 old, FlagUint16 flag)
|
||||
{
|
||||
return old.Has(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool Has<FlagUint32>(FlagUint32 old, FlagUint32 flag)
|
||||
{
|
||||
return old.Has(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool Has<FlagUint64>(FlagUint64 old, FlagUint64 flag)
|
||||
{
|
||||
return old.Has(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool Has<FlagInt8>(FlagInt8 old, FlagInt8 flag)
|
||||
{
|
||||
return old.Has(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool Has<FlagInt16>(FlagInt16 old, FlagInt16 flag)
|
||||
{
|
||||
return old.Has(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool Has<FlagInt32>(FlagInt32 old, FlagInt32 flag)
|
||||
{
|
||||
return old.Has(flag.value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool Has<FlagInt64>(FlagInt64 old, FlagInt64 flag)
|
||||
{
|
||||
return old.Has(flag.value);
|
||||
}
|
||||
|
||||
|
||||
} // namespace bits
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#pragma once
|
||||
#include <kiwano/core/BitOperator.h>
|
||||
#include <kiwano/core/Flag.h>
|
||||
#include <kiwano/core/Function.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -33,7 +34,8 @@ template <typename _Ty>
|
|||
class Property<_Ty, void>
|
||||
{
|
||||
public:
|
||||
typedef _Ty value_type;
|
||||
typedef _Ty value_type;
|
||||
typedef void notifier_type;
|
||||
|
||||
inline Property(_Ty* ptr)
|
||||
: ptr_(ptr)
|
||||
|
|
@ -55,20 +57,83 @@ private:
|
|||
};
|
||||
|
||||
|
||||
template <typename _Ty, typename _FlagTy>
|
||||
class Property<_Ty, Flag<_FlagTy>>
|
||||
{
|
||||
public:
|
||||
typedef _Ty value_type;
|
||||
typedef Flag<_FlagTy> notifier_type;
|
||||
|
||||
inline Property(_Ty* ptr, Flag<_FlagTy>* flag, _FlagTy flag_value)
|
||||
: ptr_(ptr)
|
||||
, flag_(flag)
|
||||
, flag_value_(flag_value)
|
||||
{
|
||||
}
|
||||
|
||||
inline _Ty Get() const
|
||||
{
|
||||
return *ptr_;
|
||||
}
|
||||
|
||||
inline void Set(const _Ty& value)
|
||||
{
|
||||
*ptr_ = value;
|
||||
if (flag_)
|
||||
{
|
||||
flag_->Set(flag_value_);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
_Ty* ptr_;
|
||||
Flag<_FlagTy>* flag_;
|
||||
_FlagTy flag_value_;
|
||||
};
|
||||
|
||||
|
||||
template <typename _Ty>
|
||||
class Property<_Ty, Function<void()>>
|
||||
{
|
||||
public:
|
||||
typedef _Ty value_type;
|
||||
typedef Function<void()> notifier_type;
|
||||
|
||||
inline Property(_Ty* ptr, const Function<void()>& notifier)
|
||||
: ptr_(ptr)
|
||||
, notifier_(notifier)
|
||||
{
|
||||
}
|
||||
|
||||
inline _Ty Get() const
|
||||
{
|
||||
return *ptr_;
|
||||
}
|
||||
|
||||
inline void Set(const _Ty& value)
|
||||
{
|
||||
*ptr_ = value;
|
||||
if (notifier_)
|
||||
{
|
||||
notifier_();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
_Ty* ptr_;
|
||||
Function<void()> notifier_;
|
||||
};
|
||||
|
||||
|
||||
template <typename _Ty, typename _NotifierTy>
|
||||
class Property
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_arithmetic<_NotifierTy>::value, "_NotifierTy must be an arithmetic type");
|
||||
|
||||
typedef _Ty value_type;
|
||||
typedef _NotifierTy notifier_type;
|
||||
|
||||
inline Property(_Ty* ptr)
|
||||
: ptr_(ptr)
|
||||
, notifier_(nullptr)
|
||||
, notify_value_()
|
||||
{
|
||||
}
|
||||
|
||||
inline Property(_Ty* ptr, _NotifierTy* notifier, _NotifierTy notify_value)
|
||||
: ptr_(ptr)
|
||||
, notifier_(notifier)
|
||||
|
|
|
|||
Loading…
Reference in New Issue