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.

169 lines
4.8 KiB

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