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.

233 lines
5.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Sample Source Code for "demo smoothing" tool in the engine. This could be ported into the client .dll
  4. // pretty easily -- ywb
  5. //
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #ifndef CL_DEMOSMOOTHERPANEL_H
  9. #define CL_DEMOSMOOTHERPANEL_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include <vgui_controls/Frame.h>
  14. namespace vgui
  15. {
  16. class Button;
  17. class Label;
  18. class ListPanel;
  19. class IScheme;
  20. };
  21. #include "demofile/demoformat.h"
  22. #include "demofile.h"
  23. struct demodirectory_t;
  24. class CSmoothingTypeButton;
  25. class CFixEdgeButton;
  26. typedef float (*EASEFUNC)( float t );
  27. //-----------------------------------------------------------------------------
  28. // Purpose:
  29. //-----------------------------------------------------------------------------
  30. class CDemoSmootherPanel : public vgui::Frame
  31. {
  32. DECLARE_CLASS_SIMPLE( CDemoSmootherPanel, vgui::Frame );
  33. public:
  34. CDemoSmootherPanel( vgui::Panel *parent );
  35. ~CDemoSmootherPanel();
  36. virtual void OnTick();
  37. // Command issued
  38. virtual void OnCommand(const char *command);
  39. void OnRefresh();
  40. virtual bool OverrideView( democmdinfo_t& info, int tick );
  41. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  42. virtual void DrawDebuggingInfo( int frame, float elapsed );
  43. protected:
  44. bool CanEdit();
  45. void Reset( void );
  46. demosmoothing_t *GetCurrent( void );
  47. void DrawSmoothingSample( bool original, bool processed, int samplenumber, demosmoothing_t *sample, demosmoothing_t *next );
  48. void DrawTargetSpline( void );
  49. void DrawKeySpline( void );
  50. int GetTickForFrame( int frame );
  51. int GetFrameForTick( int tick );
  52. bool GetInterpolatedViewPoint( Vector& origin, QAngle& angles );
  53. bool GetInterpolatedOriginAndAngles( bool readonly, Vector& origin, QAngle& angles );
  54. void DrawLegend( int startframe, int endframe );
  55. void OnRevert();
  56. void OnPreview( bool original );
  57. void OnSave();
  58. void OnReload();
  59. void OnSelect();
  60. void OnTogglePause();
  61. void OnStep( bool forward );
  62. void OnGotoFrame();
  63. void OnToggleKeyFrame( void );
  64. void OnToggleLookTarget( void );
  65. void OnNextKey();
  66. void OnPrevKey();
  67. void OnNextTarget();
  68. void OnPrevTarget();
  69. void OnRevertPoint( void );
  70. void PopulateMenuList();
  71. int GetStartFrame();
  72. int GetEndFrame();
  73. void OnSaveKey();
  74. void OnSetView();
  75. void OnSmoothEdges( bool left, bool right );
  76. void PerformLinearInterpolatedAngleSmoothing( int startframe, int endframe );
  77. void OnSmoothSelectionAngles( void );
  78. void OnSmoothSelectionOrigin( void );
  79. void OnLinearInterpolateAnglesBasedOnEndpoints( void );
  80. void OnLinearInterpolateOriginBasedOnEndpoints( void );
  81. void OnSplineSampleOrigin( void );
  82. void OnSplineSampleAngles( void );
  83. void OnLookAtPoints( bool spline );
  84. void OnSetKeys(float interval);
  85. void OnOriginEaseCurve( EASEFUNC easefunc );
  86. void SetLastFrame( bool jumptotarget, int frame );
  87. void AddSamplePoints( bool usetarget, bool includeboundaries, CUtlVector< demosmoothing_t * >& points, int start, int end );
  88. demosmoothing_t *GetBoundedSample( CUtlVector< demosmoothing_t * >& points, int sample );
  89. void FindSpanningPoints( int tick, CUtlVector< demosmoothing_t * >& points, int& prev, int& next );
  90. // Undo/Redo
  91. void Undo( void );
  92. void Redo( void );
  93. // Do push before changes
  94. void PushUndo( char *description );
  95. // Do this push after changes, must match pushundo 1for1
  96. void PushRedo( char *description );
  97. void WipeUndo( void );
  98. void WipeRedo( void );
  99. const char *GetUndoDescription( void );
  100. const char *GetRedoDescription( void );
  101. bool CanUndo( void );
  102. bool CanRedo( void );
  103. void ParseSmoothingInfo( CDemoFile &demoFile, CUtlVector< demosmoothing_t >& smooth );
  104. void LoadSmoothingInfo( const char *filename, CSmoothingContext& smoothing );
  105. void ClearSmoothingInfo( CSmoothingContext& smoothing );
  106. void SaveSmoothingInfo( char const *filename, CSmoothingContext& smoothing );
  107. CSmoothingTypeButton *m_pType;
  108. vgui::Button *m_pRevert;
  109. vgui::Button *m_pOK;
  110. vgui::Button *m_pCancel;
  111. vgui::Button *m_pSave;
  112. vgui::Button *m_pReloadFromDisk;
  113. vgui::TextEntry *m_pStartFrame;
  114. vgui::TextEntry *m_pEndFrame;
  115. vgui::Button *m_pPreviewOriginal;
  116. vgui::Button *m_pPreviewProcessed;
  117. vgui::CheckButton *m_pBackOff;
  118. vgui::Label *m_pSelectionInfo;
  119. vgui::CheckButton *m_pShowAllSamples;
  120. vgui::Button *m_pSelectSamples;
  121. vgui::Button *m_pPauseResume;
  122. vgui::Button *m_pStepForward;
  123. vgui::Button *m_pStepBackward;
  124. vgui::CheckButton *m_pHideLegend;
  125. vgui::CheckButton *m_pHideOriginal;
  126. vgui::CheckButton *m_pHideProcessed;
  127. vgui::Button *m_pToggleKeyFrame;
  128. vgui::Button *m_pToggleLookTarget;
  129. vgui::Button *m_pRevertPoint;
  130. vgui::Button *m_pMoveCameraToPoint;
  131. vgui::Button *m_pUndo;
  132. vgui::Button *m_pRedo;
  133. vgui::Button *m_pNextKey;
  134. vgui::Button *m_pPrevKey;
  135. vgui::Button *m_pNextTarget;
  136. vgui::Button *m_pPrevTarget;
  137. CFixEdgeButton *m_pFixEdges;
  138. vgui::TextEntry *m_pFixEdgeFrames;
  139. vgui::Button *m_pProcessKey;
  140. vgui::TextEntry *m_pGotoFrame;
  141. vgui::Button *m_pGoto;
  142. bool m_bHasSelection;
  143. int m_nSelection[2];
  144. int m_iSelectionTicksSpan;
  145. bool m_bPreviewing;
  146. bool m_bPreviewOriginal;
  147. int m_iPreviewStartTick;
  148. float m_fPreviewCurrentTime;
  149. int m_nPreviewLastFrame;
  150. bool m_bPreviewPaused;
  151. CSmoothingContext m_Smoothing;
  152. bool m_bInputActive;
  153. int m_nOldCursor[2];
  154. struct DemoSmoothUndo
  155. {
  156. CSmoothingContext *undo;
  157. CSmoothingContext *redo;
  158. char *udescription;
  159. char *rdescription;
  160. };
  161. CUtlVector< DemoSmoothUndo * > m_UndoStack;
  162. int m_nUndoLevel;
  163. bool m_bRedoPending;
  164. bool m_bDirty;
  165. Vector m_vecEyeOffset;
  166. };
  167. #endif // CL_DEMOSMOOTHERPANEL_H