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.

168 lines
4.7 KiB

  1. //====== Copyright � 1996-2003, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMELOGEDITPANEL_H
  7. #define DMELOGEDITPANEL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui_controls/frame.h"
  12. #include "matsys_controls/curveeditorpanel.h"
  13. #include "datamodel/dmehandle.h"
  14. //-----------------------------------------------------------------------------
  15. // Forward declarations
  16. //-----------------------------------------------------------------------------
  17. class CDmeLog;
  18. namespace vgui
  19. {
  20. class ComboBox;
  21. }
  22. //-----------------------------------------------------------------------------
  23. //
  24. // Curve editor for float DmeLogs
  25. //
  26. //-----------------------------------------------------------------------------
  27. class CDmeLogEditPanel : public CCurveEditorPanel
  28. {
  29. DECLARE_CLASS_SIMPLE( CDmeLogEditPanel, CCurveEditorPanel );
  30. public:
  31. enum LogField_t
  32. {
  33. FIELD_X = 0x1,
  34. FIELD_Y = 0x2,
  35. FIELD_Z = 0x4,
  36. FIELD_W = 0x8,
  37. FIELD_R = 0x1,
  38. FIELD_G = 0x2,
  39. FIELD_B = 0x4,
  40. FIELD_A = 0x8,
  41. FIELD_ALL = 0xF,
  42. };
  43. // constructor
  44. CDmeLogEditPanel( vgui::Panel *pParent, const char *pName );
  45. ~CDmeLogEditPanel();
  46. // Sets the log to edit
  47. void SetDmeLog( CDmeLog *pLog );
  48. void SetMask( int nMask );
  49. // Sets the time range on the view in ms
  50. void SetTimeRange( DmeTime_t startTime, DmeTime_t endTime );
  51. // Sets the vertical range on the view
  52. void SetVerticalRange( float flMin, float flMax );
  53. protected:
  54. // Control points + values...
  55. virtual int FindOrAddControlPoint( float flIn, float flTolerance, float flOut );
  56. virtual int FindControlPoint( float flIn, float flTolerance );
  57. virtual int ModifyControlPoint( int nPoint, float flIn, float flOut );
  58. virtual void RemoveControlPoint( int nPoint );
  59. virtual float GetValue( float flIn );
  60. virtual int ControlPointCount();
  61. virtual void GetControlPoint( int nPoint, float *pIn, float *pOut );
  62. private:
  63. // Converts normalized values to int time
  64. DmeTime_t NormalizedToTime( float flIn );
  65. DmeTime_t NormalizedToDuration( float flDuration );
  66. float TimeToNormalized( DmeTime_t time );
  67. float NormalizedToValue( float flValue );
  68. float ValueToNormalized( float flNormalized );
  69. template< class T > int FindOrAddKey( DmeTime_t time, DmeTime_t tolerance, int nComps, float flValue );
  70. template< class T > int ModifyKey( int nPoint, DmeTime_t initialTime, DmeTime_t time, int nComps, float flValue );
  71. CDmeHandle<CDmeLog> m_hLog;
  72. int m_LogFieldMask;
  73. int m_nFieldIndex;
  74. DmeTime_t m_minTime;
  75. DmeTime_t m_maxTime;
  76. float m_flMinVertical;
  77. float m_flMaxVertical;
  78. };
  79. //-----------------------------------------------------------------------------
  80. // Finds or adds a key
  81. //-----------------------------------------------------------------------------
  82. template< class T >
  83. int CDmeLogEditPanel::FindOrAddKey( DmeTime_t time, DmeTime_t tolerance, int nComps, float flValue )
  84. {
  85. T vec = CastElement< CDmeTypedLog<T> >( m_hLog )->GetValue( time );
  86. for ( int i = 0; i < nComps; ++i )
  87. {
  88. if ( m_LogFieldMask & (1 << i) )
  89. {
  90. vec[i] = flValue;
  91. }
  92. }
  93. return CastElement< CDmeTypedLog<T> >( m_hLog )->FindOrAddKey( time, tolerance, vec );
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Modifies an existing key
  97. //-----------------------------------------------------------------------------
  98. template< class T >
  99. int CDmeLogEditPanel::ModifyKey( int nPoint, DmeTime_t initialTime, DmeTime_t time, int nComps, float flValue )
  100. {
  101. T vec = CastElement< CDmeTypedLog<T> >( m_hLog )->GetValue( initialTime );
  102. for ( int i = 0; i < nComps; ++i )
  103. {
  104. if ( m_LogFieldMask & (1 << i) )
  105. {
  106. vec[i] = flValue;
  107. }
  108. }
  109. RemoveControlPoint( nPoint );
  110. return CastElement< CDmeTypedLog<T> >( m_hLog )->FindOrAddKey( time, DmeTime_t( 0 ), vec );
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose: Main app window
  114. //-----------------------------------------------------------------------------
  115. class CDmeLogEditFrame : public vgui::Frame
  116. {
  117. DECLARE_CLASS_SIMPLE( CDmeLogEditFrame, vgui::Frame );
  118. public:
  119. CDmeLogEditFrame( vgui::Panel *pParent, const char *pTitle );
  120. ~CDmeLogEditFrame();
  121. // Inherited from Frame
  122. virtual void OnCommand( const char *pCommand );
  123. // Purpose: Activate the dialog
  124. // the message "LogEdited" will be sent if ok was hit
  125. // Pass in a message to add as a subkey to the DmeSelected message
  126. void DoModal( CDmeLog *pLog, DmeTime_t startTime, DmeTime_t endTime, KeyValues *pContextKeyValues = NULL );
  127. private:
  128. MESSAGE_FUNC( OnTextChanged, "TextChanged" );
  129. void CleanUpMessage();
  130. CDmeLogEditPanel *m_pCurveEditor;
  131. vgui::Button *m_pOkButton;
  132. vgui::Button *m_pCancelButton;
  133. vgui::ComboBox *m_pFilter;
  134. KeyValues *m_pContextKeyValues;
  135. };
  136. #endif // DMELOGEDITPANEL_H