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.

209 lines
9.5 KiB

  1. //====== Copyright � 1996-2009, Valve Corporation, All rights reserved. =======
  2. //
  3. // Declaration of CLogGraph, a utility for drawing logs in a graph with scale
  4. // and offset.
  5. //
  6. //=============================================================================
  7. #ifndef LOGGRAPH_H
  8. #define LOGGRAPH_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vgui/VGUI.h"
  13. #include "movieobjects/dmeclip.h"
  14. #include "movieobjects/dmelog.h"
  15. #include "materialsystem/materialsystemutil.h"
  16. #include "mathlib/beziercurve.h"
  17. #include "Color.h"
  18. class CDmeGraphEditorCurve;
  19. class CDmeCurveKey;
  20. //-----------------------------------------------------------------------------
  21. // The CLogGraph class provides functionality for drawing logs within a graph
  22. // display. It stores the offset and scale of the graph and provides
  23. // functionality to draw log data relative to graph.
  24. //-----------------------------------------------------------------------------
  25. class CLogGraph
  26. {
  27. public:
  28. struct ColorSettings_t
  29. {
  30. Color m_BackgroundColor; // Color to fill the background area of the graph
  31. Color m_TimeBoundsColor; // Color to draw the time range bounds overlay with
  32. Color m_GridColor; // Color to draw the grid lines with
  33. Color m_FontColor; // Color to draw the graph labels with
  34. Color m_CurveColor; // Color to draw generic log curves with
  35. Color m_SegmentColor; // Color to draw selected curve segments with
  36. Color m_SelectionColor; // Color to draw the selection rectangle with
  37. Color m_CrossHairColor; // Color to draw the cross hair with
  38. Color m_KeyColor; // Color to draw keys with
  39. Color m_KeySelectedColor; // Color to draw selected keys
  40. Color m_KeyAddColor; // Color to draw keys being added to the selection
  41. Color m_KeyRemoveColor; // Color to draw keys being removed from the selection
  42. Color m_TangentColor; // Color to draw tangents with
  43. Color m_BrokenTangentColor; // Color to draw the in tangent of broken tangent keys with
  44. Color m_CurveColorX; // Color in which x components are to be displayed
  45. Color m_CurveColorY; // Color in which y components are to be displayed
  46. Color m_CurveColorZ; // Color in which z components are to be displayed
  47. };
  48. // Constructor
  49. CLogGraph( float flMinScale, float flMaxScale );
  50. // Set the screen space position of the graph area
  51. void SetScreenPosition( int x, int y );
  52. // Set the area in which the graph may be drawn
  53. void SetGraphDisplayBounds( int x, int y, int width, int height );
  54. // Set the time range being displayed by the graph
  55. void SetGraphTimeRange( DmeTime_t minTime, DmeTime_t maxTime );
  56. // Apply an offset to the graph range specified in pixels
  57. void ApplyVerticalOffset( int nPixels );
  58. // Get the current vertical scale ( total vertical value range )
  59. float GetVerticalScale() const;
  60. // Set the current vertical scale
  61. void SetVerticalScale( float scale, float center );
  62. // Set the vertical range of the graph
  63. void SetVerticalRange( float minValue, float maxValue );
  64. // Set the font with which the graph should display its text
  65. void SetFont( vgui::HFont hFont );
  66. // Set the colors with which the graph is to be displayed
  67. void SetColors( const ColorSettings_t &colors );
  68. // Draw the graph background
  69. void DrawBackground( bool bDrawGrid, const DmeFramerate_t &frameRate, bool bDrawFrames, const DmeClipStack_t &shotToRoot ) const;
  70. // Draw the bounds of the specified time range as rectangles extending to the edge of the graph area
  71. void DrawTimeRangeBounds( DmeTime_t startTime, DmeTime_t endTime );
  72. // Draw the specified rectangle to show the selection area
  73. void DrawSelectionRect( const Rect_t &rect ) const;
  74. // Draw a cross hair display across the graph at the specified location
  75. void DrawCrosshair( int x, int y, const DmeFramerate_t &frameRate, bool bDrawFrames, bool bFrameSnap, const DmeClipStack_t &shotToRoot ) const;
  76. // Draw the specified graph curve
  77. void DrawGraphCurve( const CDmeGraphEditorCurve *pCurve, const DmeClipStack_t &channelToRoot ) const;
  78. // Draw the specified set of keys
  79. void DrawKeysSelectionPreview( const CUtlVector< CDmeCurveKey * > &keyList, const DmeClipStack_t &channelToRoot, int nSelectionMode ) const;
  80. // Draw the specified log
  81. void DrawLog( const CDmeLog *pLog, const DmeClipStack_t &channelToRoot, LogComponents_t componentFlags, DmeTime_t minTime = DMETIME_MINTIME, DmeTime_t maxTime = DMETIME_MAXTIME, const Color *pColor = NULL, IMesh *pMesh = NULL ) const;
  82. // Get the pixel rectangle of a point at the specified location using the current rendering point size
  83. void GetPointRect( float flValue, DmeTime_t time, Rect_t &rect ) const;
  84. // Convert a panel coordinate into a graph pixel coordinate
  85. void PanelPositionToPixel( int &x, int &y );
  86. // Get the number of pixels per unit of time displayed on the graph
  87. float GetPixelsPerSecond() const;
  88. // Get the number of pixels per value unit
  89. float GetPixelsPerUnit() const;
  90. // Get the number of units per pixel
  91. float GetUnitsPerPixel() const;
  92. // Get the amount of time for single pixel in tenths of a ms
  93. float GetTimePerPixel() const;
  94. // Get the time for the specified pixel within the graph area
  95. DmeTime_t GetTimeForPixel( int xPos ) const;
  96. // Get the value for the specified pixel within the graph area
  97. float GetValueForPixel( int yPos ) const;
  98. // Get the x coordinate of the pixel representing the specified time within the graph
  99. int GetPixelForTime( DmeTime_t time, RoundStyle_t roundStyle = ROUND_NEAREST ) const;
  100. // Get the y coordinate of the pixel representing the specified time within the graph
  101. int GetPixelForValue( float value, RoundStyle_t roundStyle = ROUND_NEAREST ) const;
  102. // Compute the screen space position of the specified key
  103. bool ComputeKeyPositionTangents( const CDmeCurveKey *pKey, const DmeClipStack_t &channelToRoot, Vector &vPos, Vector &vInPos, Vector &vOutPos, bool bScreenSpace ) const;
  104. // Accessors
  105. DmeTime_t GetMinTime() const { return m_MinTime; }
  106. DmeTime_t GetMaxTime() const { return m_MaxTime; }
  107. private:
  108. // Get a temporary render mesh
  109. IMesh *GetDynamicRenderMesh() const;
  110. // Draw the keys for the specified curve
  111. void DrawCurveKeys( const CDmeGraphEditorCurve *pCurve, const DmeClipStack_t &channelToRoot, IMesh *pMesh ) const;
  112. // Draw the curve segments associated with the selected keys of the specified curve
  113. void DrawSelectedCurveSegments( const CDmeGraphEditorCurve *pCurve, const DmeClipStack_t &channelToRoot, IMesh *pMesh ) const;
  114. // Draw the curve segment between the two specified keys
  115. void DrawCurveSegment( const CDmeCurveKey *pStartKey, const CDmeCurveKey *pEndKey, DmeTime_t channelMinTime, DmeTime_t channelMaxTime, IMesh *pMesh ) const;
  116. // Draw the specified Bezier curve segment
  117. void DrawCurveSegment( const CCubicBezierCurve< Vector > &curveSegment, IMesh *pMesh ) const;
  118. // Draw a curve segment as a step
  119. void DrawCurveStep( const Vector &vStart, const Vector &vEnd, IMesh *pMesh ) const;
  120. // Draw the log of the specified type
  121. template < typename T >
  122. void DrawLog( const CDmeTypedLog< T > *pLog, const DmeClipStack_t &channelToRoot, LogComponents_t nComponentFlags, DmeTime_t minTime, DmeTime_t maxTime, const Color *pColor, IMesh *pMesh ) const;
  123. // Draw the specified log layer
  124. template < typename T >
  125. void DrawLogLayer( const CDmeLog *pLog, const CDmeTypedLogLayer< T > *pLogLayer, const DmeClipStack_t &channelToRoot, LogComponents_t componentFlags, bool bSubLayer, DmeTime_t minTime, DmeTime_t maxTime, const Color *pColor, IMesh *pMesh ) const;
  126. // Draw the specified set of keys from the provided log layer
  127. template < typename T >
  128. void DrawLogKeys( CUtlVector< LogKeyValue_t< T > > &displayKeys, LogComponents_t componentFlags, bool bSubLayer, DmeTime_t logMinTime, DmeTime_t logMaxTime, const Color *pColor, IMesh *pMesh ) const;
  129. // Compute the screen space position of the specified key
  130. bool ComputeKeyPosition( const CDmeCurveKey *pKey, DmeTime_t timeMin, DmeTime_t timeMax, Vector &vPos ) const;
  131. // Compute the screen space position of the specified key
  132. bool ComputeKeyPositionTangents( const CDmeCurveKey *pKey, DmeTime_t timeMin, DmeTime_t timeMax, Vector &vPos, Vector &vInPos, Vector &vOutPos, bool bScreenSpace, bool bNormalizeUnweighted, float flPointOffset = 0 ) const;
  133. CMaterialReference m_pMaterial; // Material to be used to draw the logs
  134. vgui::HFont m_hFont; // Font to be used to draw the value labels on the graph
  135. int m_nPointSize; // Size to be used when rendering a point.
  136. const float m_flMinScale; // Minimum range between the min value and the max value
  137. const float m_flMaxScale; // Maximum range between the min value and the max value
  138. float m_flMinValue; // Minimum value visible on the graph
  139. float m_flMaxValue; // Maximum value visible on the graph
  140. DmeTime_t m_MinTime; // Minimum time visible on the graph
  141. DmeTime_t m_MaxTime; // Maximum time visible on the graph
  142. int m_nScreenPosX; // Offset of the graph area in screen space
  143. int m_nScreenPosY; // Offset of the graph area in screen space
  144. int m_nAreaX; // X Coordinate of the upper left corner of the graph display area
  145. int m_nAreaY; // Y Coordinate of the upper left corner of the graph display area
  146. int m_nAreaWidth; // Width of the graph display area
  147. int m_nAreaHeight; // Height of the graph display area
  148. ColorSettings_t m_ColorSettings; // Structure containing the color settings to be used by the graph
  149. };
  150. DmeTime_t GetTimeForFrame( float frame, const DmeFramerate_t &framerate );
  151. #endif // LOGGRAPH_H