| 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 | |
| 16 | class CEnvelope; |
| 17 | |
| 18 | class CEnvelopeEditor : public CEditorComponent |
| 19 | { |
| 20 | public: |
| 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 | |
| 37 | private: |
| 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 : public SPopupMenuId |
| 95 | { |
| 96 | public: |
| 97 | CEnvelopeEditor *; |
| 98 | static CUi::EPopupMenuFunctionResult (void *pContext, CUIRect View, bool Active); |
| 99 | |
| 100 | private: |
| 101 | int [4] = {0}; |
| 102 | CLineInputNumber ; |
| 103 | CLineInputNumber ; |
| 104 | float = 0.0f; |
| 105 | float = 0.0f; |
| 106 | const char = 0; |
| 107 | const char = 0; |
| 108 | }; |
| 109 | CPopupEnvelopePoint ; |
| 110 | |
| 111 | class : public SPopupMenuId |
| 112 | { |
| 113 | public: |
| 114 | CEnvelopeEditor *; |
| 115 | static CUi::EPopupMenuFunctionResult (void *pContext, CUIRect View, bool Active); |
| 116 | |
| 117 | private: |
| 118 | const char = 0; |
| 119 | }; |
| 120 | CPopupEnvelopePointMulti ; |
| 121 | |
| 122 | class : public SPopupMenuId |
| 123 | { |
| 124 | public: |
| 125 | CEnvelopeEditor *; |
| 126 | static CUi::EPopupMenuFunctionResult (void *pContext, CUIRect View, bool Active); |
| 127 | |
| 128 | private: |
| 129 | const char [NUM_CURVETYPES - 1] = {0}; |
| 130 | }; |
| 131 | CPopupEnvelopePointCurveType ; |
| 132 | |
| 133 | class : public SPopupMenuId |
| 134 | { |
| 135 | public: |
| 136 | CEnvelopeEditor *; |
| 137 | int ; |
| 138 | static CUi::EPopupMenuFunctionResult (void *pContext, CUIRect View, bool Active); |
| 139 | |
| 140 | private: |
| 141 | const char [NUM_CURVETYPES] = {0}; |
| 142 | }; |
| 143 | CPopupEnvelopeCurveType ; |
| 144 | }; |
| 145 | |
| 146 | #endif |
| 147 | |