Program Listing for File animationtimer.cpp¶
↰ Return to documentation for file (src/core/timer/animationtimer.cpp
)
/*
* AnimationTimer - Class for managing time-sensitive actions for Animations.
*/
#include "animationtimer.h"
#include <math.h>
namespace PixelMaestro {
AnimationTimer::AnimationTimer(const Animation& animation) : animation_(animation) { }
uint16_t AnimationTimer::get_delay() const {
return delay_;
}
uint8_t AnimationTimer::get_step_count() const {
return step_count_;
}
void AnimationTimer::recalculate_step_count() {
/*
* If fading, calculate the distance in steps between the current cycle and the next cycle.
* Otherwise, just jump to the next cycle.
*/
if (animation_.get_fade()) {
step_count_ = fmax((interval_ - delay_) / (float)animation_.get_section().get_maestro().get_timer().get_interval(), 1);
}
else {
step_count_ = 1;
}
}
void AnimationTimer::set_interval(uint16_t interval, uint16_t delay) {
this->interval_ = interval;
this->delay_ = delay;
this->recalculate_step_count();
}
bool AnimationTimer::update(const uint32_t& current_time) {
if (running_ && ((current_time - last_time_) >= (interval_))) {
last_time_ = current_time;
return true;
}
return false;
}
}