From a89b0a78bdbd89b62ba415dd3e0b20c8b402ffe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Sat, 13 Jan 2018 19:29:59 -0300 Subject: [PATCH] Added Actions: Dealy, Sequence, Spawn. Fixed several minor bugs in Actions. --HG-- branch : dev-2.1 --- include/eepp/math/interpolation1d.hpp | 5 + include/eepp/math/interpolation2d.hpp | 5 + include/eepp/ui.hpp | 3 + .../eepp/ui/actions/actioninterpolation1d.hpp | 4 +- .../eepp/ui/actions/actioninterpolation2d.hpp | 4 +- include/eepp/ui/actions/delay.hpp | 36 ++++++ include/eepp/ui/actions/fade.hpp | 2 +- include/eepp/ui/actions/marginmove.hpp | 2 +- include/eepp/ui/actions/move.hpp | 2 +- include/eepp/ui/actions/rotate.hpp | 2 +- include/eepp/ui/actions/scale.hpp | 2 +- include/eepp/ui/actions/sequence.hpp | 44 ++++++++ include/eepp/ui/actions/spawn.hpp | 43 ++++++++ include/eepp/ui/uiaction.hpp | 9 +- include/eepp/ui/uiactionmanager.hpp | 2 +- projects/linux/ee.creator.user | 6 +- projects/linux/ee.files | 7 ++ src/eepp/math/interpolation1d.cpp | 30 +++++ src/eepp/math/interpolation2d.cpp | 27 +++++ src/eepp/ui/actions/delay.cpp | 39 +++++++ src/eepp/ui/actions/fade.cpp | 5 +- src/eepp/ui/actions/marginmove.cpp | 27 ++--- src/eepp/ui/actions/move.cpp | 7 +- src/eepp/ui/actions/rotate.cpp | 7 +- src/eepp/ui/actions/scale.cpp | 7 +- src/eepp/ui/actions/sequence.cpp | 99 +++++++++++++++++ src/eepp/ui/actions/spawn.cpp | 103 ++++++++++++++++++ src/eepp/ui/uiaction.cpp | 4 - src/eepp/ui/uinode.cpp | 2 +- src/test/eetest.cpp | 8 +- 30 files changed, 489 insertions(+), 54 deletions(-) create mode 100644 include/eepp/ui/actions/delay.hpp create mode 100644 include/eepp/ui/actions/sequence.hpp create mode 100644 include/eepp/ui/actions/spawn.hpp create mode 100644 src/eepp/ui/actions/delay.cpp create mode 100644 src/eepp/ui/actions/sequence.cpp create mode 100644 src/eepp/ui/actions/spawn.cpp diff --git a/include/eepp/math/interpolation1d.hpp b/include/eepp/math/interpolation1d.hpp index e7978c9e4..6efff336a 100644 --- a/include/eepp/math/interpolation1d.hpp +++ b/include/eepp/math/interpolation1d.hpp @@ -25,6 +25,8 @@ class EE_API Interpolation1d { public: Interpolation1d(); + Interpolation1d( std::vector points ); + ~Interpolation1d(); typedef cb::Callback1 OnPathEndCallback; @@ -99,6 +101,9 @@ class EE_API Interpolation1d { /** @return the vector of points */ const std::vector& getPoints() const; + /** @return the vector of points reversed */ + std::vector getReversePoints(); + /** @return The Current Node */ Point1d* getCurrentActual() const; diff --git a/include/eepp/math/interpolation2d.hpp b/include/eepp/math/interpolation2d.hpp index ac9465a43..54e4a630e 100755 --- a/include/eepp/math/interpolation2d.hpp +++ b/include/eepp/math/interpolation2d.hpp @@ -26,6 +26,8 @@ class EE_API Interpolation2d { public: Interpolation2d(); + Interpolation2d( std::vector points ); + ~Interpolation2d(); typedef cb::Callback1 OnPathEndCallback; @@ -101,6 +103,9 @@ class EE_API Interpolation2d { /** @return the vector of waypoints */ const std::vector& getPoints() const; + /** @return the vector of waypoints reversed */ + std::vector getReversePoints(); + /** Set the current interpolation speed ( This will destroy the time of the interpolation and create one depending on the speed ) ( pixels per second ) */ Interpolation2d& setSpeed( const Float& speed ); diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index 5d1df9ce9..fc793999b 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -65,5 +65,8 @@ #include #include #include +#include +#include +#include #endif diff --git a/include/eepp/ui/actions/actioninterpolation1d.hpp b/include/eepp/ui/actions/actioninterpolation1d.hpp index b1e1a6e51..1e1526fe7 100644 --- a/include/eepp/ui/actions/actioninterpolation1d.hpp +++ b/include/eepp/ui/actions/actioninterpolation1d.hpp @@ -7,7 +7,7 @@ using namespace EE::Math; namespace EE { namespace UI { namespace Action { -class ActionInterpolation1d : public UIAction { +class EE_API ActionInterpolation1d : public UIAction { public: void start() override; @@ -19,7 +19,7 @@ class ActionInterpolation1d : public UIAction { Interpolation1d * getInterpolation(); protected: - Interpolation1d mInterpolation; + mutable Interpolation1d mInterpolation; ActionInterpolation1d(); diff --git a/include/eepp/ui/actions/actioninterpolation2d.hpp b/include/eepp/ui/actions/actioninterpolation2d.hpp index b4fec4cc5..1b968b493 100644 --- a/include/eepp/ui/actions/actioninterpolation2d.hpp +++ b/include/eepp/ui/actions/actioninterpolation2d.hpp @@ -7,7 +7,7 @@ using namespace EE::Math; namespace EE { namespace UI { namespace Action { -class ActionInterpolation2d : public UIAction { +class EE_API ActionInterpolation2d : public UIAction { public: void start() override; @@ -19,7 +19,7 @@ class ActionInterpolation2d : public UIAction { Interpolation2d * getInterpolation(); protected: - Interpolation2d mInterpolation; + mutable Interpolation2d mInterpolation; ActionInterpolation2d(); diff --git a/include/eepp/ui/actions/delay.hpp b/include/eepp/ui/actions/delay.hpp new file mode 100644 index 000000000..e128b3f0f --- /dev/null +++ b/include/eepp/ui/actions/delay.hpp @@ -0,0 +1,36 @@ +#ifndef EE_UI_ACTION_DELAY_HPP +#define EE_UI_ACTION_DELAY_HPP + +#include +#include +using namespace EE::System; + +namespace EE { namespace UI { namespace Action { + +class EE_API Delay : public UIAction { + public: + static Delay * New( const Time& time ); + + void start() override; + + void stop() override; + + void update( const Time& time ) override; + + bool isDone() override; + + UIAction * clone() const; + + UIAction * reverse() const; + + protected: + Clock mClock; + Time mTime; + + Delay( const Time& time ); + +}; + +}}} + +#endif diff --git a/include/eepp/ui/actions/fade.hpp b/include/eepp/ui/actions/fade.hpp index 40c16552a..49760a132 100644 --- a/include/eepp/ui/actions/fade.hpp +++ b/include/eepp/ui/actions/fade.hpp @@ -6,7 +6,7 @@ namespace EE { namespace UI { namespace Action { -class Fade : public ActionInterpolation1d { +class EE_API Fade : public ActionInterpolation1d { public: static Fade * New( const Float& start, const Float& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear, const bool& alphaChilds = true ); diff --git a/include/eepp/ui/actions/marginmove.hpp b/include/eepp/ui/actions/marginmove.hpp index ba457d231..62c17fa19 100644 --- a/include/eepp/ui/actions/marginmove.hpp +++ b/include/eepp/ui/actions/marginmove.hpp @@ -9,7 +9,7 @@ using namespace EE::Math; namespace EE { namespace UI { namespace Action { -class MarginMove : public UIAction { +class EE_API MarginMove : public UIAction { public: static MarginMove * New( const Rect& start, const Rect& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); diff --git a/include/eepp/ui/actions/move.hpp b/include/eepp/ui/actions/move.hpp index 47319fbd7..b13fb6526 100644 --- a/include/eepp/ui/actions/move.hpp +++ b/include/eepp/ui/actions/move.hpp @@ -6,7 +6,7 @@ namespace EE { namespace UI { namespace Action { -class Move : public ActionInterpolation2d { +class EE_API Move : public ActionInterpolation2d { public: static Move * New( const Vector2f& start, const Vector2f& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); diff --git a/include/eepp/ui/actions/rotate.hpp b/include/eepp/ui/actions/rotate.hpp index 5305a34eb..691ecd77d 100644 --- a/include/eepp/ui/actions/rotate.hpp +++ b/include/eepp/ui/actions/rotate.hpp @@ -6,7 +6,7 @@ namespace EE { namespace UI { namespace Action { -class Rotate : public ActionInterpolation1d { +class EE_API Rotate : public ActionInterpolation1d { public: static Rotate * New( const Float& start, const Float& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); diff --git a/include/eepp/ui/actions/scale.hpp b/include/eepp/ui/actions/scale.hpp index 4b76624a2..1606102ad 100644 --- a/include/eepp/ui/actions/scale.hpp +++ b/include/eepp/ui/actions/scale.hpp @@ -6,7 +6,7 @@ namespace EE { namespace UI { namespace Action { -class Scale : public ActionInterpolation2d { +class EE_API Scale : public ActionInterpolation2d { public: static Scale * New( const Vector2f& start, const Vector2f& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear ); diff --git a/include/eepp/ui/actions/sequence.hpp b/include/eepp/ui/actions/sequence.hpp new file mode 100644 index 000000000..7cdbb60ed --- /dev/null +++ b/include/eepp/ui/actions/sequence.hpp @@ -0,0 +1,44 @@ +#ifndef EE_UI_ACTION_SEQUENCE_HPP +#define EE_UI_ACTION_SEQUENCE_HPP + +#include + +namespace EE { namespace UI { namespace Action { + +class EE_API Sequence : public UIAction { + public: + static Sequence * New( const std::vector sequence ); + static Sequence * New( UIAction * action, UIAction * action2 ); + static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3 ); + static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4 ); + static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5 ); + static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6 ); + static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7 ); + static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8 ); + static Sequence * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8, UIAction * action9 ); + + void start() override; + + void stop() override; + + void update( const Time& time ) override; + + bool isDone() override; + + UIAction * clone() const; + + UIAction * reverse() const; + + virtual ~Sequence(); + + protected: + std::vector mSequence; + Uint32 mCurPos; + + Sequence( const std::vector sequence ); + +}; + +}}} + +#endif diff --git a/include/eepp/ui/actions/spawn.hpp b/include/eepp/ui/actions/spawn.hpp new file mode 100644 index 000000000..10ed69668 --- /dev/null +++ b/include/eepp/ui/actions/spawn.hpp @@ -0,0 +1,43 @@ +#ifndef EE_UI_ACTION_SPAWN_HPP +#define EE_UI_ACTION_SPAWN_HPP + +#include + +namespace EE { namespace UI { namespace Action { + +class EE_API Spawn : public UIAction { + public: + static Spawn * New( const std::vector spawn ); + static Spawn * New( UIAction * action, UIAction * action2 ); + static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3 ); + static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4 ); + static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5 ); + static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6 ); + static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7 ); + static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8 ); + static Spawn * New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8, UIAction * action9 ); + + void start() override; + + void stop() override; + + void update( const Time& time ) override; + + bool isDone() override; + + UIAction * clone() const; + + UIAction * reverse() const; + + virtual ~Spawn(); + protected: + std::vector mSpawn; + bool mAllDone; + + Spawn( const std::vector spawn ); + +}; + +}}} + +#endif diff --git a/include/eepp/ui/uiaction.hpp b/include/eepp/ui/uiaction.hpp index 1719da66d..0efc68e8f 100644 --- a/include/eepp/ui/uiaction.hpp +++ b/include/eepp/ui/uiaction.hpp @@ -10,13 +10,14 @@ namespace EE { namespace UI { class UINode; -class UIAction { +class EE_API UIAction { public: enum ActionType { OnStart, OnStop, - OnDone + OnDone, + OnStep }; typedef cb::Callback2 ActionCallback; @@ -53,7 +54,7 @@ class UIAction { void sendEvent( const ActionType & actionType ); - UINode * getNode() const; + void setTarget( UINode * target ); protected: friend class UINode; typedef std::map< ActionType, std::map > ActionCallbackMap; @@ -64,8 +65,6 @@ class UIAction { Uint32 mNumCallBacks; ActionCallbackMap mCallbacks; - void setTarget( UINode * target ); - virtual void onStart(); virtual void onStop(); diff --git a/include/eepp/ui/uiactionmanager.hpp b/include/eepp/ui/uiactionmanager.hpp index e302b7dc0..bfe1b902e 100644 --- a/include/eepp/ui/uiactionmanager.hpp +++ b/include/eepp/ui/uiactionmanager.hpp @@ -10,7 +10,7 @@ namespace EE { namespace UI { class UIAction; -class UIActionManager { +class EE_API UIActionManager { public: UIActionManager(); diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 8fb6a3f73..d98955601 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,10 +1,10 @@ - + EnvironmentId - {d43f4693-30c1-436c-b1d1-498aab2c2f8c} + {b6114084-39c2-4cd0-b9e2-d8803dc6b446} ProjectExplorer.Project.ActiveTarget @@ -63,7 +63,7 @@ Desktop Desktop - {6d057187-158a-4883-8d5b-d470a6b6b025} + {388e5431-b31b-42b3-b9ad-9002d279d75d} 10 0 0 diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 30dfe872e..8fd824466 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -39,10 +39,14 @@ ../../include/eepp/system/virtualfilesystem.hpp ../../include/eepp/ui/actions/actioninterpolation1d.hpp ../../include/eepp/ui/actions/actioninterpolation2d.hpp +../../include/eepp/ui/actions/delay.hpp ../../include/eepp/ui/actions/fade.hpp +../../include/eepp/ui/actions/marginmove.hpp ../../include/eepp/ui/actions/move.hpp ../../include/eepp/ui/actions/rotate.hpp ../../include/eepp/ui/actions/scale.hpp +../../include/eepp/ui/actions/sequence.hpp +../../include/eepp/ui/actions/spawn.hpp ../../include/eepp/ui/marginmove/scale.hpp ../../include/eepp/ui/uiaction.hpp ../../include/eepp/ui/uiactionmanager.hpp @@ -103,11 +107,14 @@ ../../src/eepp/system/virtualfilesystem.cpp ../../src/eepp/ui/actions/actioninterpolation1d.cpp ../../src/eepp/ui/actions/actioninterpolation2d.cpp +../../src/eepp/ui/actions/delay.cpp ../../src/eepp/ui/actions/fade.cpp ../../src/eepp/ui/actions/move.cpp ../../src/eepp/ui/actions/rotate.cpp ../../src/eepp/ui/actions/scale.cpp ../../src/eepp/ui/actions/marginmove.cpp +../../src/eepp/ui/actions/sequence.cpp +../../src/eepp/ui/actions/spawn.cpp ../../src/eepp/ui/uiaction.cpp ../../src/eepp/ui/uiactionmanager.cpp ../../src/eepp/ui/uigridlayout.cpp diff --git a/src/eepp/math/interpolation1d.cpp b/src/eepp/math/interpolation1d.cpp index 04987dee1..629776bd3 100644 --- a/src/eepp/math/interpolation1d.cpp +++ b/src/eepp/math/interpolation1d.cpp @@ -23,6 +23,26 @@ Interpolation1d::Interpolation1d() : { } +Interpolation1d::Interpolation1d( std::vector points ) : + mData(0), + mType(Ease::Linear), + mEnable(false), + mUpdate(true), + mLoop(false), + mEnded(false), + mTotDist(0.f), + mCurPos(0.f), + mCurPoint(0), + mCurTime(Time::Zero), + mSpeed(1.3f), + mActP(NULL), + mNexP(NULL), + mPoints(points), + mOnPathEndCallback(), + mOnStepCallback() +{ +} + Interpolation1d::~Interpolation1d() { } @@ -302,6 +322,16 @@ const std::vector& Interpolation1d::getPoints() const { return mPoints; } +std::vector Interpolation1d::getReversePoints() { + std::vector reversed; + + for ( auto it = mPoints.rbegin(); it != mPoints.rend(); ++it ) { + reversed.push_back( *it ); + } + + return reversed; +} + const Float& Interpolation1d::getSpeed() const { return mSpeed; } diff --git a/src/eepp/math/interpolation2d.cpp b/src/eepp/math/interpolation2d.cpp index 9cf3e9584..60ab91b5a 100755 --- a/src/eepp/math/interpolation2d.cpp +++ b/src/eepp/math/interpolation2d.cpp @@ -20,6 +20,23 @@ Interpolation2d::Interpolation2d() : { } +Interpolation2d::Interpolation2d( std::vector points ) : + mData(0), + mType(Ease::Linear), + mEnable(false), + mUpdate(true), + mLoop(false), + mEnded(false), + mTotDist(0.f), + mCurPoint(0), + mCurTime(Time::Zero), + mSpeed(1.3f), + mPoints(points), + mOnPathEndCallback(), + mOnStepCallback() +{ +} + Interpolation2d::~Interpolation2d() { } @@ -300,6 +317,16 @@ const std::vector& Interpolation2d::getPoints() const { return mPoints; } +std::vector Interpolation2d::getReversePoints() { + std::vector reversed; + + for ( auto it = mPoints.rbegin(); it != mPoints.rend(); ++it ) { + reversed.push_back( *it ); + } + + return reversed; +} + const Float& Interpolation2d::getSpeed() const { return mSpeed; } diff --git a/src/eepp/ui/actions/delay.cpp b/src/eepp/ui/actions/delay.cpp new file mode 100644 index 000000000..b0f7b23cb --- /dev/null +++ b/src/eepp/ui/actions/delay.cpp @@ -0,0 +1,39 @@ +#include + +namespace EE { namespace UI { namespace Action { + +Delay * Delay::New(const Time & time) { + return eeNew( Delay, ( time ) ); +} + +void Delay::start() { + mClock.restart(); + + sendEvent( ActionType::OnStart ); +} + +void Delay::stop() { + // 'Cause none of them can stop the time + sendEvent( ActionType::OnStop ); +} + +void Delay::update(const Time & time) +{} + +bool Delay::isDone() { + return mClock.getElapsedTime() >= mTime; +} + +UIAction *Delay::clone() const { + return New( mTime ); +} + +UIAction *Delay::reverse() const { + return NULL; // or a time machine +} + +Delay::Delay(const Time & time) : + mTime( time ) +{} + +}}} diff --git a/src/eepp/ui/actions/fade.cpp b/src/eepp/ui/actions/fade.cpp index a0576b351..06832b164 100644 --- a/src/eepp/ui/actions/fade.cpp +++ b/src/eepp/ui/actions/fade.cpp @@ -46,7 +46,10 @@ UIAction * Fade::clone() const { } UIAction * Fade::reverse() const { - return NULL; + Fade * action = eeNew( Fade, () ); + action->mAffectChilds = mAffectChilds; + action->setInterpolation( Interpolation1d( mInterpolation.getReversePoints() ) ); + return action; } }}} diff --git a/src/eepp/ui/actions/marginmove.cpp b/src/eepp/ui/actions/marginmove.cpp index 882407aab..ef7d51c20 100644 --- a/src/eepp/ui/actions/marginmove.cpp +++ b/src/eepp/ui/actions/marginmove.cpp @@ -11,48 +11,39 @@ MarginMove * MarginMove::New( const Rect & start, const Rect & end, const Time& MarginMove::MarginMove() {} -Interpolation1d MarginMove::getInterpolationBottom() const -{ +Interpolation1d MarginMove::getInterpolationBottom() const { return mInterpolationBottom; } -void MarginMove::setInterpolationBottom(const Interpolation1d & interpolationBottom) -{ +void MarginMove::setInterpolationBottom(const Interpolation1d & interpolationBottom) { mInterpolationBottom = interpolationBottom; } -Interpolation1d MarginMove::getInterpolationTop() const -{ +Interpolation1d MarginMove::getInterpolationTop() const { return mInterpolationTop; } -void MarginMove::setInterpolationTop(const Interpolation1d & interpolationTop) -{ +void MarginMove::setInterpolationTop(const Interpolation1d & interpolationTop) { mInterpolationTop = interpolationTop; } -Interpolation1d MarginMove::getInterpolationRight() const -{ +Interpolation1d MarginMove::getInterpolationRight() const { return mInterpolationRight; } -void MarginMove::setInterpolationRight(const Interpolation1d & interpolationRight) -{ +void MarginMove::setInterpolationRight(const Interpolation1d & interpolationRight) { mInterpolationRight = interpolationRight; } -Interpolation1d MarginMove::getInterpolationLeft() const -{ +Interpolation1d MarginMove::getInterpolationLeft() const { return mInterpolationLeft; } -void MarginMove::setInterpolationLeft(const Interpolation1d & interpolationLeft) -{ +void MarginMove::setInterpolationLeft(const Interpolation1d & interpolationLeft) { mInterpolationLeft = interpolationLeft; } -MarginMove::MarginMove( const Rect& start, const Rect & end, const Time& duration, const Ease::Interpolation& type ) -{ +MarginMove::MarginMove( const Rect& start, const Rect & end, const Time& duration, const Ease::Interpolation& type ) { mInterpolationLeft.clear().add( start.Left, duration ).add( end.Left ).setType( type ); mInterpolationRight.clear().add( start.Right, duration ).add( end.Right ).setType( type ); mInterpolationTop.clear().add( start.Top, duration ).add( end.Top ).setType( type ); diff --git a/src/eepp/ui/actions/move.cpp b/src/eepp/ui/actions/move.cpp index f34a6476f..82e538619 100644 --- a/src/eepp/ui/actions/move.cpp +++ b/src/eepp/ui/actions/move.cpp @@ -10,8 +10,7 @@ Move * Move::New( const Vector2f& start, const Vector2f& end, const Time& durati Move::Move() {} -Move::Move( const Vector2f & start, const Vector2f & end, const Time& duration, const Ease::Interpolation& type ) -{ +Move::Move( const Vector2f & start, const Vector2f & end, const Time& duration, const Ease::Interpolation& type ) { mInterpolation.clear().add( start, duration ).add( end ).setType( type ); } @@ -34,7 +33,9 @@ UIAction * Move::clone() const { } UIAction * Move::reverse() const { - return NULL; + Move * action = eeNew( Move, () ); + action->setInterpolation( Interpolation2d( mInterpolation.getReversePoints() ) ); + return action; } }}} diff --git a/src/eepp/ui/actions/rotate.cpp b/src/eepp/ui/actions/rotate.cpp index a741d1aa9..e3e380dde 100644 --- a/src/eepp/ui/actions/rotate.cpp +++ b/src/eepp/ui/actions/rotate.cpp @@ -10,8 +10,7 @@ Rotate * Rotate::New( const Float & start, const Float & end, const Time& durati Rotate::Rotate() {} -Rotate::Rotate( const Float & start, const Float & end, const Time& duration, const Ease::Interpolation& type ) -{ +Rotate::Rotate( const Float & start, const Float & end, const Time& duration, const Ease::Interpolation& type ) { mInterpolation.clear().add( start, duration ).add( end ).setType( type ); } @@ -34,7 +33,9 @@ UIAction * Rotate::clone() const { } UIAction * Rotate::reverse() const { - return NULL; + Rotate * action = eeNew( Rotate, () ); + action->setInterpolation( Interpolation1d( mInterpolation.getReversePoints() ) ); + return action; } }}} diff --git a/src/eepp/ui/actions/scale.cpp b/src/eepp/ui/actions/scale.cpp index 61f65c625..8189c333d 100644 --- a/src/eepp/ui/actions/scale.cpp +++ b/src/eepp/ui/actions/scale.cpp @@ -10,8 +10,7 @@ Scale * Scale::New( const Vector2f& start, const Vector2f& end, const Time& dura Scale::Scale() {} -Scale::Scale( const Vector2f & start, const Vector2f & end, const Time& duration, const Ease::Interpolation& type ) -{ +Scale::Scale( const Vector2f & start, const Vector2f & end, const Time& duration, const Ease::Interpolation& type ) { mInterpolation.clear().add( start, duration ).add( end ).setType( type ); } @@ -34,7 +33,9 @@ UIAction * Scale::clone() const { } UIAction * Scale::reverse() const { - return NULL; + Scale * action = eeNew( Scale, () ); + action->setInterpolation( mInterpolation.getReversePoints() ); + return action; } }}} diff --git a/src/eepp/ui/actions/sequence.cpp b/src/eepp/ui/actions/sequence.cpp new file mode 100644 index 000000000..7516feb3f --- /dev/null +++ b/src/eepp/ui/actions/sequence.cpp @@ -0,0 +1,99 @@ +#include + +namespace EE { namespace UI { namespace Action { + +Sequence * Sequence::New( const std::vector sequence ) { + return eeNew( Sequence, ( sequence ) ); +} + +Sequence * Sequence::New( UIAction * action, UIAction * action2 ) { + return New( { action, action2 } ); +} + +Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3 ) { + return New( { action, action2, action3 } ); +} + +Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4 ) { + return New( { action, action2, action3, action4 } ); +} + +Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5 ) { + return New( { action, action2, action3, action4, action5 } ); +} + +Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6 ) { + return New( { action, action2, action3, action4, action5, action6 } ); +} + +Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7 ) { + return New( { action, action2, action3, action4, action5, action6, action7 } ); +} + +Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8 ) { + return New( { action, action2, action3, action4, action5, action6, action7, action8 } ); +} + +Sequence * Sequence::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8, UIAction * action9 ) { + return New( { action, action2, action3, action4, action5, action6, action7, action8, action9 } ); +} + +void Sequence::start() { + for ( size_t i = 0; i < mSequence.size(); i++ ) { + mSequence[ i ]->setTarget( getTarget() ); + } + + mSequence[ mCurPos ]->start(); + + sendEvent( ActionType::OnStart ); +} + +void Sequence::stop() { + mSequence[ mCurPos ]->stop(); + sendEvent( ActionType::OnStop ); +} + +void Sequence::update( const Time & time ) { + if ( isDone() ) + return; + + mSequence[ mCurPos ]->update( time ); + + if ( mSequence[ mCurPos ]->isDone() && mCurPos + 1 < mSequence.size() ) { + mCurPos++; + mSequence[ mCurPos ]->start(); + sendEvent( ActionType::OnStep ); + } +} + +bool Sequence::isDone() { + return mCurPos == mSequence.size() - 1 && mSequence[ mCurPos ]->isDone(); +} + +UIAction * Sequence::clone() const { + return Sequence::New( mSequence ); +} + +UIAction * Sequence::reverse() const { + std::vector reversed; + + for ( auto it = mSequence.rbegin(); it != mSequence.rend(); ++it ) { + reversed.push_back( *it ); + } + + return Sequence::New( reversed ); +} + +Sequence::~Sequence() { + for ( size_t i = 0; i < mSequence.size(); i++ ) { + UIAction * action = mSequence[ i ]; + eeSAFE_DELETE( action ); + } +} + +Sequence::Sequence( const std::vector sequence ) : + mSequence( sequence ), + mCurPos( 0 ) +{} + +}}} diff --git a/src/eepp/ui/actions/spawn.cpp b/src/eepp/ui/actions/spawn.cpp new file mode 100644 index 000000000..f3ff41b87 --- /dev/null +++ b/src/eepp/ui/actions/spawn.cpp @@ -0,0 +1,103 @@ +#include + +namespace EE { namespace UI { namespace Action { + +Spawn * Spawn::New( const std::vector spawn ) { + return eeNew( Spawn, ( spawn ) ); +} + +Spawn * Spawn::New( UIAction * action, UIAction * action2 ) { + return New( { action, action2 } ); +} + +Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3 ) { + return New( { action, action2, action3 } ); +} + +Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4 ) { + return New( { action, action2, action3, action4 } ); +} + +Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5 ) { + return New( { action, action2, action3, action4, action5 } ); +} + +Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6 ) { + return New( { action, action2, action3, action4, action5, action6 } ); +} + +Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7 ) { + return New( { action, action2, action3, action4, action5, action6, action7 } ); +} + +Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8 ) { + return New( { action, action2, action3, action4, action5, action6, action7, action8 } ); +} + +Spawn * Spawn::New( UIAction * action, UIAction * action2, UIAction * action3, UIAction * action4, UIAction * action5, UIAction * action6, UIAction * action7, UIAction * action8, UIAction * action9 ) { + return New( { action, action2, action3, action4, action5, action6, action7, action8, action9 } ); +} + +void Spawn::start() { + for ( size_t i = 0; i < mSpawn.size(); i++ ) { + mSpawn[ i ]->setTarget( getTarget() ); + mSpawn[ i ]->start(); + } + + sendEvent( ActionType::OnStart ); +} + +void Spawn::stop() { + for ( size_t i = 0; i < mSpawn.size(); i++ ) + mSpawn[ i ]->stop(); + + sendEvent( ActionType::OnStop ); +} + +void Spawn::update( const Time & time ) { + if ( isDone() ) + return; + + bool allDone = true; + + for ( size_t i = 0; i < mSpawn.size(); i++ ) { + mSpawn[ i ]->update( time ); + + if ( !mSpawn[i]->isDone() ) { + allDone = false; + } + } + + mAllDone = allDone; +} + +bool Spawn::isDone() { + return mAllDone; +} + +UIAction * Spawn::clone() const { + return Spawn::New( mSpawn ); +} + +UIAction * Spawn::reverse() const { + std::vector reversed; + + for ( auto it = mSpawn.rbegin(); it != mSpawn.rend(); ++it ) { + reversed.push_back( *it ); + } + + return Spawn::New( reversed ); +} + +Spawn::~Spawn() { + for ( size_t i = 0; i < mSpawn.size(); i++ ) { + UIAction * action = mSpawn[ i ]; + eeSAFE_DELETE( action ); + } +} + +Spawn::Spawn( const std::vector spawn ) : + mSpawn( spawn ) +{} + +}}} diff --git a/src/eepp/ui/uiaction.cpp b/src/eepp/ui/uiaction.cpp index 225531d51..bbf49218a 100644 --- a/src/eepp/ui/uiaction.cpp +++ b/src/eepp/ui/uiaction.cpp @@ -74,10 +74,6 @@ void UIAction::sendEvent( const ActionType& actionType ) { } } -UINode * UIAction::getNode() const { - return mNode; -} - void UIAction::onStart() {} void UIAction::onStop() {} diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 11263854f..3be2d3656 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -1868,7 +1868,7 @@ bool UINode::isAnimating() { } static void UINode_onFadeDone( UIAction * action, const UIAction::ActionType& actionType ) { - UINode * node = action->getNode(); + UINode * node = action->getTarget(); if ( NULL != node ) { if ( ( node->getNodeFlags() & UI_CTRL_FLAG_CLOSE_FO ) ) diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 2e527abd2..d1557d474 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1106,6 +1106,8 @@ void EETest::onMainClick( const UIEvent * Event ) { } } +using namespace EE::UI::Action; + void EETest::onButtonClick( const UIEvent * Event ) { const UIEventMouse * MouseEvent = reinterpret_cast ( Event ); @@ -1113,12 +1115,12 @@ void EETest::onButtonClick( const UIEvent * Event ) { UIImage * Gfx = UIImage::New(); Gfx->setDrawable( mTheme->getIconByName( "ok" ) ); Gfx->setEnabled( false ); - + Gfx->runAction( Sequence::New( Scale::New( Vector2f(1.f,1.f), Vector2f(2.f,2.f), Seconds( 0.5f ) ), + Scale::New( Vector2f(2.f,2.f), Vector2f(1.f,1.f), Seconds( 0.5f ) ) + ) ); Gfx->startRotation( 0, 2500, Milliseconds( 2500 ) ); Gfx->startTranslation( Vector2i( Math::randi( 0, mWindow->getWidth() ), -64 ), Vector2i( Math::randi( 0, mWindow->getWidth() ), mWindow->getHeight() + 64 ), Milliseconds( 2500 ) ); Gfx->closeFadeOut( Milliseconds( 3500 ) ); - - //mListBox->addListBoxItem( "Test ListBox " + String::toStr( mListBox->getCount() + 1 ) + " testing it right now!" ); } }