diff --git a/include/eepp/scene/actions/close.hpp b/include/eepp/scene/actions/close.hpp index f990feaf1..da0f855dc 100644 --- a/include/eepp/scene/actions/close.hpp +++ b/include/eepp/scene/actions/close.hpp @@ -17,6 +17,8 @@ class EE_API Close : public Delay { protected: Close( const Time& time ); + + void onStart() override; }; diff --git a/include/eepp/scene/actions/fade.hpp b/include/eepp/scene/actions/fade.hpp index 2cf016e27..f98797c4d 100644 --- a/include/eepp/scene/actions/fade.hpp +++ b/include/eepp/scene/actions/fade.hpp @@ -14,6 +14,8 @@ class EE_API Fade : public ActionInterpolation1d { Action * reverse() const override; protected: + Fade(); + Fade( const Float & start, const Float & end, const Time & duration, const Ease::Interpolation & type, const bool& alphaChilds ); void onStart() override; @@ -21,8 +23,42 @@ class EE_API Fade : public ActionInterpolation1d { void onUpdate( const Time& time ) override; bool mAffectChilds; - private: - Fade(); +}; + +class EE_API FadeIn : public Fade { + public: + static FadeIn * New( const Time& duration, const Ease::Interpolation& type = Ease::Linear, const bool& alphaChilds = true ); + + void start() override; + + Action * clone() const override; + + Action * reverse() const override; + protected: + Time mDuration; + Ease::Interpolation mType; + + FadeIn(); + + FadeIn( const Time & duration, const Ease::Interpolation & type, const bool& alphaChilds ); +}; + +class EE_API FadeOut: public Fade { + public: + static FadeOut * New( const Time& duration, const Ease::Interpolation& type = Ease::Linear, const bool& alphaChilds = true ); + + void start() override; + + Action * clone() const override; + + Action * reverse() const override; + protected: + Time mDuration; + Ease::Interpolation mType; + + FadeOut(); + + FadeOut( const Time & duration, const Ease::Interpolation & type, const bool& alphaChilds ); }; }}} diff --git a/src/eepp/scene/actions/close.cpp b/src/eepp/scene/actions/close.cpp index 0b83b60ca..9502fe47a 100644 --- a/src/eepp/scene/actions/close.cpp +++ b/src/eepp/scene/actions/close.cpp @@ -25,4 +25,8 @@ Close::Close(const Time & time) : Delay( time ) {} +void Close::onStart() { + update(Seconds(0)); +} + }}} diff --git a/src/eepp/scene/actions/delay.cpp b/src/eepp/scene/actions/delay.cpp index 24fa86d60..dcfbe4b0b 100644 --- a/src/eepp/scene/actions/delay.cpp +++ b/src/eepp/scene/actions/delay.cpp @@ -9,11 +9,15 @@ Delay * Delay::New(const Time & time) { void Delay::start() { mClock.restart(); + onStart(); + sendEvent( ActionType::OnStart ); } void Delay::stop() { // 'Cause none of them can stop the time + onStop(); + sendEvent( ActionType::OnStop ); } diff --git a/src/eepp/scene/actions/fade.cpp b/src/eepp/scene/actions/fade.cpp index fac6899a8..25c67ca75 100644 --- a/src/eepp/scene/actions/fade.cpp +++ b/src/eepp/scene/actions/fade.cpp @@ -52,4 +52,84 @@ Action * Fade::reverse() const { return action; } +FadeIn * FadeIn::New(const Time & duration, const Ease::Interpolation & type, const bool & alphaChilds) { + return eeNew( FadeIn, ( duration, type, alphaChilds ) ); +} + +Action * FadeIn::clone() const { + FadeIn * action = eeNew( FadeIn, () ); + action->mAffectChilds = mAffectChilds; + action->mDuration = mDuration; + action->mType = mType; + action->setInterpolation( mInterpolation ); + return action; +} + +Action * FadeIn::reverse() const { + FadeIn * action = eeNew( FadeIn, () ); + action->mAffectChilds = mAffectChilds; + action->mDuration = mDuration; + action->mType = mType; + action->setInterpolation( Interpolation1d( mInterpolation.getReversePoints() ) ); + return action; +} + +void FadeIn::start() { + mInterpolation.clear().add( mNode->getAlpha(), mDuration ).add( 255.f ).setType( mType ); + + Fade::start(); +} + +FadeIn::FadeIn() : + Fade() +{} + +FadeIn::FadeIn( const Time & duration, const Ease::Interpolation & type, const bool& alphaChilds ) : + Fade(), + mDuration( duration ), + mType( type ) +{ + mAffectChilds = alphaChilds; +} + +FadeOut * FadeOut::New(const Time & duration, const Ease::Interpolation & type, const bool & alphaChilds) { + return eeNew( FadeOut, ( duration, type, alphaChilds ) ); +} + +Action * FadeOut::clone() const { + FadeOut * action = eeNew( FadeOut, () ); + action->mAffectChilds = mAffectChilds; + action->mDuration = mDuration; + action->mType = mType; + action->setInterpolation( mInterpolation ); + return action; +} + +Action * FadeOut::reverse() const { + FadeOut * action = eeNew( FadeOut, () ); + action->mAffectChilds = mAffectChilds; + action->mDuration = mDuration; + action->mType = mType; + action->setInterpolation( Interpolation1d( mInterpolation.getReversePoints() ) ); + return action; +} + +void FadeOut::start() { + mInterpolation.clear().add( mNode->getAlpha(), mDuration ).add( 0.f ).setType( mType ); + + Fade::start(); +} + +FadeOut::FadeOut() : + Fade() +{} + +FadeOut::FadeOut( const Time & duration, const Ease::Interpolation & type, const bool& alphaChilds ) : + Fade(), + mDuration( duration ), + mType( type ) +{ + mAffectChilds = alphaChilds; +} + }}}