Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

368 lines
9.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef EXPRESSIONTOOL_H
  8. #define EXPRESSIONTOOL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <mxtk/mx.h>
  13. #include "studio.h"
  14. #include "UtlVector.h"
  15. #include "tier1/utldict.h"
  16. #include "faceposertoolwindow.h"
  17. class CChoreoEvent;
  18. class TimelineItem;
  19. class CFlexAnimationTrack;
  20. class CExpClass;
  21. class CChoreoWidgetDrawHelper;
  22. class CExpressionToolWorkspace;
  23. class CChoreoView;
  24. class CFlexTimingTag;
  25. class CExpression;
  26. class mxSlider;
  27. #define IDC_EXPRESSIONTOOLVSCROLL 1000
  28. #define IDC_ADDTRACKS 1001
  29. #define IDC_COLLAPSEALL 1002
  30. #define IDC_EXPANDALL 1003
  31. #define IDC_EXPANDVALID 1004
  32. #define IDC_INSERT_TIMING_TAG 1005
  33. #define IDC_DELETE_TIMING_TAG 1006
  34. #define IDC_LOCK_TIMING_TAG 1007
  35. #define IDC_UNLOCK_TIMING_TAG 1008
  36. #define IDC_COPY_TO_FLEX 1009
  37. #define IDC_COPY_FROM_FLEX 1010
  38. #define IDC_NEW_EXPRESSION_FROM_FLEXANIMATION 1011
  39. #define IDC_EXPORT_FA 1012
  40. #define IDC_IMPORT_FA 1013
  41. #define IDC_REDO_FA 1014
  42. #define IDC_UNDO_FA 1015
  43. #define IDC_TL_COPY 1016
  44. #define IDC_TL_PASTE 1017
  45. #define IDC_TL_DELETE 1018
  46. #define IDC_TL_DESELECT 1019
  47. #define IDC_TL_SELECTALL 1020
  48. #define IDC_TL_COLLAPSE 1021
  49. #define IDC_TL_EXPAND 1022
  50. #define IDC_TL_ENABLE 1023
  51. #define IDC_TL_DISABLE 1024
  52. #define IDC_TL_EDITNORMAL 1025
  53. #define IDC_TL_EDITLEFTRIGHT 1026
  54. #define IDC_COLLAPSE_ALL_EXCEPT 1027
  55. #define IDC_DISABLE_ALL_EXCEPT 1028
  56. #define IDC_ENABLE_ALL_VALID 1029
  57. #define IDC_TL_SNAPSELECTED 1030
  58. #define IDC_TL_SNAPPOINTS 1031
  59. #define IDC_TL_DELETECOLUMN 1032
  60. #define IDC_TL_SNAPALL 1033
  61. #define IDC_FLEX_CHANGESCALE 1034
  62. #define IDC_FLEXHSCROLL 1035
  63. #define IDC_ET_SORT_BY_USED 1036
  64. #define IDC_ET_SORT_BY_NAME 1037
  65. #define IDC_ET_SELECTION_DELETE 1038
  66. #define IDC_ET_SELECTION_EXCISE 1039
  67. #define IDC_ET_RESET_ITEM_SIZE 1040
  68. #define IDC_ET_RESET_ALL_ITEM_SIZES 1041
  69. #define IDC_FLEX_SCALESAMPLES 1042
  70. #define IDC_TL_KB_TENSION 1050
  71. #define IDC_TL_KB_BIAS 1051
  72. #define IDC_TL_KB_CONTINUITY 1052
  73. #define IDC_ET_EDGEPROPERTIES 1053
  74. #define IDC_ET_SELECTION_COPY 1054
  75. #define IDC_ET_SELECTION_PASTE 1055
  76. #include "ExpressionSample.h"
  77. class ExpressionTool : public mxWindow, public IFacePoserToolWindow
  78. {
  79. public:
  80. // Construction
  81. ExpressionTool( mxWindow *parent );
  82. ~ExpressionTool( void );
  83. virtual void Think( float dt );
  84. void ScrubThink( float dt, bool scrubbing );
  85. virtual bool IsScrubbing( void ) const;
  86. virtual bool IsProcessing( void );
  87. virtual int handleEvent( mxEvent *event );
  88. virtual void redraw( void );
  89. virtual bool PaintBackground();
  90. bool SetFlexAnimationTrackFromExpression( int mx, int my, CExpClass *cl, CExpression *exp );
  91. void SetEvent( CChoreoEvent *event );
  92. bool HasCopyData( void );
  93. void Copy( CFlexAnimationTrack *source );
  94. void Paste( CFlexAnimationTrack *destination );
  95. void GetScrubHandleRect( RECT& rcHandle, bool clipped = false );
  96. void DrawScrubHandle( CChoreoWidgetDrawHelper& drawHelper, RECT& rcHandle );
  97. void DrawEventEnd( CChoreoWidgetDrawHelper& drawHelper );
  98. CChoreoEvent *GetSafeEvent( void );
  99. void ExpandAll( void );
  100. void ExpandValid( void );
  101. void LayoutItems( bool force = false );
  102. void OnCopyToFlex( bool isEdited );
  103. void OnCopyFromFlex( bool isEdited );
  104. void OnCopyToFlex( float scenetime, bool isEdited );
  105. void OnCopyFromFlex( float scenetime, bool isEdited );
  106. void OnSetSingleKeyFromFlex( char const *sliderName );
  107. void OnNewExpression( void );
  108. void ShowContextMenu( mxEvent *event, bool include_track_menus );
  109. void ForceScrubPosition( float newtime );
  110. void ForceScrubPositionFromSceneTime( float scenetime );
  111. void SetScrubTime( float t );
  112. void SetScrubTargetTime( float t );
  113. void DrawScrubHandles();
  114. void SetClickedPos( int x, int y );
  115. float GetTimeForClickedPos( void );
  116. void SetMouseOverPos( int x, int y );
  117. void GetMouseOverPos( int &x, int& y );
  118. void GetMouseOverPosRect( RECT& rcPos );
  119. void DrawMouseOverPos( CChoreoWidgetDrawHelper& drawHelper, RECT& rcPos );
  120. void DrawMouseOverPos();
  121. void MoveSelectedSamples( float dfdx, float dfdy, bool snap );
  122. void DeleteSelectedSamples( void );
  123. int CountSelectedSamples( void );
  124. void DeselectAll( void );
  125. void RepositionHSlider( void );
  126. bool IsFocusItem( TimelineItem *item );
  127. virtual void OnModelChanged();
  128. float GetScrub() const { return m_flScrub; }
  129. float GetScrubberSceneTime();
  130. void GetTimelineItems( CUtlVector< TimelineItem * >& list );
  131. void InvalidateLayout( void );
  132. private:
  133. void DoTrackLookup( CChoreoEvent *event );
  134. void AddFlexTimingTag( int mx );
  135. void DeleteFlexTimingTag( int mx, int my );
  136. void OnSortByUsed( void );
  137. void OnSortByName( void );
  138. void OnDeleteSelection( bool excise_time );
  139. void OnResetItemSize();
  140. void OnResetAllItemSizes();
  141. void ResampleControlPoints( CFlexTimingTag *tag, float newposition );
  142. void OnScaleSamples();
  143. void LockTimingTag( void );
  144. void UnlockTimingTag( void );
  145. bool GetTimingTagRect( RECT& rcClient, CChoreoEvent *event, CFlexTimingTag *tag, RECT& rcTag );
  146. // float MouseToFrac( int mx );
  147. //float MouseToTime( int mx );
  148. // int TimeToMouse( float t );
  149. void GetWorkspaceLeftRight( int& left, int& right );
  150. bool IsMouseOverScrubHandle( mxEvent *event );
  151. CFlexTimingTag *IsMouseOverTag( int mx, int my );
  152. void DrawRelativeTags( CChoreoWidgetDrawHelper& drawHelper );
  153. void DrawFocusRect( void );
  154. void ApplyBounds( int& mx, int& my );
  155. void CalcBounds( int movetype );
  156. void OnExportFlexAnimation( void );
  157. void OnImportFlexAnimation( void );
  158. void OnUndo( void );
  159. void OnRedo( void );
  160. void StartDragging( int dragtype, int startx, int starty, HCURSOR cursor );
  161. void GetWorkspaceRect( RECT &rc );
  162. void AddFocusRect( RECT& rc );
  163. void OnMouseMove( mxEvent *event );
  164. // Mouse control over selected samples
  165. void SelectPoints( float starttime, float endtime );
  166. void FinishSelect( int startx, int mx );
  167. void FinishMoveSelection( int startx, int mx );
  168. void FinishMoveSelectionStart( int startx, int mx );
  169. void FinishMoveSelectionEnd( int startx, int mx );
  170. // In general over the point area tray
  171. bool IsMouseOverPoints( int mx, int my );
  172. // Specifically over selected points
  173. bool IsMouseOverSelection( int mx, int my );
  174. bool IsMouseOverSelectionStartEdge( mxEvent *event );
  175. bool IsMouseOverSelectionEndEdge( mxEvent *event );
  176. // Readjust slider
  177. void MoveTimeSliderToPos( int x );
  178. void OnChangeScale();
  179. int ComputeHPixelsNeeded( void );
  180. float GetTimeValueForMouse( int mx, bool clip = false );
  181. void OnEdgeProperties();
  182. public:
  183. int GetPixelForTimeValue( float time, bool *clipped = NULL );
  184. float GetPixelsPerSecond( void );
  185. void GetStartAndEndTime( float& st, float& ed );
  186. float GetEventEndTime();
  187. private:
  188. class CColumnCopier
  189. {
  190. public:
  191. class CTrackData
  192. {
  193. public:
  194. CTrackData() {};
  195. CTrackData( const CTrackData& other )
  196. {
  197. m_Samples[ 0 ].CopyArray( other.m_Samples[ 0 ].Base(), other.m_Samples[ 0 ].Count() );
  198. m_Samples[ 1 ].CopyArray( other.m_Samples[ 1 ].Base(), other.m_Samples[ 1 ].Count() );
  199. }
  200. CUtlVector< CExpressionSample > m_Samples[ 2 ];
  201. };
  202. bool m_bActive;
  203. float m_flCopyTimes[ 2 ];
  204. CUtlDict< CTrackData, int > m_Data;
  205. CColumnCopier() : m_bActive( false )
  206. {
  207. m_flCopyTimes[ 0 ] = m_flCopyTimes[ 1 ] = 0.0f;
  208. }
  209. void Reset()
  210. {
  211. m_bActive = false;
  212. m_flCopyTimes[ 0 ] = m_flCopyTimes[ 1 ] = 0.0f;
  213. m_Data.Purge();
  214. }
  215. };
  216. bool HasCopiedColumn();
  217. void OnCopyColumn();
  218. void OnPasteColumn();
  219. void ClearColumnCopy();
  220. CColumnCopier m_ColumnCopy;
  221. int m_nFocusEventGlobalID;
  222. float m_flScrub;
  223. float m_flScrubTarget;
  224. enum
  225. {
  226. DRAGTYPE_NONE = 0,
  227. DRAGTYPE_SCRUBBER,
  228. DRAGTYPE_FLEXTIMINGTAG,
  229. DRAGTYPE_SELECTSAMPLES,
  230. DRAGTYPE_MOVESELECTION,
  231. DRAGTYPE_MOVESELECTIONSTART,
  232. DRAGTYPE_MOVESELECTIONEND,
  233. };
  234. HCURSOR m_hPrevCursor;
  235. int m_nDragType;
  236. int m_nStartX;
  237. int m_nStartY;
  238. int m_nLastX;
  239. int m_nLastY;
  240. int m_nClickedX;
  241. int m_nClickedY;
  242. bool m_bUseBounds;
  243. int m_nMinX;
  244. int m_nMaxX;
  245. struct CFocusRect
  246. {
  247. RECT m_rcOrig;
  248. RECT m_rcFocus;
  249. };
  250. CUtlVector < CFocusRect > m_FocusRects;
  251. CUtlVector< CExpressionSample > m_CopyData[2];
  252. CExpressionToolWorkspace *m_pWorkspace;
  253. CChoreoEvent *m_pLastEvent;
  254. int m_nMousePos[ 2 ];
  255. float m_flSelection[ 2 ];
  256. bool m_bSelectionActive;
  257. bool m_bSuppressLayout;
  258. // Height/width of scroll bars
  259. int m_nScrollbarHeight;
  260. float m_flLeftOffset;
  261. mxScrollbar *m_pHorzScrollBar;
  262. int m_nLastHPixelsNeeded;
  263. // How many pixels per second we are showing in the UI
  264. float m_flPixelsPerSecond;
  265. // Do we need to move controls?
  266. bool m_bLayoutIsValid;
  267. float m_flLastDuration;
  268. bool m_bInSetEvent;
  269. float m_flScrubberTimeOffset;
  270. friend class CChoreoView;
  271. };
  272. extern ExpressionTool *g_pExpressionTool;
  273. #endif // EXPRESSIONTOOL_H