Added animations to file selector
This commit is contained in:
parent
4e17d6e40c
commit
2d039dc47b
10 changed files with 250 additions and 178 deletions
68
src/GUIStuff/GUIFloatAnimation.cpp
Normal file
68
src/GUIStuff/GUIFloatAnimation.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#include "GUIFloatAnimation.hpp"
|
||||
#include "GUIManager.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
GUIFloatAnimation::GUIFloatAnimation(const GUIFloatAnimationData& animData):
|
||||
anim(animData),
|
||||
animVal(animData.startVal)
|
||||
{}
|
||||
|
||||
bool GUIFloatAnimation::is_at_start() {
|
||||
return state == State::DONE && currentTime == 0.0f;
|
||||
}
|
||||
|
||||
bool GUIFloatAnimation::is_at_end() {
|
||||
return state == State::DONE && currentTime == anim.duration;
|
||||
}
|
||||
|
||||
bool GUIFloatAnimation::is_done() {
|
||||
return state == State::DONE;
|
||||
}
|
||||
|
||||
void GUIFloatAnimation::calculate_anim_val() {
|
||||
animVal = std::lerp(anim.startVal, anim.endVal, anim.easing(currentTime / anim.duration));
|
||||
}
|
||||
|
||||
void GUIFloatAnimation::update(GUIManager& gui) {
|
||||
switch(state) {
|
||||
case State::RUN: {
|
||||
currentTime += gui.io.deltaTime;
|
||||
if(currentTime >= anim.duration) {
|
||||
currentTime = anim.duration;
|
||||
state = State::DONE;
|
||||
}
|
||||
calculate_anim_val();
|
||||
gui.set_to_layout();
|
||||
break;
|
||||
}
|
||||
case State::RUN_REVERSE: {
|
||||
currentTime -= gui.io.deltaTime;
|
||||
if(currentTime <= 0.0f) {
|
||||
currentTime = 0.0f;
|
||||
state = State::DONE;
|
||||
}
|
||||
calculate_anim_val();
|
||||
gui.set_to_layout();
|
||||
break;
|
||||
}
|
||||
case State::DONE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float GUIFloatAnimation::get_val() const {
|
||||
return animVal;
|
||||
}
|
||||
|
||||
void GUIFloatAnimation::animation_trigger() {
|
||||
if(currentTime < anim.duration)
|
||||
state = State::RUN;
|
||||
}
|
||||
|
||||
void GUIFloatAnimation::animation_trigger_reverse() {
|
||||
if(currentTime > 0.0f)
|
||||
state = State::RUN_REVERSE;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue