Plasma Engine  2.0
Loading...
Searching...
No Matches
CurveEditData.h
1#pragma once
2
3#include <Foundation/Containers/DynamicArray.h>
4#include <Foundation/Math/Color8UNorm.h>
5#include <Foundation/Math/Vec2.h>
6#include <Foundation/Reflection/Reflection.h>
7#include <Foundation/Tracks/Curve1D.h>
8#include <GuiFoundation/GuiFoundationDLL.h>
9
10class plCurve1D;
11
12PL_DECLARE_REFLECTABLE_TYPE(PL_GUIFOUNDATION_DLL, plCurveTangentMode);
13
14template <typename T>
15void FindNearestControlPoints(plArrayPtr<T> cps, plInt64 iTick, T*& ref_pLlhs, T*& lhs, T*& rhs, T*& ref_pRrhs)
16{
17 ref_pLlhs = nullptr;
18 lhs = nullptr;
19 rhs = nullptr;
20 ref_pRrhs = nullptr;
21 plInt64 lhsTick = plMath::MinValue<plInt64>();
22 plInt64 llhsTick = plMath::MinValue<plInt64>();
23 plInt64 rhsTick = plMath::MaxValue<plInt64>();
24 plInt64 rrhsTick = plMath::MaxValue<plInt64>();
25
26 for (decltype(auto) cp : cps)
27 {
28 if (cp.m_iTick <= iTick)
29 {
30 if (cp.m_iTick > lhsTick)
31 {
32 ref_pLlhs = lhs;
33 llhsTick = lhsTick;
34
35 lhs = &cp;
36 lhsTick = cp.m_iTick;
37 }
38 else if (cp.m_iTick > llhsTick)
39 {
40 ref_pLlhs = &cp;
41 llhsTick = cp.m_iTick;
42 }
43 }
44
45 if (cp.m_iTick > iTick)
46 {
47 if (cp.m_iTick < rhsTick)
48 {
49 ref_pRrhs = rhs;
50 rrhsTick = rhsTick;
51
52 rhs = &cp;
53 rhsTick = cp.m_iTick;
54 }
55 else if (cp.m_iTick < rrhsTick)
56 {
57 ref_pRrhs = &cp;
58 rrhsTick = cp.m_iTick;
59 }
60 }
61 }
62}
63
64class PL_GUIFOUNDATION_DLL plCurveControlPointData : public plReflectedClass
65{
66 PL_ADD_DYNAMIC_REFLECTION(plCurveControlPointData, plReflectedClass);
67
68public:
69 plTime GetTickAsTime() const { return plTime::MakeFromSeconds(m_iTick / 4800.0); }
70 void SetTickFromTime(plTime time, plInt64 iFps);
71
72 plInt64 m_iTick; // 4800 ticks per second
73 double m_fValue;
74 plVec2 m_LeftTangent = plVec2(-0.1f, 0.0f);
75 plVec2 m_RightTangent = plVec2(+0.1f, 0.0f);
76 bool m_bTangentsLinked = true;
77 plEnum<plCurveTangentMode> m_LeftTangentMode;
78 plEnum<plCurveTangentMode> m_RightTangentMode;
79};
80
81class PL_GUIFOUNDATION_DLL plSingleCurveData : public plReflectedClass
82{
83 PL_ADD_DYNAMIC_REFLECTION(plSingleCurveData, plReflectedClass);
84
85public:
86 plColorGammaUB m_CurveColor;
88
89 void ConvertToRuntimeData(plCurve1D& out_result) const;
90 double Evaluate(plInt64 iTick) const;
91};
92
93class PL_GUIFOUNDATION_DLL plCurveExtentsAttribute : public plPropertyAttribute
94{
95 PL_ADD_DYNAMIC_REFLECTION(plCurveExtentsAttribute, plPropertyAttribute);
96
97public:
98 plCurveExtentsAttribute() = default;
99 plCurveExtentsAttribute(double fLowerExtent, bool bLowerExtentFixed, double fUpperExtent, bool bUpperExtentFixed);
100
101 double m_fLowerExtent = 0.0;
102 double m_fUpperExtent = 1.0;
103 bool m_bLowerExtentFixed = false;
104 bool m_bUpperExtentFixed = false;
105};
106
107
108class PL_GUIFOUNDATION_DLL plCurveGroupData : public plReflectedClass
109{
110 PL_ADD_DYNAMIC_REFLECTION(plCurveGroupData, plReflectedClass);
111
112public:
113 plCurveGroupData() = default;
114 plCurveGroupData(const plCurveGroupData& rhs) = delete;
116 plCurveGroupData& operator=(const plCurveGroupData& rhs) = delete;
117
119 void CloneFrom(const plCurveGroupData& rhs);
120
122 void Clear();
123
125 bool m_bOwnsData = true;
127 plUInt16 m_uiFramesPerSecond = 60;
128
129 plInt64 TickFromTime(plTime time) const;
130
131 void ConvertToRuntimeData(plUInt32 uiCurveIdx, plCurve1D& out_result) const;
132};
133
134struct PL_GUIFOUNDATION_DLL plSelectedCurveCP
135{
136 PL_DECLARE_POD_TYPE();
137
138 plUInt16 m_uiCurve;
139 plUInt16 m_uiPoint;
140};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:99
A 1D curve for animating a single value over time.
Definition Curve1D.h:29
Definition CurveEditData.h:65
Definition CurveEditData.h:94
Definition CurveEditData.h:109
Definition DynamicArray.h:81
Base class of all attributes can be used to decorate a RTTI property.
Definition PropertyAttributes.h:11
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
Definition CurveEditData.h:82
constexpr TYPE MaxValue()
Returns the largest possible positive value (that is not infinity).
constexpr TYPE MinValue()
Returns the smallest possible value (that is not -infinity). Usually zero or -MaxValue()....
Definition Curve1D.h:13
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition CurveEditData.h:135
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
PL_ALWAYS_INLINE static constexpr plTime MakeFromSeconds(double fSeconds)
Creates an instance of plTime that was initialized from seconds.
Definition Time.h:30