1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3
4#ifndef GAME_EDITOR_ENVELOPE_EDITOR_H
5#define GAME_EDITOR_ENVELOPE_EDITOR_H
6
7#include <game/client/ui.h>
8#include <game/editor/component.h>
9#include <game/editor/editor_trackers.h>
10#include <game/editor/smooth_value.h>
11#include <game/mapitems.h>
12
13#include <memory>
14#include <vector>
15
16class CEnvelope;
17
18class CEnvelopeEditor : public CEditorComponent
19{
20public:
21 class CState
22 {
23 public:
24 CSmoothValue m_ZoomX;
25 CSmoothValue m_ZoomY;
26 bool m_ResetZoom;
27 vec2 m_Offset;
28 int m_ActiveChannels;
29
30 void Reset(CEditor *pEditor);
31 };
32
33 void OnReset() override;
34 void Render(CUIRect View);
35 bool IsPointOperationActive() const;
36
37private:
38 void RenderColorBar(CUIRect ColorBar, const std::shared_ptr<CEnvelope> &pEnvelope);
39 void RenderPointTimeTooltip(CUIRect View, int PointIndex, const std::shared_ptr<CEnvelope> &pEnvelope);
40 void RenderPointValueTooltip(CUIRect View, int PointIndex, const std::shared_ptr<CEnvelope> &pEnvelope);
41 void RenderTangentInTooltip(CUIRect View, int PointIndex, int Channel, const std::shared_ptr<CEnvelope> &pEnvelope);
42 void RenderTangentOutTooltip(CUIRect View, int PointIndex, int Channel, const std::shared_ptr<CEnvelope> &pEnvelope);
43 void RenderTangentTooltip(CUIRect View, int PointIndex, int Channel, CFixedTime Time, int Value, const std::shared_ptr<CEnvelope> &pEnvelope);
44 void RenderScaleTooltip(CUIRect View, const std::shared_ptr<CEnvelope> &pEnvelope);
45 void RenderTimebarTooltip(CUIRect View, const std::shared_ptr<CEnvelope> &pEnvelope);
46 void RenderTooltip(CUIRect *pTooltipRect, CUIRect Boundary);
47
48 void UpdateHotEnvelopeObject(const CUIRect &View, const CEnvelope *pEnvelope, int ActiveChannels);
49
50 void ZoomAdaptOffsetX(float ZoomFactor, const CUIRect &View);
51 void UpdateZoomEnvelopeX(const CUIRect &View);
52
53 void ZoomAdaptOffsetY(float ZoomFactor, const CUIRect &View);
54 void UpdateZoomEnvelopeY(const CUIRect &View);
55
56 void ResetZoomEnvelope(const std::shared_ptr<CEnvelope> &pEnvelope, int ActiveChannels);
57 void RemoveTimeOffsetEnvelope(const std::shared_ptr<CEnvelope> &pEnvelope);
58
59 float ScreenToEnvelopeX(const CUIRect &View, float x) const;
60 float EnvelopeToScreenX(const CUIRect &View, float x) const;
61 float ScreenToEnvelopeY(const CUIRect &View, float y) const;
62 float EnvelopeToScreenY(const CUIRect &View, float y) const;
63 float ScreenToEnvelopeDeltaX(const CUIRect &View, float DeltaX);
64 float ScreenToEnvelopeDeltaY(const CUIRect &View, float DeltaY);
65
66 const char m_RedoButtonId = 0;
67 const char m_UndoButtonId = 0;
68 const char m_NewSoundEnvelopeButtonId = 0;
69 const char m_NewColorEnvelopeButtonId = 0;
70 const char m_NewPositionEnvelopeButtonId = 0;
71 const char m_DeleteButtonId = 0;
72 const char m_MoveRightButtonId = 0;
73 const char m_MoveLeftButtonId = 0;
74 const char m_ZoomOutButtonId = 0;
75 const char m_ResetZoomButtonId = 0;
76 const char m_ZoomInButtonId = 0;
77 const char m_EnvelopeSelectorId = 0;
78 const char m_PrevEnvelopeButtonId = 0;
79 const char m_NextEnvelopeButtonId = 0;
80 const char m_aChannelButtonIds[CEnvPoint::MAX_CHANNELS] = {0};
81 const char m_EnvelopeEditorId = 0;
82 const char m_ScaleOperationId = 0;
83 CLineInput m_NameInput;
84 int m_EnvelopeEditorButtonUsed;
85 EEnvelopeEditorOp m_Operation;
86 std::vector<float> m_vAccurateDragValuesX;
87 std::vector<float> m_vAccurateDragValuesY;
88 vec2 m_MouseStart;
89 vec2 m_ScaleFactor;
90 vec2 m_Midpoint;
91 std::vector<float> m_vInitialPositionsX;
92 std::vector<float> m_vInitialPositionsY;
93
94 class CPopupEnvelopePoint : public SPopupMenuId
95 {
96 public:
97 CEnvelopeEditor *m_pEnvelopeEditor;
98 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
99
100 private:
101 int m_aValues[4] = {0};
102 CLineInputNumber m_ValueInput;
103 CLineInputNumber m_TimeInput;
104 float m_CurrentTime = 0.0f;
105 float m_CurrentValue = 0.0f;
106 const char m_ColorPickerButtonId = 0;
107 const char m_DeleteButtonId = 0;
108 };
109 CPopupEnvelopePoint m_PopupEnvelopePoint;
110
111 class CPopupEnvelopePointMulti : public SPopupMenuId
112 {
113 public:
114 CEnvelopeEditor *m_pEnvelopeEditor;
115 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
116
117 private:
118 const char m_ProjectOntoButtonId = 0;
119 };
120 CPopupEnvelopePointMulti m_PopupEnvelopePointMulti;
121
122 class CPopupEnvelopePointCurveType : public SPopupMenuId
123 {
124 public:
125 CEnvelopeEditor *m_pEnvelopeEditor;
126 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
127
128 private:
129 const char m_aButtonIds[NUM_CURVETYPES - 1] = {0};
130 };
131 CPopupEnvelopePointCurveType m_PopupEnvelopePointCurveType;
132
133 class CPopupEnvelopeCurveType : public SPopupMenuId
134 {
135 public:
136 CEnvelopeEditor *m_pEnvelopeEditor;
137 int m_SelectedPoint;
138 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
139
140 private:
141 const char m_aButtonIds[NUM_CURVETYPES] = {0};
142 };
143 CPopupEnvelopeCurveType m_PopupEnvelopeCurveType;
144};
145
146#endif
147