[deploy] Add Cloneable
This commit is contained in:
parent
659093b45f
commit
781d1a2f6c
|
|
@ -15,6 +15,7 @@
|
|||
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Allocator.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Any.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Cloneable.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Common.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Director.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\event\Event.h" />
|
||||
|
|
|
|||
|
|
@ -321,6 +321,9 @@
|
|||
<ClInclude Include="..\..\src\kiwano\core\Allocator.h">
|
||||
<Filter>core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\core\Cloneable.h">
|
||||
<Filter>core</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ void Action::Restart(Actor* target)
|
|||
Init(target);
|
||||
}
|
||||
|
||||
ActionPtr Action::InnerClone(ActionPtr to) const
|
||||
ActionPtr Action::DoClone(ActionPtr to) const
|
||||
{
|
||||
if (to)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Cloneable.h>
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
#include <kiwano/core/SmartPtr.hpp>
|
||||
#include <kiwano/core/Time.h>
|
||||
|
|
@ -51,6 +52,7 @@ typedef IntrusiveList<ActionPtr> ActionList;
|
|||
/// @brief 动画
|
||||
class KGE_API Action
|
||||
: public ObjectBase
|
||||
, public Cloneable<Action>
|
||||
, protected IntrusiveListValue<ActionPtr>
|
||||
{
|
||||
friend class ActionManager;
|
||||
|
|
@ -99,10 +101,6 @@ public:
|
|||
/// @brief 设置动画循环结束时的回调函数
|
||||
void SetLoopDoneCallback(const DoneCallback& cb);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的拷贝
|
||||
virtual ActionPtr Clone() const = 0;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的倒转
|
||||
virtual ActionPtr Reverse() const = 0;
|
||||
|
|
@ -184,7 +182,7 @@ protected:
|
|||
bool IsRemoveable() const;
|
||||
|
||||
protected:
|
||||
ActionPtr InnerClone(ActionPtr to) const;
|
||||
ActionPtr DoClone(ActionPtr to) const;
|
||||
|
||||
private:
|
||||
Status status_;
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ ActionDelayPtr ActionDelay::Create(Duration delay)
|
|||
|
||||
ActionPtr ActionDelay::Clone() const
|
||||
{
|
||||
return InnerClone(ActionDelay::Create(GetDelay()));
|
||||
return DoClone(ActionDelay::Create(GetDelay()));
|
||||
}
|
||||
|
||||
ActionPtr ActionDelay::Reverse() const
|
||||
{
|
||||
return InnerClone(ActionDelay::Create(GetDelay()));
|
||||
return DoClone(ActionDelay::Create(GetDelay()));
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ ActionPtr ActionGroup::Clone() const
|
|||
actions.push_back(action->Clone());
|
||||
}
|
||||
}
|
||||
return InnerClone(ActionGroup::Create(actions, sync_));
|
||||
return DoClone(ActionGroup::Create(actions, sync_));
|
||||
}
|
||||
|
||||
ActionPtr ActionGroup::Reverse() const
|
||||
|
|
@ -146,7 +146,7 @@ ActionPtr ActionGroup::Reverse() const
|
|||
actions.push_back(action->Reverse());
|
||||
}
|
||||
}
|
||||
return InnerClone(ActionGroup::Create(actions, sync_));
|
||||
return DoClone(ActionGroup::Create(actions, sync_));
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -129,15 +129,14 @@ void ActionTween::Update(Actor* target, Duration dt)
|
|||
UpdateTween(target, percent);
|
||||
}
|
||||
|
||||
ActionPtr ActionTween::InnerClone(ActionTweenPtr to) const
|
||||
ActionPtr ActionTween::DoClone(ActionTweenPtr to) const
|
||||
{
|
||||
if (to)
|
||||
{
|
||||
(void)Action::InnerClone(to);
|
||||
to->SetDuration(this->GetDuration());
|
||||
to->SetEaseFunc(this->GetEaseFunc());
|
||||
}
|
||||
return to;
|
||||
return Action::DoClone(to);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
|
@ -178,12 +177,12 @@ void ActionMoveBy::UpdateTween(Actor* target, float percent)
|
|||
|
||||
ActionPtr ActionMoveBy::Clone() const
|
||||
{
|
||||
return InnerClone(ActionMoveBy::Create(GetDuration(), displacement_));
|
||||
return DoClone(ActionMoveBy::Create(GetDuration(), displacement_));
|
||||
}
|
||||
|
||||
ActionPtr ActionMoveBy::Reverse() const
|
||||
{
|
||||
return InnerClone(ActionMoveBy::Create(GetDuration(), -displacement_));
|
||||
return DoClone(ActionMoveBy::Create(GetDuration(), -displacement_));
|
||||
}
|
||||
|
||||
ActionMoveToPtr ActionMoveTo::Create(Duration duration, const Point& distination)
|
||||
|
|
@ -201,7 +200,7 @@ ActionMoveTo::ActionMoveTo() {}
|
|||
|
||||
ActionPtr ActionMoveTo::Clone() const
|
||||
{
|
||||
return InnerClone(ActionMoveTo::Create(GetDuration(), distination_));
|
||||
return DoClone(ActionMoveTo::Create(GetDuration(), distination_));
|
||||
}
|
||||
|
||||
void ActionMoveTo::Init(Actor* target)
|
||||
|
|
@ -237,12 +236,12 @@ ActionJumpBy::ActionJumpBy()
|
|||
|
||||
ActionPtr ActionJumpBy::Clone() const
|
||||
{
|
||||
return InnerClone(ActionJumpBy::Create(GetDuration(), displacement_, height_, jump_count_));
|
||||
return DoClone(ActionJumpBy::Create(GetDuration(), displacement_, height_, jump_count_));
|
||||
}
|
||||
|
||||
ActionPtr ActionJumpBy::Reverse() const
|
||||
{
|
||||
return InnerClone(ActionJumpBy::Create(GetDuration(), -displacement_, height_, jump_count_));
|
||||
return DoClone(ActionJumpBy::Create(GetDuration(), -displacement_, height_, jump_count_));
|
||||
}
|
||||
|
||||
void ActionJumpBy::Init(Actor* target)
|
||||
|
|
@ -288,7 +287,7 @@ ActionJumpTo::ActionJumpTo() {}
|
|||
|
||||
ActionPtr ActionJumpTo::Clone() const
|
||||
{
|
||||
return InnerClone(ActionJumpTo::Create(GetDuration(), distination_, height_, jump_count_));
|
||||
return DoClone(ActionJumpTo::Create(GetDuration(), distination_, height_, jump_count_));
|
||||
}
|
||||
|
||||
void ActionJumpTo::Init(Actor* target)
|
||||
|
|
@ -337,12 +336,12 @@ void ActionScaleBy::UpdateTween(Actor* target, float percent)
|
|||
|
||||
ActionPtr ActionScaleBy::Clone() const
|
||||
{
|
||||
return InnerClone(ActionScaleBy::Create(GetDuration(), delta_x_, delta_y_));
|
||||
return DoClone(ActionScaleBy::Create(GetDuration(), delta_x_, delta_y_));
|
||||
}
|
||||
|
||||
ActionPtr ActionScaleBy::Reverse() const
|
||||
{
|
||||
return InnerClone(ActionScaleBy::Create(GetDuration(), -delta_x_, -delta_y_));
|
||||
return DoClone(ActionScaleBy::Create(GetDuration(), -delta_x_, -delta_y_));
|
||||
}
|
||||
|
||||
ActionScaleToPtr ActionScaleTo::Create(Duration duration, float scale_x, float scale_y)
|
||||
|
|
@ -365,7 +364,7 @@ ActionScaleTo::ActionScaleTo()
|
|||
|
||||
ActionPtr ActionScaleTo::Clone() const
|
||||
{
|
||||
return InnerClone(ActionScaleTo::Create(GetDuration(), end_scale_x_, end_scale_y_));
|
||||
return DoClone(ActionScaleTo::Create(GetDuration(), end_scale_x_, end_scale_y_));
|
||||
}
|
||||
|
||||
void ActionScaleTo::Init(Actor* target)
|
||||
|
|
@ -413,7 +412,7 @@ void ActionFadeTo::UpdateTween(Actor* target, float percent)
|
|||
|
||||
ActionPtr ActionFadeTo::Clone() const
|
||||
{
|
||||
return InnerClone(ActionFadeTo::Create(GetDuration(), end_val_));
|
||||
return DoClone(ActionFadeTo::Create(GetDuration(), end_val_));
|
||||
}
|
||||
|
||||
ActionFadeInPtr ActionFadeIn::Create(Duration duration)
|
||||
|
|
@ -478,12 +477,12 @@ void ActionRotateBy::UpdateTween(Actor* target, float percent)
|
|||
|
||||
ActionPtr ActionRotateBy::Clone() const
|
||||
{
|
||||
return InnerClone(ActionRotateBy::Create(GetDuration(), delta_val_));
|
||||
return DoClone(ActionRotateBy::Create(GetDuration(), delta_val_));
|
||||
}
|
||||
|
||||
ActionPtr ActionRotateBy::Reverse() const
|
||||
{
|
||||
return InnerClone(ActionRotateBy::Create(GetDuration(), -delta_val_));
|
||||
return DoClone(ActionRotateBy::Create(GetDuration(), -delta_val_));
|
||||
}
|
||||
|
||||
ActionRotateToPtr ActionRotateTo::Create(Duration duration, float rotation)
|
||||
|
|
@ -504,7 +503,7 @@ ActionRotateTo::ActionRotateTo()
|
|||
|
||||
ActionPtr ActionRotateTo::Clone() const
|
||||
{
|
||||
return InnerClone(ActionRotateTo::Create(GetDuration(), end_val_));
|
||||
return DoClone(ActionRotateTo::Create(GetDuration(), end_val_));
|
||||
}
|
||||
|
||||
void ActionRotateTo::Init(Actor* target)
|
||||
|
|
@ -532,7 +531,7 @@ ActionCustom::ActionCustom() {}
|
|||
|
||||
ActionPtr ActionCustom::Clone() const
|
||||
{
|
||||
return InnerClone(ActionCustom::Create(GetDuration(), tween_func_));
|
||||
return DoClone(ActionCustom::Create(GetDuration(), tween_func_));
|
||||
}
|
||||
|
||||
void ActionCustom::Init(Actor* target)
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ protected:
|
|||
|
||||
virtual void UpdateTween(Actor* target, float percent) = 0;
|
||||
|
||||
ActionPtr InnerClone(ActionTweenPtr to) const;
|
||||
ActionPtr DoClone(ActionTweenPtr to) const;
|
||||
|
||||
private:
|
||||
Duration dur_;
|
||||
|
|
|
|||
|
|
@ -48,12 +48,12 @@ ActionWalk::ActionWalk()
|
|||
|
||||
ActionPtr ActionWalk::Clone() const
|
||||
{
|
||||
return InnerClone(ActionWalk::Create(GetDuration(), path_, rotating_, start_, end_));
|
||||
return DoClone(ActionWalk::Create(GetDuration(), path_, rotating_, start_, end_));
|
||||
}
|
||||
|
||||
ActionPtr ActionWalk::Reverse() const
|
||||
{
|
||||
return InnerClone(ActionWalk::Create(GetDuration(), path_, rotating_, end_, start_));
|
||||
return DoClone(ActionWalk::Create(GetDuration(), path_, rotating_, end_, start_));
|
||||
}
|
||||
|
||||
void ActionWalk::Init(Actor* target)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ ActionPtr Animation::Clone() const
|
|||
{
|
||||
if (frame_seq_)
|
||||
{
|
||||
return InnerClone(Animation::Create(GetDuration(), frame_seq_));
|
||||
return DoClone(Animation::Create(GetDuration(), frame_seq_));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ ActionPtr Animation::Reverse() const
|
|||
FrameSequencePtr frames = frame_seq_->Reverse();
|
||||
if (frames)
|
||||
{
|
||||
return InnerClone(Animation::Create(GetDuration(), frames));
|
||||
return DoClone(Animation::Create(GetDuration(), frames));
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) 2016-2018 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/SmartPtr.hpp>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
template <typename _Ty>
|
||||
class Cloneable
|
||||
{
|
||||
public:
|
||||
virtual SmartPtr<_Ty> Clone() const = 0;
|
||||
|
||||
protected:
|
||||
Cloneable() = default;
|
||||
|
||||
private:
|
||||
Cloneable(const Cloneable&) = delete;
|
||||
|
||||
Cloneable& operator=(const Cloneable&) = delete;
|
||||
};
|
||||
|
||||
} // namespace kiwano
|
||||
Loading…
Reference in New Issue