1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #ifndef __SplineCtrl_h__
4 #define __SplineCtrl_h__
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)
20 //////////////////////////////////////////////////////////////////////////
22 //////////////////////////////////////////////////////////////////////////
23 class PLUGIN_API CSplineCtrl
: public CWnd
26 DECLARE_DYNAMIC(CSplineCtrl
)
29 virtual ~CSplineCtrl();
31 BOOL
Create(DWORD dwStyle
, const CRect
& rc
, CWnd
* pParentWnd
, UINT nID
);
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
);
53 typedef Functor1
<CSplineCtrl
*> UpdateCallback
;
54 void SetUpdateCallback(const UpdateCallback
& cb
) { m_updateCallback
= cb
; };
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
);
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
88 void TrackKey(CPoint point
);
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
);
104 ISplineInterpolator
* m_pSpline
;
117 int m_nKeyDrawRadius
;
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__