Dawn/src/dawn/games/vn/events/VNAnimateEvent.hpp
2023-04-21 23:30:33 -07:00

49 lines
1.1 KiB
C++

// 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<typename T>
class VNAnimateEvent : public VNEvent {
public:
T from;
T to;
float_t duration;
protected:
SimplerCallbackAnimation<T> 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;
};
}