diff --git a/RetroFE/Source/Graphics/Animate/Tween.cpp b/RetroFE/Source/Graphics/Animate/Tween.cpp index 2b4d4b3..3db751c 100644 --- a/RetroFE/Source/Graphics/Animate/Tween.cpp +++ b/RetroFE/Source/Graphics/Animate/Tween.cpp @@ -110,6 +110,11 @@ float Tween::animate(double elapsedTime) return animateSingle(type, start, end, duration, elapsedTime); } +float Tween::animate(double elapsedTime, double startValue) +{ + return animateSingle(type, startValue, end, duration, elapsedTime); +} + //todo: SDL likes floats, consider having casting being performed elsewhere float Tween::animateSingle(TweenAlgorithm type, double start, double end, double duration, double elapsedTime) { @@ -369,3 +374,9 @@ double Tween::easeInOutCircular(double t, double d, double b, double c) t -= 2; return c/2 * (sqrt(1 - t*t) + 1) + b; } + + +double Tween::getStart() +{ + return start; +} \ No newline at end of file diff --git a/RetroFE/Source/Graphics/Animate/Tween.h b/RetroFE/Source/Graphics/Animate/Tween.h index b38bd8e..1ed2d36 100644 --- a/RetroFE/Source/Graphics/Animate/Tween.h +++ b/RetroFE/Source/Graphics/Animate/Tween.h @@ -27,11 +27,13 @@ public: Tween(TweenProperty name, TweenAlgorithm type, double start, double end, double duration); float animate(double elapsedTime); + float animate(double elapsedTime, double startValue); static float animateSingle(TweenAlgorithm type, double start, double end, double duration, double elapsedTime); static TweenAlgorithm getTweenType(std::string name); static bool getTweenProperty(std::string name, TweenProperty &property); TweenProperty property; double duration; + double getStart(); private: static double easeInQuadratic(double elapsedTime, double duration, double b, double c); diff --git a/RetroFE/Source/Graphics/Component/Component.cpp b/RetroFE/Source/Graphics/Component/Component.cpp index e6f6880..30bd4a6 100644 --- a/RetroFE/Source/Graphics/Component/Component.cpp +++ b/RetroFE/Source/Graphics/Component/Component.cpp @@ -18,6 +18,7 @@ #include "../../Graphics/ViewInfo.h" #include "../../Utility/Log.h" #include "../../SDL.h" +#include Component::Component(Page &p) : page(p) @@ -134,18 +135,20 @@ void Component::update(float dt) currentTweens_ = newTweens; currentTweenIndex_ = 0; elapsedTweenTime_ = 0; + storeViewInfo_ = baseViewInfo; currentTweenComplete_ = false; } animationRequested_ = false; } else if (tweens_ && currentTweenComplete_) { - animationType_ = "idle"; - currentTweens_ = tweens_->getAnimation( "idle", menuIndex_ ); - currentTweenIndex_ = 0; - elapsedTweenTime_ = 0; - currentTweenComplete_ = false; - animationRequested_ = false; + animationType_ = "idle"; + currentTweens_ = tweens_->getAnimation( "idle", menuIndex_ ); + currentTweenIndex_ = 0; + elapsedTweenTime_ = 0; + storeViewInfo_ = baseViewInfo; + currentTweenComplete_ = false; + animationRequested_ = false; } currentTweenComplete_ = animate(); @@ -196,64 +199,94 @@ bool Component::animate() //todo: too many levels of nesting if(elapsedTime < tween->duration) - { currentDone = false; - } else - { elapsedTime = static_cast(tween->duration); - } - - float value = tween->animate(elapsedTime); switch(tween->property) { case TWEEN_PROPERTY_X: - baseViewInfo.X = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.X = tween->animate(elapsedTime, storeViewInfo_.X); + else + baseViewInfo.X = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_Y: - baseViewInfo.Y = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.Y = tween->animate(elapsedTime, storeViewInfo_.Y); + else + baseViewInfo.Y = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_HEIGHT: - baseViewInfo.Height = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.Height = tween->animate(elapsedTime, storeViewInfo_.Height); + else + baseViewInfo.Height = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_WIDTH: - baseViewInfo.Width = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.Width = tween->animate(elapsedTime, storeViewInfo_.Width); + else + baseViewInfo.Width = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_ANGLE: - baseViewInfo.Angle = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.Angle = tween->animate(elapsedTime, storeViewInfo_.Angle); + else + baseViewInfo.Angle = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_ALPHA: - baseViewInfo.Alpha = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.Alpha = tween->animate(elapsedTime, storeViewInfo_.Alpha); + else + baseViewInfo.Alpha = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_X_ORIGIN: - baseViewInfo.XOrigin = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.XOrigin = tween->animate(elapsedTime, storeViewInfo_.XOrigin); + else + baseViewInfo.XOrigin = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_Y_ORIGIN: - baseViewInfo.YOrigin = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.YOrigin = tween->animate(elapsedTime, storeViewInfo_.YOrigin); + else + baseViewInfo.YOrigin = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_X_OFFSET: - baseViewInfo.XOffset = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.XOffset = tween->animate(elapsedTime, storeViewInfo_.XOffset); + else + baseViewInfo.XOffset = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_Y_OFFSET: - baseViewInfo.YOffset = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.YOffset = tween->animate(elapsedTime, storeViewInfo_.YOffset); + else + baseViewInfo.YOffset = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_FONT_SIZE: - baseViewInfo.FontSize = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.FontSize = tween->animate(elapsedTime, storeViewInfo_.FontSize); + else + baseViewInfo.FontSize = tween->animate(elapsedTime); break; case TWEEN_PROPERTY_BACKGROUND_ALPHA: - baseViewInfo.BackgroundAlpha = value; + if (std::isnan( tween->getStart() )) + baseViewInfo.BackgroundAlpha = tween->animate(elapsedTime, storeViewInfo_.BackgroundAlpha); + else + baseViewInfo.BackgroundAlpha = tween->animate(elapsedTime); break; } } diff --git a/RetroFE/Source/Graphics/Component/Component.h b/RetroFE/Source/Graphics/Component/Component.h index 4f28847..d49e0a0 100644 --- a/RetroFE/Source/Graphics/Component/Component.h +++ b/RetroFE/Source/Graphics/Component/Component.h @@ -60,6 +60,7 @@ private: Animation *currentTweens_; SDL_Texture *backgroundTexture_; + ViewInfo storeViewInfo_; unsigned int currentTweenIndex_; bool currentTweenComplete_; float elapsedTweenTime_; diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index 35ec921..111eefa 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -37,6 +37,7 @@ #include #include #include +#include using namespace rapidxml; @@ -952,17 +953,21 @@ void PageBuilder::getAnimationEvents(xml_node<> *node, TweenSet &tweens) { Logger::write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"type\" attribute"); } - else if(!from) - { - Logger::write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"from\" attribute"); - } else if(!to) { Logger::write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"to\" attribute"); } else { - float fromValue = Utils::convertFloat(from->value()); + float fromValue; + if (from) + { + fromValue = Utils::convertFloat(from->value()); + } + else + { + fromValue = std::numeric_limits::quiet_NaN(); + } float toValue = Utils::convertFloat(to->value()); float durationValue = Utils::convertFloat(durationXml->value());