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
36private:
37 void RenderColorBar(CUIRect ColorBar, const std::shared_ptr<CEnvelope> &pEnvelope);
38
39 void UpdateHotEnvelopeObject(const CUIRect &View, const CEnvelope *pEnvelope, int ActiveChannels);
40
41 void ZoomAdaptOffsetX(float ZoomFactor, const CUIRect &View);
42 void UpdateZoomEnvelopeX(const CUIRect &View);
43
44 void ZoomAdaptOffsetY(float ZoomFactor, const CUIRect &View);
45 void UpdateZoomEnvelopeY(const CUIRect &View);
46
47 void ResetZoomEnvelope(const std::shared_ptr<CEnvelope> &pEnvelope, int ActiveChannels);
48 void RemoveTimeOffsetEnvelope(const std::shared_ptr<CEnvelope> &pEnvelope);
49
50 float ScreenToEnvelopeX(const CUIRect &View, float x) const;
51 float EnvelopeToScreenX(const CUIRect &View, float x) const;
52 float ScreenToEnvelopeY(const CUIRect &View, float y) const;
53 float EnvelopeToScreenY(const CUIRect &View, float y) const;
54 float ScreenToEnvelopeDeltaX(const CUIRect &View, float DeltaX);
55 float ScreenToEnvelopeDeltaY(const CUIRect &View, float DeltaY);
56
57 const char m_RedoButtonId = 0;
58 const char m_UndoButtonId = 0;
59 const char m_NewSoundEnvelopeButtonId = 0;
60 const char m_NewColorEnvelopeButtonId = 0;
61 const char m_NewPositionEnvelopeButtonId = 0;
62 const char m_DeleteButtonId = 0;
63 const char m_MoveRightButtonId = 0;
64 const char m_MoveLeftButtonId = 0;
65 const char m_ZoomOutButtonId = 0;
66 const char m_ResetZoomButtonId = 0;
67 const char m_ZoomInButtonId = 0;
68 const char m_EnvelopeSelectorId = 0;
69 const char m_PrevEnvelopeButtonId = 0;
70 const char m_NextEnvelopeButtonId = 0;
71 const char m_aChannelButtonIds[CEnvPoint::MAX_CHANNELS] = {0};
72 const char m_EnvelopeEditorId = 0;
73 CLineInput m_NameInput;
74 int m_EnvelopeEditorButtonUsed;
75 EEnvelopeEditorOp m_Operation;
76 std::vector<float> m_vAccurateDragValuesX;
77 std::vector<float> m_vAccurateDragValuesY;
78 vec2 m_MouseStart;
79 vec2 m_ScaleFactor;
80 vec2 m_Midpoint;
81 std::vector<float> m_vInitialPositionsX;
82 std::vector<float> m_vInitialPositionsY;
83
84 class CPopupEnvelopePoint : public SPopupMenuId
85 {
86 public:
87 CEnvelopeEditor *m_pEnvelopeEditor;
88 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
89
90 private:
91 int m_aValues[4] = {0};
92 CLineInputNumber m_ValueInput;
93 CLineInputNumber m_TimeInput;
94 float m_CurrentTime = 0.0f;
95 float m_CurrentValue = 0.0f;
96 const char m_ColorPickerButtonId = 0;
97 const char m_DeleteButtonId = 0;
98 };
99 CPopupEnvelopePoint m_PopupEnvelopePoint;
100
101 class CPopupEnvelopePointMulti : public SPopupMenuId
102 {
103 public:
104 CEnvelopeEditor *m_pEnvelopeEditor;
105 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
106
107 private:
108 const char m_ProjectOntoButtonId = 0;
109 };
110 CPopupEnvelopePointMulti m_PopupEnvelopePointMulti;
111
112 class CPopupEnvelopePointCurveType : public SPopupMenuId
113 {
114 public:
115 CEnvelopeEditor *m_pEnvelopeEditor;
116 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
117
118 private:
119 const char m_aButtonIds[NUM_CURVETYPES - 1] = {0};
120 };
121 CPopupEnvelopePointCurveType m_PopupEnvelopePointCurveType;
122
123 class CPopupEnvelopeCurveType : public SPopupMenuId
124 {
125 public:
126 CEnvelopeEditor *m_pEnvelopeEditor;
127 int m_SelectedPoint;
128 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
129
130 private:
131 const char m_aButtonIds[NUM_CURVETYPES] = {0};
132 };
133 CPopupEnvelopeCurveType m_PopupEnvelopeCurveType;
134};
135
136#endif
137