[deploy] remove Value & ValueObserver
This commit is contained in:
parent
66e6f75290
commit
cbe454c4ad
|
|
@ -45,7 +45,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Singleton.h" />
|
<ClInclude Include="..\..\src\kiwano\core\Singleton.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\String.h" />
|
<ClInclude Include="..\..\src\kiwano\core\String.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Time.h" />
|
<ClInclude Include="..\..\src\kiwano\core\Time.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Value.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano\event\Event.h" />
|
<ClInclude Include="..\..\src\kiwano\event\Event.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\event\EventDispatcher.h" />
|
<ClInclude Include="..\..\src\kiwano\event\EventDispatcher.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\event\EventListener.h" />
|
<ClInclude Include="..\..\src\kiwano\event\EventListener.h" />
|
||||||
|
|
|
||||||
|
|
@ -336,9 +336,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Flag.h">
|
<ClInclude Include="..\..\src\kiwano\core\Flag.h">
|
||||||
<Filter>core</Filter>
|
<Filter>core</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Value.h">
|
|
||||||
<Filter>core</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\animation\EaseFunc.h">
|
<ClInclude Include="..\..\src\kiwano\2d\animation\EaseFunc.h">
|
||||||
<Filter>2d\animation</Filter>
|
<Filter>2d\animation</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
||||||
|
|
@ -446,69 +446,6 @@ public:
|
||||||
/// @brief 设置默认锚点
|
/// @brief 设置默认锚点
|
||||||
static void SetDefaultAnchor(float anchor_x, float anchor_y);
|
static void SetDefaultAnchor(float anchor_x, float anchor_y);
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取可见性属性
|
|
||||||
inline Value<bool> VisibleProperty()
|
|
||||||
{
|
|
||||||
return Value<bool>(visible_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取不透明度属性
|
|
||||||
inline Value<float, FlagUint8> OpacityProperty()
|
|
||||||
{
|
|
||||||
return Value<float, FlagUint8>(opacity_, { dirty_flag_, DirtyFlag::DirtyOpacity });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取锚点属性
|
|
||||||
inline Value<Point, FlagUint8> AnchorProperty()
|
|
||||||
{
|
|
||||||
return Value<Point, FlagUint8>(anchor_, { dirty_flag_, DirtyFlag::DirtyTransform });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取大小属性
|
|
||||||
inline Value<Size, FlagUint8> SizeProperty()
|
|
||||||
{
|
|
||||||
return Value<Size, FlagUint8>(size_, { dirty_flag_, DirtyFlag::DirtyTransform });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取位置属性
|
|
||||||
inline Value<Point, FlagUint8> PositionProperty()
|
|
||||||
{
|
|
||||||
return Value<Point, FlagUint8>(transform_.position, { dirty_flag_, DirtyFlag::DirtyTransform });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取旋转角度属性
|
|
||||||
inline Value<float, FlagUint8> RotationProperty()
|
|
||||||
{
|
|
||||||
return Value<float, FlagUint8>(transform_.rotation, { dirty_flag_, DirtyFlag::DirtyTransform });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取缩放属性
|
|
||||||
inline Value<Point, FlagUint8> ScaleProperty()
|
|
||||||
{
|
|
||||||
return Value<Point, FlagUint8>(transform_.scale, { dirty_flag_, DirtyFlag::DirtyTransform });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取错切角度属性
|
|
||||||
inline Value<Point, FlagUint8> SkewProperty()
|
|
||||||
{
|
|
||||||
return Value<Point, FlagUint8>(transform_.skew, { dirty_flag_, DirtyFlag::DirtyTransform });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取Z轴顺序属性
|
|
||||||
inline Value<int, Function<void()>> ZOrderProperty()
|
|
||||||
{
|
|
||||||
return Value<int, Function<void()>>(z_order_, Closure(this, &Actor::Reorder));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新自身和所有子角色
|
/// @brief 更新自身和所有子角色
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@
|
||||||
#include <kiwano/core/Allocator.h>
|
#include <kiwano/core/Allocator.h>
|
||||||
#include <kiwano/core/BitOperator.h>
|
#include <kiwano/core/BitOperator.h>
|
||||||
#include <kiwano/core/Flag.h>
|
#include <kiwano/core/Flag.h>
|
||||||
#include <kiwano/core/Value.h>
|
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,148 +0,0 @@
|
||||||
// Copyright (c) 2019-2020 Kiwano - Nomango
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
|
||||||
// in the Software without restriction, including without limitation the rights
|
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
// THE SOFTWARE.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <kiwano/core/Function.h>
|
|
||||||
#include <kiwano/core/BitOperator.h>
|
|
||||||
#include <kiwano/core/Flag.h>
|
|
||||||
|
|
||||||
namespace kiwano
|
|
||||||
{
|
|
||||||
|
|
||||||
template <typename _Ty, typename _FlagTy>
|
|
||||||
struct ValueObserver;
|
|
||||||
|
|
||||||
template <typename _Ty, typename _FlagTy>
|
|
||||||
struct ValueObserver
|
|
||||||
{
|
|
||||||
static_assert(std::is_arithmetic<_FlagTy>::value, "_Ty must be an arithmetic type");
|
|
||||||
|
|
||||||
inline ValueObserver(_FlagTy& observer, _FlagTy value)
|
|
||||||
: observer(observer)
|
|
||||||
, value(value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Changed(const _Ty& old_val, const _Ty& new_val)
|
|
||||||
{
|
|
||||||
bits::Set(observer, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
_FlagTy& observer;
|
|
||||||
_FlagTy value;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename _Ty, typename _FlagTy>
|
|
||||||
struct ValueObserver<_Ty, Flag<_FlagTy>>
|
|
||||||
{
|
|
||||||
inline ValueObserver(Flag<_FlagTy>& flag, _FlagTy flag_value)
|
|
||||||
: flag(flag)
|
|
||||||
, flag_value(flag_value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Changed(const _Ty& old_val, const _Ty& new_val)
|
|
||||||
{
|
|
||||||
flag.Set(flag_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Flag<_FlagTy>& flag;
|
|
||||||
_FlagTy flag_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename _Ty>
|
|
||||||
struct ValueObserver<_Ty, Function<void()>>
|
|
||||||
{
|
|
||||||
inline ValueObserver(const Function<void()>& callback)
|
|
||||||
: callback(callback)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Changed(const _Ty& old_val, const _Ty& new_val)
|
|
||||||
{
|
|
||||||
if (callback)
|
|
||||||
{
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Function<void()> callback;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename _Ty, typename _ObserverTy = void>
|
|
||||||
class Value;
|
|
||||||
|
|
||||||
template <typename _Ty>
|
|
||||||
class Value<_Ty, void>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef _Ty value_type;
|
|
||||||
typedef void observer_type;
|
|
||||||
|
|
||||||
inline Value(_Ty& ptr)
|
|
||||||
: ptr_(ptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const _Ty& Get() const
|
|
||||||
{
|
|
||||||
return ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Set(const _Ty& value)
|
|
||||||
{
|
|
||||||
ptr_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
_Ty& ptr_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename _Ty, typename _ObserverTy>
|
|
||||||
class Value
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef _Ty value_type;
|
|
||||||
|
|
||||||
typedef ValueObserver<_Ty, _ObserverTy> observer_type;
|
|
||||||
|
|
||||||
inline Value(_Ty& ptr, const observer_type& observer)
|
|
||||||
: ptr_(ptr)
|
|
||||||
, observer_(observer)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const _Ty& Get() const
|
|
||||||
{
|
|
||||||
return ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Set(const _Ty& value)
|
|
||||||
{
|
|
||||||
ptr_ = value;
|
|
||||||
observer_.Changed(ptr_, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
_Ty& ptr_;
|
|
||||||
observer_type observer_;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue