Team Fortress 2 Source Code as on 22/4/2020
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.

205 lines
5.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef RAMPTOOL_H
  8. #define RAMPTOOL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <mxtk/mx.h>
  13. #include "studio.h"
  14. #include "utlvector.h"
  15. #include "faceposertoolwindow.h"
  16. class CChoreoEvent;
  17. class CChoreoWidgetDrawHelper;
  18. class CChoreoView;
  19. struct CExpressionSample;
  20. #define IDC_REDO_RT 1000
  21. #define IDC_UNDO_RT 1001
  22. #define IDC_RT_DELETE 1002
  23. #define IDC_RT_DESELECT 1003
  24. #define IDC_RT_SELECTALL 1004
  25. #define IDC_RT_CHANGESCALE 1005
  26. #define IDC_RAMPHSCROLL 1006
  27. #define IDC_RT_EDGEPROPERTIES 1007
  28. #define FP_RT_SELECTION_TOLERANCE 30.0f
  29. #define FP_RT_SELECTION_RECTANGLE_TOLERANCE 5.0f
  30. #define FP_RT_ADDSAMPLE_TOLERANCE 5.0f
  31. template< class T > class CCurveEditorHelper;
  32. class RampTool : public mxWindow, public IFacePoserToolWindow
  33. {
  34. public:
  35. // Construction
  36. RampTool( mxWindow *parent );
  37. ~RampTool( void );
  38. virtual void Think( float dt );
  39. void ScrubThink( float dt, bool scrubbing );
  40. virtual bool IsScrubbing( void ) const;
  41. virtual bool IsProcessing( void );
  42. virtual int handleEvent( mxEvent *event );
  43. virtual void redraw( void );
  44. virtual bool PaintBackground();
  45. void SetEvent( CChoreoEvent *event );
  46. void GetScrubHandleRect( RECT& rcHandle, float scrub, bool clipped = false );
  47. void DrawScrubHandle( CChoreoWidgetDrawHelper& drawHelper, RECT& rcHandle, float scrub, bool reference );
  48. void DrawTimeLine( CChoreoWidgetDrawHelper& drawHelper, RECT& rc, float left, float right );
  49. void DrawEventEnd( CChoreoWidgetDrawHelper& drawHelper );
  50. void SetMouseOverPos( int x, int y );
  51. void GetMouseOverPos( int &x, int& y );
  52. void GetMouseOverPosRect( RECT& rcPos );
  53. void DrawMouseOverPos( CChoreoWidgetDrawHelper& drawHelper, RECT& rcPos );
  54. void DrawMouseOverPos();
  55. void DrawScrubHandles();
  56. CChoreoEvent *GetSafeEvent( void );
  57. bool IsMouseOverScrubHandle( mxEvent *event );
  58. void ForceScrubPosition( float newtime );
  59. void ForceScrubPositionFromSceneTime( float scenetime );
  60. void SetScrubTime( float t );
  61. void SetScrubTargetTime( float t );
  62. void DrawSamplesSimple( CChoreoWidgetDrawHelper& drawHelper, CChoreoEvent *e, bool clearbackground, COLORREF sampleColor, RECT &rcSamples );
  63. virtual void OnModelChanged();
  64. void SetMousePositionForEvent( mxEvent *event );
  65. int NumSamples();
  66. CExpressionSample *GetSample( int idx );
  67. void PreDataChanged( char const *undodescription );
  68. void PostDataChanged( char const *redodescription );
  69. CExpressionSample *GetSampleUnderMouse( int mx, int my, float tolerance = FP_RT_SELECTION_TOLERANCE );
  70. void GetWorkList( bool reflect, CUtlVector< RampTool * >& list );
  71. private:
  72. void GetSampleTrayRect( RECT& rc );
  73. void DrawSamples( CChoreoWidgetDrawHelper& drawHelper, RECT &rcSamples );
  74. void SelectPoints( void );
  75. void DeselectAll();
  76. void SelectAll();
  77. void Delete( void );
  78. int CountSelected( void );
  79. void MoveSelectedSamples( float dfdx, float dfdy );
  80. void StartDragging( int dragtype, int startx, int starty, HCURSOR cursor );
  81. void AddFocusRect( RECT& rc );
  82. void OnMouseMove( mxEvent *event );
  83. void DrawFocusRect( void );
  84. void ShowContextMenu( mxEvent *event, bool include_track_menus );
  85. void GetWorkspaceLeftRight( int& left, int& right );
  86. void SetClickedPos( int x, int y );
  87. float GetTimeForClickedPos( void );
  88. void DrawAutoHighlight( mxEvent *event );
  89. void ApplyBounds( int& mx, int& my );
  90. void CalcBounds( int movetype );
  91. void OnUndo( void );
  92. void OnRedo( void );
  93. //CEventAbsoluteTag *IsMouseOverTag( int mx, int my );
  94. void OnRevert( void );
  95. void OnEdgeProperties();
  96. void DrawTimingTags( CChoreoWidgetDrawHelper& drawHelper, RECT& rc );
  97. void DrawRelativeTagsForEvent( CChoreoWidgetDrawHelper& drawHelper, RECT& rc, CChoreoEvent *rampevent, CChoreoEvent *event, float starttime, float endtime );
  98. void DrawAbsoluteTagsForEvent( CChoreoWidgetDrawHelper& drawHelper, RECT &rc, CChoreoEvent *rampevent, CChoreoEvent *event, float starttime, float endtime );
  99. // Readjust slider
  100. void MoveTimeSliderToPos( int x );
  101. void OnChangeScale();
  102. int ComputeHPixelsNeeded( void );
  103. float GetPixelsPerSecond( void );
  104. void InvalidateLayout( void );
  105. void RepositionHSlider( void );
  106. void GetStartAndEndTime( float& st, float& ed );
  107. float GetEventEndTime();
  108. float GetTimeValueForMouse( int mx, bool clip = false );
  109. int GetPixelForTimeValue( float time, bool *clipped = NULL );
  110. float m_flScrub;
  111. float m_flScrubTarget;
  112. enum
  113. {
  114. DRAGTYPE_NONE = 0,
  115. DRAGTYPE_SCRUBBER,
  116. DRAGTYPE_MOVEPOINTS_VALUE,
  117. DRAGTYPE_MOVEPOINTS_TIME,
  118. DRAGTYPE_SELECTION,
  119. };
  120. int m_nFocusEventGlobalID;
  121. int m_nMousePos[ 2 ];
  122. bool m_bUseBounds;
  123. int m_nMinX;
  124. int m_nMaxX;
  125. HCURSOR m_hPrevCursor;
  126. int m_nDragType;
  127. int m_nStartX;
  128. int m_nStartY;
  129. int m_nLastX;
  130. int m_nLastY;
  131. int m_nClickedX;
  132. int m_nClickedY;
  133. struct CFocusRect
  134. {
  135. RECT m_rcOrig;
  136. RECT m_rcFocus;
  137. };
  138. CUtlVector < CFocusRect > m_FocusRects;
  139. CChoreoEvent *m_pLastEvent;
  140. bool m_bSuppressLayout;
  141. // Height/width of scroll bars
  142. int m_nScrollbarHeight;
  143. float m_flLeftOffset;
  144. mxScrollbar *m_pHorzScrollBar;
  145. int m_nLastHPixelsNeeded;
  146. // How many pixels per second we are showing in the UI
  147. float m_flPixelsPerSecond;
  148. // Do we need to move controls?
  149. bool m_bLayoutIsValid;
  150. float m_flLastDuration;
  151. bool m_bInSetEvent;
  152. float m_flScrubberTimeOffset;
  153. int m_nUndoSetup;
  154. CCurveEditorHelper< RampTool > *m_pHelper;
  155. friend class CChoreoView;
  156. };
  157. extern RampTool *g_pRampTool;
  158. #endif // RAMPTOOL_H