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.

232 lines
9.8 KiB

  1. //====== Copyright � 1996-2009, Valve Corporation, All rights reserved. =======
  2. //
  3. // Declaration of the CGraphEditor class, which is used to perform direct
  4. // manipulation of log data as if it were a curve.
  5. //
  6. //=============================================================================
  7. #ifndef GRAPHEDITOR_H
  8. #define GRAPHEDITOR_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "datamodel/dmelement.h"
  13. #include "sfmobjects/dmegrapheditorstate.h"
  14. class CDmeGraphEditorState;
  15. //-----------------------------------------------------------------------------
  16. // The CGraphEditor class performs direct manipulations of log data by fitting
  17. // a cubic bezier curve to a segment of sample data and then manipulating the
  18. // controls points of the curve.
  19. //-----------------------------------------------------------------------------
  20. class CGraphEditor
  21. {
  22. public:
  23. enum PasteMode_t
  24. {
  25. PASTE_MERGE, // Keys are merged with other keys within the paste time range
  26. PASTE_INSERT, // Keys after the paste location are offset in time by the paste time range
  27. PASTE_OVERWRITE // Keys within the paste time range are removed
  28. };
  29. enum Operation_t
  30. {
  31. OPERATION_NONE,
  32. OPERATION_MOVE_KEYS,
  33. OPERATION_SCALE_KEYS,
  34. OPERATION_SET_KEYS,
  35. OPERATION_BLEND_KEYS,
  36. OPERATION_COUNT,
  37. };
  38. // Constructor
  39. CGraphEditor();
  40. // Destructor
  41. ~CGraphEditor();
  42. // Set the pointer to the current state element
  43. void SetStateElement( CDmeGraphEditorState *pStateElement );
  44. // Set the frame rate to be used by the graph editor when performing sampling operations
  45. void SetFramerate( DmeFramerate_t framerate );
  46. // Set the current clip stack, defining the local time frame in which the graph is operating
  47. void SetClipstack( const DmeClipStack_t &clipStack );
  48. // Get the pointer to the state element in use by the graph editor
  49. CDmeGraphEditorState *GetStateElement();
  50. // Start a new operation
  51. void StartOperation();
  52. // Finish the current operation and finalize the curve modifications
  53. void FinishOperation();
  54. // Cancel the current operation
  55. void AbortOperation();
  56. // Move the currently selected keys by the specified amount and time
  57. void MoveSelectedKeys( DmeTime_t timeDelta, float valueDelta, float flValueScale, float timeScale, DmeTime_t cursorTime, bool bSnapToFrames, bool bUnifiedTangents, bool bEditLayerUndoable );
  58. // Scale the currently selected keys by the specified amount using the provided origin
  59. void ScaleSelectedKeys( float flTimeScaleFctor, float flValueScaleFactor, DmeTime_t originTime, float flOriginValue, bool bEditLayerUndoable );
  60. // Delete the currently selected keys
  61. bool DeleteSelectedKeys();
  62. // Modify the tangents of the currently selected keys using the specified operation
  63. bool ModifyTangents( TangentOperation_t operation, float flUnitsPerSecond, bool bUpdateLog );
  64. // Remove all of the active curves from the graph editor
  65. void RemoveAllCurves();
  66. // Remove all of the curves from the list of active curves ( the ones visible in the graph editor )
  67. void DeactivateAllCurves();
  68. // Update the curves associated with the specified channels from their base log data
  69. void UpdateActiveCurvesFromChannels( const CUtlVector< CDmeChannel * > &channelList );
  70. // Set the active channels which are to be edited
  71. void SetActiveChannels( CUtlVector< CDmeChannel * > &channelList, CUtlVector< LogComponents_t > &componentFlags, bool bFrameSnap );
  72. // Set a key value for all active components of the curves associated with the specified channels
  73. void SetKeysForChannels( const CUtlVector< CDmeChannel * > &channelList, DmeTime_t globalTime, bool bFinal );
  74. // Set a key value for the specified components of the curve associated with the provided channel
  75. void SetKeysForChannels( const CUtlVector< CDmAttribute * > &keyValueAttributes, const CUtlVector< CDmeChannel * > &channelList, const CUtlVector< LogComponents_t > &nComponentFlags, DmeTime_t globalTime, bool bFinal );
  76. // Get the value of all of the components of the curve associated with the specified channel at the given time
  77. int GetValuesForChannel( CDmeChannel *pChannel, DmeTime_t time, float *pValues, int nMaxValues ) const;
  78. // Set the value of all of the components of the curve associated with the specified channel at the given time
  79. bool SetValuesForChannel( CDmeChannel *pChannel, DmeTime_t time, const float *pValues, int nNumValues ) const;
  80. // Blend the selected keys on each of the specified channels to the provided value for each channel
  81. void BlendSelectedKeysForChannels( const CUtlVector< CDmeChannel * > &channelList, const CUtlVector< Vector4D > &valueList, float flBlendFactor, bool bFinal );
  82. // Blend the selected keys on the curves associated with each of the specified channels to the value on the curve at the specified time.
  83. void BlendSelectedKeysForChannels( const CUtlVector< CDmeChannel * > &channelList, DmeTime_t globalTargetTime, float flBlendFactor, bool bFinal );
  84. // Select the specified set of keys according to the provided selection mode
  85. void SelectKeys( CUtlVector< CDmeCurveKey * > &keyList, SelectionMode_t selectionMode );
  86. // Select the specified keys and their tangents according to the specified selection mode
  87. void SelectKeyTangents( CUtlVector< CDmeCurveKey * > &keyList, CUtlVector< bool > &inTangents, CUtlVector< bool > &outTangents, SelectionMode_t selectionMode );
  88. // Select the specified component of the specified curve and all the keys on the component
  89. void SelectCurveComponents( const CUtlVector< CDmeGraphEditorCurve * > &curveList, const CUtlVector < LogComponents_t > &nComponentFlagsList, SelectionMode_t selectionMode );
  90. // Compute the tangent values of any selected keys that currently have invalid tangent values
  91. void ComputeSelectedKeyTangents();
  92. // Copy the currently selected keys to the clipboard
  93. void CopySelectedKeys();
  94. // Cut the currently selected keys and store them in the clipboard
  95. void CutSelectedKeys();
  96. // Paste the keys from the clipboard at the specified time
  97. void PasteKeysFromClipboard( DmeTime_t pasteTime, PasteMode_t pasteMode, bool bConnect );
  98. // Add a bookmark to the current curve set
  99. void AddBookmark( CDmeBookmark *pBookmark );
  100. // Remove a bookmark from the current curve set
  101. void RemoveBookmark( CDmeBookmark *pBookmark );
  102. // Update the time of the associated bookmark proxy if it no longer matches the bookmark.
  103. void UpdateBookmarkTime( const CDmeBookmark *pBookmark, DmeTime_t oldTime );
  104. // Get the composite set of bookmarks for all active curves
  105. CDmaElementArray< CDmeBookmark > *GetBookmarkSet();
  106. // Perform the required update when the time of a bookmark changes
  107. void OnBookmarkTimeChange( DmeTime_t oldTime, DmeTime_t newTime );
  108. // Get the number of selected keys
  109. int GetNumSelectedKeys() const;
  110. // Get the selected keys in arrays grouped by the curve to which the key belongs
  111. int GetSelectedKeysByCurve( CUtlVector< CUtlVector< CDmeCurveKey * > > &curveKeyList, bool bIncludeNeighbors = false ) const;
  112. // Get all of the keys on the active curves
  113. int GetAllKeysByCurve( CUtlVector< CUtlVector< CDmeCurveKey * > > &curveKeyList ) const;
  114. // Get all of the active curves
  115. void GetActiveCurves( CUtlVector< CDmeGraphEditorCurve * > &curveList ) const;
  116. // Get the current number of active curves
  117. int GetNumActiveCurves() const;
  118. // Compute the time selection for the currently selected keys
  119. bool ComputeTimeSelction( DmeTime_t times[ TS_TIME_COUNT ] );
  120. // Enable or disable offset mode
  121. void EnableOffsetMode( bool bEnable );
  122. // Determine if offset mode is enabled
  123. bool IsOffsetModeEnabled() const;
  124. // Enable or disable adding keys in stepped mode
  125. void SetAddKeysStepped( bool bAddKeysStepped );
  126. // Determine if add keys in stepped mode is enabled
  127. bool IsAddingKeysStepped() const;
  128. // Determine if the graph editor is currently performing a drag operation
  129. bool IsDragging() const;
  130. private:
  131. struct OperationEntry_t
  132. {
  133. int mode; // Operation mode identifier
  134. char name[ 32 ]; // Name of the operation (used for undo)
  135. };
  136. // Set the specified operation mode and perform initialization for that mode
  137. void SetOperationMode( Operation_t mode );
  138. // Finalize all of the modifications that have been made to the curves
  139. void FinalizeChanges() const;
  140. // Build the bookmark list from the current curve set
  141. void BuildBookmarksFromCurves();
  142. // Paste the keys from the provided curve data to the corresponding components of the destination curve
  143. void PasteKeysToCurve( KeyValues *pCurveData, CDmeGraphEditorCurve *pDstCurve, DmeTime_t timeOffset, DmeTime_t timeSpan, PasteMode_t pasteMode, bool bConnect );
  144. // Paste the keys from the provided component data to the corresponding destination curve component
  145. void PasteKeysToComponent( KeyValues *pComponentData, CDmeGraphEditorCurve *pDstCurve, int nComponentIndex, DmeTime_t timeOffset, DmeTime_t timeSpan, PasteMode_t pasteMode, bool bConnect );
  146. CDmeGraphEditorState *m_pState; // Pointer to the state element to be modified by the graph editor
  147. DmeFramerate_t m_framerate; // Frame rate of the current document
  148. DmeClipStack_t m_clipstack; // Clip stack from global time to the local time of the graph
  149. bool m_bBuildingBookmarks; // Flag indicating if the building process is in progress
  150. bool m_bStartOperation; // Flag specifying if the next call to set operation mode will start a new operation
  151. bool m_bOffsetMode; // Flag indicating if the graph editor is operating in offset mode
  152. bool m_bAddKeysStepped; // Flag indicating if new keys added should be created in stepped mode
  153. Operation_t m_OperationMode; // The currently active operation mode
  154. static const OperationEntry_t sm_OperationTable[];
  155. static const OperationEntry_t sm_TangentOperationTable[];
  156. };
  157. #endif // GRAPHEDITOR_H