| 1 | #ifndef GAME_EDITOR_SMOOTH_VALUE_H |
| 2 | #define GAME_EDITOR_SMOOTH_VALUE_H |
| 3 | |
| 4 | #include "editor_object.h" |
| 5 | |
| 6 | #include <base/bezier.h> |
| 7 | |
| 8 | /** |
| 9 | * A value that is changed smoothly over time. |
| 10 | */ |
| 11 | class CSmoothValue : public CEditorObject |
| 12 | { |
| 13 | public: |
| 14 | CSmoothValue() = default; |
| 15 | CSmoothValue(float InitialValue, float MinValue, float MaxValue); |
| 16 | |
| 17 | /** |
| 18 | * Set a new target which the value should change to. |
| 19 | */ |
| 20 | void SetValue(float Target); |
| 21 | |
| 22 | /** |
| 23 | * Scale the value by the given amount. |
| 24 | */ |
| 25 | void ScaleValue(float Factor); |
| 26 | |
| 27 | /** |
| 28 | * Set the value to the target instantly. If the value was changing the |
| 29 | * target will be discarded. |
| 30 | */ |
| 31 | void SetValueInstant(float Target); |
| 32 | |
| 33 | bool UpdateValue(); |
| 34 | |
| 35 | float GetValue() const; |
| 36 | void SetValueRange(float MinValue, float MaxValue); |
| 37 | float GetMinValue() const; |
| 38 | float GetMaxValue() const; |
| 39 | |
| 40 | private: |
| 41 | float Progress(float CurrentTime) const; |
| 42 | |
| 43 | bool m_Smoothing; |
| 44 | float m_Value; |
| 45 | CCubicBezier m_ValueSmoothing; |
| 46 | float m_ValueSmoothingTarget; |
| 47 | float m_ValueSmoothingStart; |
| 48 | float m_ValueSmoothingEnd; |
| 49 | |
| 50 | float m_MinValue; |
| 51 | float m_MaxValue; |
| 52 | }; |
| 53 | |
| 54 | #endif |
| 55 | |