!XT (BREAK-16) (Sandbox) Remove double-newlines at the end of files.
[CRYENGINE.git] / Code / Sandbox / Plugins / MFCToolsPlugin / Controls / SplineCtrl.h
blob5e85a05e9c1ac1828b3b88e8bd5a1bd12b9538c1
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #ifndef __SplineCtrl_h__
4 #define __SplineCtrl_h__
5 #pragma once
7 #include <CryMath/ISplines.h>
9 // Custom styles for this control.
10 #define SPLINE_STYLE_NOGRID 0x0001
11 #define SPLINE_STYLE_NO_TIME_MARKER 0x0002
13 // Notify event sent when spline is being modified.
14 #define SPLN_CHANGE (0x0001)
15 // Notify event sent just before when spline is modified.
16 #define SPLN_BEFORE_CHANGE (0x0002)
18 class CTimelineCtrl;
20 //////////////////////////////////////////////////////////////////////////
21 // Spline control.
22 //////////////////////////////////////////////////////////////////////////
23 class PLUGIN_API CSplineCtrl : public CWnd
25 public:
26 DECLARE_DYNAMIC(CSplineCtrl)
28 CSplineCtrl();
29 virtual ~CSplineCtrl();
31 BOOL Create(DWORD dwStyle, const CRect& rc, CWnd* pParentWnd, UINT nID);
33 //Key functions
34 int GetActiveKey() { return m_nActiveKey; };
35 void SetActiveKey(int nIndex);
36 int InsertKey(CPoint point);
37 void ToggleKeySlope(int nIndex, int nDist);
39 void SetGrid(int numX, int numY) { m_gridX = numX; m_gridY = numY; };
40 void SetTimeRange(float tmin, float tmax) { m_fMinTime = tmin; m_fMaxTime = tmax; }
41 void SetValueRange(float tmin, float tmax) { m_fMinValue = tmin; m_fMaxValue = tmax; if (m_fMinValue == m_fMaxValue) m_fMaxValue = m_fMinValue + 0.001f; }
42 void SetTooltipValueScale(float x, float y) { m_fTooltipScaleX = x; m_fTooltipScaleY = y; };
43 // Lock value of first and last key to be the same.
44 void LockFirstAndLastKeys(bool bLock) { m_bLockFirstLastKey = bLock; }
46 void SetSpline(ISplineInterpolator* pSpline, BOOL bRedraw = FALSE);
47 ISplineInterpolator* GetSpline();
49 void SetTimeMarker(float fTime);
50 void SetTimelineCtrl(CTimelineCtrl* pTimelineCtrl);
51 void UpdateToolTip();
53 typedef Functor1<CSplineCtrl*> UpdateCallback;
54 void SetUpdateCallback(const UpdateCallback& cb) { m_updateCallback = cb; };
56 protected:
57 enum EHitCode
59 HIT_NOTHING,
60 HIT_KEY,
61 HIT_SPLINE,
64 DECLARE_MESSAGE_MAP()
66 virtual BOOL PreTranslateMessage(MSG* pMsg);
67 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
68 afx_msg void OnPaint();
69 afx_msg void OnSize(UINT nType, int cx, int cy);
70 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
71 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
72 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
73 afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
74 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
75 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
76 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
78 // Drawing functions
79 void DrawGrid(CDC* pDC);
80 void DrawSpline(CDC* pDC);
81 void DrawKeys(CDC* pDC);
82 void DrawTimeMarker(CDC* pDC);
84 EHitCode HitTest(CPoint point);
86 //Tracking support helper functions
87 void StartTracking();
88 void TrackKey(CPoint point);
89 void StopTracking();
90 void RemoveKey(int nKey);
92 CPoint KeyToPoint(int nKey);
93 CPoint TimeToPoint(float time);
94 void PointToTimeValue(CPoint point, float& time, float& value);
95 float XOfsToTime(int x);
96 CPoint XOfsToPoint(int x);
98 void ClearSelection();
99 void ValidateSpline();
101 void SendNotifyEvent(int nEvent);
103 private:
104 ISplineInterpolator* m_pSpline;
106 CRect m_rcClipRect;
107 CRect m_rcSpline;
109 CPoint m_hitPoint;
110 EHitCode m_hitCode;
111 int m_nHitKeyIndex;
112 int m_nHitKeyDist;
114 float m_fTimeMarker;
116 int m_nActiveKey;
117 int m_nKeyDrawRadius;
119 bool m_bTracking;
121 int m_gridX;
122 int m_gridY;
124 float m_fMinTime, m_fMaxTime;
125 float m_fMinValue, m_fMaxValue;
126 float m_fTooltipScaleX, m_fTooltipScaleY;
128 bool m_bLockFirstLastKey;
130 std::vector<int> m_bSelectedKeys;
132 CToolTipCtrl m_tooltip;
134 CTimelineCtrl* m_pTimelineCtrl;
136 CBitmap m_offscreenBitmap;
137 CRect m_TimeUpdateRect;
139 UpdateCallback m_updateCallback;
142 #endif // __SplineCtrl_h__