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.

190 lines
8.1 KiB

  1. //====== Copyright � 1996-2009, Valve Corporation, All rights reserved. =======
  2. //
  3. // Declaration of CGraphEditorView class
  4. //
  5. //=============================================================================
  6. #ifndef GRAPHEDITORVIEW_H
  7. #define GRAPHEDITORVIEW_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "sfmobjects/grapheditor.h"
  12. #include "loggraph.h"
  13. // Forward declarations
  14. class CDmeGraphEditorState;
  15. // Function declarations for head time manipulation callbacks.
  16. typedef void (*FnSetHeadTime )( DmeTime_t newTime, void *pData );
  17. typedef void (*FnMoveHead )( int nPixels, void *pData );
  18. typedef void (*FnScaleAboutHead )( float flScaleFactor, void *pData );
  19. typedef void (*FnSetTimeSelection)( DmeTime_t times[ TS_TIME_COUNT ], void *pData );
  20. // Enumeration for the major types of operations
  21. // which can be performed within the graph editor view.
  22. enum GraphOperationType_t
  23. {
  24. GRAPH_OPERATION_NONE,
  25. GRAPH_OPERATION_SELECT,
  26. GRAPH_OPERATION_ZOOM,
  27. GRAPH_OPERATION_PAN,
  28. GRAPH_OPERATION_DRAG_KEYS,
  29. GRAPH_OPERATION_SCALE_KEYS,
  30. };
  31. //-----------------------------------------------------------------------------
  32. // The CGraphEditorView provides a management and manipulation of the the graph
  33. // editor and the graph display of the the curves and logs being edited.
  34. //-----------------------------------------------------------------------------
  35. class CGraphEditorView
  36. {
  37. public:
  38. enum AxisMode_t
  39. {
  40. AXIS_MODE_XY,
  41. AXIS_MODE_SELECT,
  42. AXIS_MODE_X,
  43. AXIS_MODE_Y
  44. };
  45. struct Point_t
  46. {
  47. Point_t() { x = 0; y = 0; }
  48. Point_t( int xVal, int yVal ) { x = xVal; y = yVal; }
  49. int x;
  50. int y;
  51. };
  52. public:
  53. // Constructor, sets the graph editor which is being viewed
  54. CGraphEditorView( CGraphEditor &graphEditor );
  55. // Set the head position and time manipulation callback functions
  56. void SetCallbacks( FnSetHeadTime pfnSetHeadTime, FnMoveHead pfnSetMoveTime, FnScaleAboutHead pfnScaleAboutHead, FnSetTimeSelection pfnSetTimeSelection, void *pData );
  57. // Set the area in which the curve graph may be drawn
  58. void SetGraphDisplayBounds( int x, int y, int width, int height );
  59. // Set the time range currently being displayed by the graph
  60. void SetGraphTimeRange( DmeTime_t minTime, DmeTime_t maxTime );
  61. // Set the active time range, this time range where the graph operations are effective, such as the time range of the current shot
  62. void SetActiveTimeRange( DmeTime_t startTime, DmeTime_t endTime );
  63. // Set the screen position
  64. void SetScreenPosition( int x, int y );
  65. // Draw the background of the graph
  66. void DrawBackground( DmeFramerate_t frame, bool bDisplayFrames, bool bFrameSnap, const DmeClipStack_t &shotToRoot );
  67. // Draw the graph elements
  68. void Draw();
  69. // Draw the selection preview of the keys
  70. void DrawSelection() const;
  71. // Start an operation of the specified type if an operation is not currently underway
  72. bool StartOperation( GraphOperationType_t operationType );
  73. // Complete the current active operation
  74. void FinishOperation();
  75. // Update the currently active operation
  76. bool UpdateOperation( int nCursorPosX, int nCursorPosY, bool bCtrlDown, bool bAltDown, bool bShiftDown, bool bFrameSnap, DmeTime_t currentTime, SelectionMode_t selectionMode, bool bFinal );
  77. // Apply the specified vertical scale to the the graph using the provided center location
  78. void ApplyVerticalScale( int delta, int nCursorPosY );
  79. // Set the vertical range of the graph
  80. void SetVerticalRange( float minValue, float maxValue );
  81. // Compute the bounding time and values of the current selection
  82. bool ComputeSelectionBounds( DmeTime_t &minTime, DmeTime_t &maxTime, float &minValue, float &maxValue ) const;
  83. // Determine if the cursor is currently within the graph display area
  84. bool IsPointInGraphArea( int x, int y ) const;
  85. // Find the curves at the specified location
  86. void FindCurvesAtPosition( int nPosX, int nPosY, CUtlVector< CDmeGraphEditorCurve * > &curveList, CUtlVector< LogComponents_t > &componentFlags ) const;
  87. // Accessors
  88. GraphOperationType_t GetCurrentOperation() const { return m_CurrentOperation; }
  89. AxisMode_t GetAxisMode() const { return m_AxisMode; }
  90. const Rect_t &GetArea() const { return m_GraphArea; }
  91. CLogGraph &GetLogGraph() { return m_LogGraph; }
  92. private:
  93. // Update the axis mode based on the mouse movement
  94. bool UpdateAxisMode( bool bAxisLock );
  95. // Update the panning operation
  96. void UpdatePanning( bool bMoveHead, bool bAxisLock );
  97. // Update the zoom operation
  98. void UpdateZoom( bool bAxisLock );
  99. // Update the current key manipulation operation
  100. bool UpdateKeyManipulation( bool bAxisLock, bool bSnapToFrames, bool bUnifiedTangents, GraphOperationType_t operationType, bool bFinal );
  101. // Update the selection operation
  102. void UpdateSelection( SelectionMode_t selectionMode );
  103. // Compute the selection rectangle base on the current cursor position and the pressed cursor position
  104. void ComputeSelectionRectangle( const Point_t &startPoint, const Point_t &endPoint, Rect_t &rect ) const;
  105. // Select the keys in the specified rectangle
  106. void SelectKeysInRectangle( const Rect_t &rect, SelectionMode_t selectionMode );
  107. // Get a list of the keys in the rectangle specified local to the panel
  108. void FindKeysInRectangle( CDmeGraphEditorCurve *pCurve, const Rect_t &rect, CUtlVector< CDmeCurveKey * > &keyList ) const;
  109. // Get a list of the tangents belonging to the provided keys that are in the specified rectangle
  110. void FindKeyTangentsInRectangle( const Rect_t &rect, CUtlVector< CDmeCurveKey * > &keyList, CUtlVector< bool > &inTangents, CUtlVector< bool > &outTangents ) const;
  111. // Get a list of the curves in the specified rectangle
  112. void FindCurvesInRectangle( const Rect_t &rect, CUtlVector< CDmeGraphEditorCurve * > &curveList, CUtlVector< LogComponents_t > &componentFlags ) const;
  113. // Determine which components of the specified curve intersect the specified rectangle
  114. void FindCurveComponentsInRectangle( const Rect_t &rect, CDmeGraphEditorCurve *pCurve, LogComponents_t &nComponentFlags ) const;
  115. // Determine if the specified log intersects the specified rectangle.
  116. template < typename T >
  117. void IsLogInRectangle( const Rect_t &rect, const CDmeTypedLog< T > *pLog, const DmeClipStack_t &curveClipStack, LogComponents_t &nComponentFlags ) const;
  118. CGraphEditor &m_GraphEditor; // Graph editor instance used to manipulate the logs using curves
  119. CLogGraph m_LogGraph; // Pointer to the log graph to be used to draw the logs
  120. GraphOperationType_t m_CurrentOperation; // Current state of the panel, specifies what operations are currently happening
  121. AxisMode_t m_AxisMode; // Current axis mode selected for panning
  122. bool m_bUnifiedTangents; // Current unified tangent mode for tangent manipulations
  123. SelectionMode_t m_SelectionMode; // Current selection mode ( add, remove, toggle )
  124. Rect_t m_SelectionRect; // Current area selection rectangle
  125. Rect_t m_GraphArea; // Graph area within the panel
  126. float m_flVerticalScale; // Vertical scale (range) of the graph
  127. DmeTime_t m_ActiveStartTime; // Start time of the active time range of the graph
  128. DmeTime_t m_ActiveEndTime; // End time of the active time range of the graph
  129. DmeTime_t m_StartDocTime; // Document time at the start of the current operation
  130. DmeTime_t m_CurrentDocTime; // Current document time
  131. Point_t m_CursorPos; // Position of the cursor when the last Think() occurred
  132. Point_t m_CursorDelta; // Number of pixels the cursor moved during the last frame
  133. Point_t m_StartCursorPos; // Cursor position at the start of the current operation
  134. FnSetHeadTime m_pfnSetHeadTime; // Callback function for setting the head time
  135. FnMoveHead m_pfnMoveHead; // Callback function for moving the head
  136. FnScaleAboutHead m_pfnScaleAboutHead; // Callback function for scaling time about the head position
  137. FnSetTimeSelection m_pfnSetTimeSelection; // Callback function for setting the current time selection
  138. void *m_pCallbackData; // Pointer to be provided to the callback time
  139. };
  140. #endif // GRAPHEDITORPANEL_H