// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "VNEvent.hpp" #include "display/animation/SimplerCallbackAnimation.hpp" namespace Dawn { template class VNAnimateEvent : public VNEvent { public: T from; T to; float_t duration; protected: SimplerCallbackAnimation animation; void onStart() override { if(duration > 0) { animation.clear(); animation.addKeyframe(0, from); animation.addKeyframe(duration, to); animation.callback = [&](T v){ this->setValue(v); }; // On-end useEvent([&]() { this->next(); }, animation.event2AnimationEnd); useEvent([&](float_t delta) { animation.tick(delta); }, getScene()->eventSceneUpdate); } else { this->setValue(to); this->next(); } } virtual void setValue(T value) = 0; }; }