2022-04-23 14:16:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../defines.hpp"
|
|
|
|
#include <any>
|
|
|
|
|
|
|
|
enum ANIMATEDVARTYPE {
|
|
|
|
AVARTYPE_INVALID = -1,
|
|
|
|
AVARTYPE_FLOAT,
|
|
|
|
AVARTYPE_VECTOR,
|
|
|
|
AVARTYPE_COLOR
|
|
|
|
};
|
|
|
|
|
2022-05-05 14:02:30 +02:00
|
|
|
enum AVARDAMAGEPOLICY {
|
|
|
|
AVARDAMAGE_INVALID = -1,
|
|
|
|
AVARDAMAGE_ENTIRE = 0,
|
2022-07-16 12:44:45 +02:00
|
|
|
AVARDAMAGE_BORDER,
|
|
|
|
AVARDAMAGE_SHADOW
|
2022-05-05 14:02:30 +02:00
|
|
|
};
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
class CAnimationManager;
|
2022-05-12 11:27:31 +02:00
|
|
|
class CWorkspace;
|
2022-05-14 17:23:46 +02:00
|
|
|
struct SLayerSurface;
|
2022-07-28 13:28:43 +02:00
|
|
|
struct SAnimationPropertyConfig;
|
2022-04-23 14:16:02 +02:00
|
|
|
|
|
|
|
class CAnimatedVariable {
|
|
|
|
public:
|
|
|
|
CAnimatedVariable(); // dummy var
|
|
|
|
|
2022-07-28 13:28:43 +02:00
|
|
|
void create(ANIMATEDVARTYPE, SAnimationPropertyConfig*, void* pWindow, AVARDAMAGEPOLICY);
|
|
|
|
void create(ANIMATEDVARTYPE, std::any val, SAnimationPropertyConfig*, void* pWindow, AVARDAMAGEPOLICY);
|
2022-04-23 14:16:02 +02:00
|
|
|
|
|
|
|
~CAnimatedVariable();
|
|
|
|
|
2022-05-12 11:27:31 +02:00
|
|
|
void unregister();
|
|
|
|
|
2022-04-23 14:35:34 +02:00
|
|
|
// gets the current vector value (real time)
|
2022-04-23 14:40:51 +02:00
|
|
|
const Vector2D& vec() const {
|
2022-04-23 14:16:02 +02:00
|
|
|
return m_vValue;
|
|
|
|
}
|
|
|
|
|
2022-04-23 14:35:34 +02:00
|
|
|
// gets the current float value (real time)
|
2022-04-23 14:40:51 +02:00
|
|
|
const float& fl() const {
|
2022-04-23 14:16:02 +02:00
|
|
|
return m_fValue;
|
|
|
|
}
|
|
|
|
|
2022-04-23 14:35:34 +02:00
|
|
|
// gets the current color value (real time)
|
2022-04-23 14:40:51 +02:00
|
|
|
const CColor& col() const {
|
2022-04-23 14:16:02 +02:00
|
|
|
return m_cValue;
|
|
|
|
}
|
|
|
|
|
2022-04-23 14:35:34 +02:00
|
|
|
// gets the goal vector value
|
2022-04-23 14:40:51 +02:00
|
|
|
const Vector2D& goalv() const {
|
2022-04-23 14:35:34 +02:00
|
|
|
return m_vGoal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gets the goal float value
|
2022-04-23 14:40:51 +02:00
|
|
|
const float& goalf() const {
|
2022-04-23 14:35:34 +02:00
|
|
|
return m_fGoal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gets the goal color value
|
2022-04-23 14:40:51 +02:00
|
|
|
const CColor& goalc() const {
|
2022-04-23 14:35:34 +02:00
|
|
|
return m_cGoal;
|
|
|
|
}
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
void operator=(const Vector2D& v) {
|
|
|
|
m_vGoal = v;
|
2022-04-23 21:47:16 +02:00
|
|
|
animationBegin = std::chrono::system_clock::now();
|
|
|
|
m_vBegun = m_vValue;
|
2022-04-23 14:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator=(const float& v) {
|
|
|
|
m_fGoal = v;
|
2022-04-23 21:47:16 +02:00
|
|
|
animationBegin = std::chrono::system_clock::now();
|
|
|
|
m_fBegun = m_fValue;
|
2022-04-23 14:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator=(const CColor& v) {
|
|
|
|
m_cGoal = v;
|
2022-04-23 21:47:16 +02:00
|
|
|
animationBegin = std::chrono::system_clock::now();
|
|
|
|
m_cBegun = m_cValue;
|
2022-04-23 14:16:02 +02:00
|
|
|
}
|
|
|
|
|
2022-04-23 21:47:16 +02:00
|
|
|
// Sets the actual stored value, without affecting the goal, but resets the timer
|
2022-04-23 14:16:02 +02:00
|
|
|
void setValue(const Vector2D& v) {
|
|
|
|
m_vValue = v;
|
2022-04-23 21:47:16 +02:00
|
|
|
animationBegin = std::chrono::system_clock::now();
|
|
|
|
m_vBegun = m_vValue;
|
2022-04-23 14:16:02 +02:00
|
|
|
}
|
|
|
|
|
2022-04-23 21:47:16 +02:00
|
|
|
// Sets the actual stored value, without affecting the goal, but resets the timer
|
2022-04-23 14:16:02 +02:00
|
|
|
void setValue(const float& v) {
|
|
|
|
m_fValue = v;
|
2022-04-23 21:47:16 +02:00
|
|
|
animationBegin = std::chrono::system_clock::now();
|
|
|
|
m_vBegun = m_vValue;
|
2022-04-23 14:16:02 +02:00
|
|
|
}
|
|
|
|
|
2022-04-23 21:47:16 +02:00
|
|
|
// Sets the actual stored value, without affecting the goal, but resets the timer
|
2022-04-23 14:16:02 +02:00
|
|
|
void setValue(const CColor& v) {
|
|
|
|
m_cValue = v;
|
2022-04-23 21:47:16 +02:00
|
|
|
animationBegin = std::chrono::system_clock::now();
|
|
|
|
m_vBegun = m_vValue;
|
2022-04-23 14:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the actual value and goal
|
|
|
|
void setValueAndWarp(const Vector2D& v) {
|
|
|
|
m_vGoal = v;
|
|
|
|
warp();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the actual value and goal
|
|
|
|
void setValueAndWarp(const float& v) {
|
|
|
|
m_fGoal = v;
|
|
|
|
warp();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the actual value and goal
|
|
|
|
void setValueAndWarp(const CColor& v) {
|
|
|
|
m_cGoal = v;
|
|
|
|
warp();
|
|
|
|
}
|
|
|
|
|
2022-05-12 11:27:31 +02:00
|
|
|
// checks if an animation is in progress
|
|
|
|
bool isBeingAnimated() {
|
|
|
|
switch (m_eVarType) {
|
|
|
|
case AVARTYPE_FLOAT:
|
|
|
|
return m_fValue != m_fGoal;
|
|
|
|
case AVARTYPE_VECTOR:
|
|
|
|
return m_vValue != m_vGoal;
|
|
|
|
case AVARTYPE_COLOR:
|
|
|
|
return m_cValue != m_cGoal;
|
|
|
|
default:
|
2022-07-25 21:34:57 +02:00
|
|
|
UNREACHABLE();
|
2022-05-12 11:27:31 +02:00
|
|
|
}
|
|
|
|
|
2022-07-25 21:34:57 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
|
|
|
|
return false; // just so that the warning is suppressed
|
2022-05-12 11:27:31 +02:00
|
|
|
}
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
void warp() {
|
|
|
|
switch (m_eVarType) {
|
|
|
|
case AVARTYPE_FLOAT: {
|
|
|
|
m_fValue = m_fGoal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AVARTYPE_VECTOR: {
|
|
|
|
m_vValue = m_vGoal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AVARTYPE_COLOR: {
|
|
|
|
m_cValue = m_cGoal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2022-07-25 21:34:57 +02:00
|
|
|
UNREACHABLE();
|
2022-04-23 14:16:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:28:43 +02:00
|
|
|
void setConfig(SAnimationPropertyConfig* pConfig) {
|
|
|
|
m_pConfig = pConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
SAnimationPropertyConfig* getConfig() {
|
|
|
|
return m_pConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getDurationLeftMs();
|
|
|
|
|
2022-05-31 14:01:00 +02:00
|
|
|
private:
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
Vector2D m_vValue = Vector2D(0,0);
|
|
|
|
float m_fValue = 0;
|
|
|
|
CColor m_cValue;
|
|
|
|
|
|
|
|
Vector2D m_vGoal = Vector2D(0,0);
|
|
|
|
float m_fGoal = 0;
|
|
|
|
CColor m_cGoal;
|
|
|
|
|
2022-04-23 21:47:16 +02:00
|
|
|
Vector2D m_vBegun = Vector2D(0,0);
|
|
|
|
float m_fBegun = 0;
|
|
|
|
CColor m_cBegun;
|
|
|
|
|
2022-05-14 17:23:46 +02:00
|
|
|
// owners
|
2022-04-23 14:16:02 +02:00
|
|
|
void* m_pWindow = nullptr;
|
2022-05-12 11:27:31 +02:00
|
|
|
void* m_pWorkspace = nullptr;
|
2022-05-14 17:23:46 +02:00
|
|
|
void* m_pLayer = nullptr;
|
|
|
|
|
2022-07-28 13:28:43 +02:00
|
|
|
SAnimationPropertyConfig* m_pConfig = nullptr;
|
2022-04-23 14:16:02 +02:00
|
|
|
|
|
|
|
bool m_bDummy = true;
|
|
|
|
|
2022-04-23 21:47:16 +02:00
|
|
|
std::chrono::system_clock::time_point animationBegin;
|
|
|
|
|
2022-05-05 14:02:30 +02:00
|
|
|
ANIMATEDVARTYPE m_eVarType = AVARTYPE_INVALID;
|
|
|
|
AVARDAMAGEPOLICY m_eDamagePolicy = AVARDAMAGE_INVALID;
|
2022-04-23 14:16:02 +02:00
|
|
|
|
|
|
|
friend class CAnimationManager;
|
2022-05-12 11:27:31 +02:00
|
|
|
friend class CWorkspace;
|
2022-05-14 17:23:46 +02:00
|
|
|
friend struct SLayerSurface;
|
2022-04-23 14:16:02 +02:00
|
|
|
};
|