diff --git a/Kiwano/2d/ActionHelper.h b/Kiwano/2d/ActionHelper.h index 5e1ad8b4..3e8ac5be 100644 --- a/Kiwano/2d/ActionHelper.h +++ b/Kiwano/2d/ActionHelper.h @@ -46,9 +46,9 @@ namespace kiwano inline ActionHelper& SetName(String const& name) { base->SetName(name); return (*this); } // 获取指针 - inline ActionPtr Get() const { return base; } + inline ActionPtr Get() const { return base; } - inline ActionHelper(ActionPtr base) : base(base) {} + inline ActionHelper(ActionPtr base) : base(base) {} inline operator ActionPtr() const { return base; } @@ -154,15 +154,9 @@ namespace kiwano } static inline TweenHelper - OpacityBy(float opacity) + FadeTo(float opacity) { - return TweenHelper(new kiwano::ActionOpacityBy(0, opacity)); - } - - static inline TweenHelper - OpacityTo(float opacity) - { - return TweenHelper(new kiwano::ActionOpacityTo(0, opacity)); + return TweenHelper(new kiwano::ActionFadeTo(0, opacity)); } static inline TweenHelper @@ -232,6 +226,21 @@ namespace kiwano #pragma warning(push) #pragma warning(disable : 4996) + KGE_DEPRECATED("Tween::OpacityBy has been removed, use Tween::FadeTo instead") + static inline TweenHelper + OpacityBy(float opacity) + { + KGE_ASSERT("Tween::OpacityBy has been removed, use Tween::FadeTo instead"); + return TweenHelper(nullptr); + } + + KGE_DEPRECATED("Tween::OpacityTo is deprecated, use Tween::FadeTo instead") + static inline TweenHelper + OpacityTo(float opacity) + { + return TweenHelper(new kiwano::ActionFadeTo(0, opacity)); + } + KGE_DEPRECATED("Tween::Sequence is deprecated, use Tween::Group instead") static inline ActionHelper Sequence(Array const& actions) diff --git a/Kiwano/2d/ActionTween.cpp b/Kiwano/2d/ActionTween.cpp index 13fd5e1a..21804465 100644 --- a/Kiwano/2d/ActionTween.cpp +++ b/Kiwano/2d/ActionTween.cpp @@ -326,59 +326,39 @@ namespace kiwano // Opacity Action //------------------------------------------------------- - ActionOpacityBy::ActionOpacityBy(Duration duration, float opacity, EaseFunc func) + ActionFadeTo::ActionFadeTo(Duration duration, float opacity, EaseFunc func) : ActionTween(duration, func) - , delta_val_(opacity) + , delta_val_(0.f) + , end_val_(opacity) { } - void ActionOpacityBy::Init(NodePtr target) + void ActionFadeTo::Init(NodePtr target) { if (target) { start_val_ = target->GetOpacity(); + delta_val_ = end_val_ - start_val_; } } - void ActionOpacityBy::UpdateTween(NodePtr target, float percent) + void ActionFadeTo::UpdateTween(NodePtr target, float percent) { target->SetOpacity(start_val_ + delta_val_ * percent); } - ActionPtr ActionOpacityBy::Clone() const + ActionPtr ActionFadeTo::Clone() const { - return new (std::nothrow) ActionOpacityBy(dur_, delta_val_, ease_func_); - } - - ActionPtr ActionOpacityBy::Reverse() const - { - return new (std::nothrow) ActionOpacityBy(dur_, -delta_val_, ease_func_); - } - - ActionOpacityTo::ActionOpacityTo(Duration duration, float opacity, EaseFunc func) - : ActionOpacityBy(duration, 0, func) - { - end_val_ = opacity; - } - - ActionPtr ActionOpacityTo::Clone() const - { - return new (std::nothrow) ActionOpacityTo(dur_, end_val_, ease_func_); - } - - void ActionOpacityTo::Init(NodePtr target) - { - ActionOpacityBy::Init(target); - delta_val_ = end_val_ - start_val_; + return new (std::nothrow) ActionFadeTo(dur_, end_val_, ease_func_); } ActionFadeIn::ActionFadeIn(Duration duration, EaseFunc func) - : ActionOpacityTo(duration, 1, func) + : ActionFadeTo(duration, 1, func) { } ActionFadeOut::ActionFadeOut(Duration duration, EaseFunc func) - : ActionOpacityTo(duration, 0, func) + : ActionFadeTo(duration, 0, func) { } diff --git a/Kiwano/2d/ActionTween.h b/Kiwano/2d/ActionTween.h index 5c671a9c..272de038 100644 --- a/Kiwano/2d/ActionTween.h +++ b/Kiwano/2d/ActionTween.h @@ -296,40 +296,12 @@ namespace kiwano }; - // 透明度相对渐变动作 - class KGE_API ActionOpacityBy + // 透明度渐变动作 + class KGE_API ActionFadeTo : public ActionTween { public: - ActionOpacityBy( - Duration duration, /* 持续时长 */ - float opacity, /* 相对变化值 */ - EaseFunc func = nullptr /* 速度变化 */ - ); - - // 获取该动作的拷贝对象 - ActionPtr Clone() const override; - - // 获取该动作的倒转 - ActionPtr Reverse() const override; - - protected: - void Init(NodePtr target) override; - - void UpdateTween(NodePtr target, float percent) override; - - protected: - float start_val_; - float delta_val_; - }; - - - // 透明度渐变动作 - class KGE_API ActionOpacityTo - : public ActionOpacityBy - { - public: - ActionOpacityTo( + ActionFadeTo( Duration duration, /* 持续时长 */ float opacity, /* 目标值 */ EaseFunc func = nullptr /* 速度变化 */ @@ -341,21 +313,25 @@ namespace kiwano // 获取该动作的倒转 virtual ActionPtr Reverse() const override { - KGE_ERROR_LOG(L"Reverse() not supported in ActionOpacityTo"); + KGE_ERROR_LOG(L"Reverse() not supported in ActionFadeTo"); return nullptr; } protected: void Init(NodePtr target) override; + void UpdateTween(NodePtr target, float percent) override; + protected: + float start_val_; + float delta_val_; float end_val_; }; // 淡入动作 class KGE_API ActionFadeIn - : public ActionOpacityTo + : public ActionFadeTo { public: // 创建淡入动作 @@ -368,7 +344,7 @@ namespace kiwano // 淡出动作 class KGE_API ActionFadeOut - : public ActionOpacityTo + : public ActionFadeTo { public: // 创建淡出动作 diff --git a/Kiwano/2d/include-forwards.h b/Kiwano/2d/include-forwards.h index 043ff7f3..9fdb85b0 100644 --- a/Kiwano/2d/include-forwards.h +++ b/Kiwano/2d/include-forwards.h @@ -60,8 +60,7 @@ namespace kiwano KGE_DECLARE_SMART_PTR(ActionJumpTo); KGE_DECLARE_SMART_PTR(ActionScaleBy); KGE_DECLARE_SMART_PTR(ActionScaleTo); - KGE_DECLARE_SMART_PTR(ActionOpacityBy); - KGE_DECLARE_SMART_PTR(ActionOpacityTo); + KGE_DECLARE_SMART_PTR(ActionFadeTo); KGE_DECLARE_SMART_PTR(ActionFadeIn); KGE_DECLARE_SMART_PTR(ActionFadeOut); KGE_DECLARE_SMART_PTR(ActionRotateBy);