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.

320 lines
9.6 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef PANORAMA_MOVIEPLAYER_H
  6. #define PANORAMA_MOVIEPLAYER_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panel2d.h"
  11. #include "../data/iimagesource.h"
  12. #include "../data/panoramavideoplayer.h"
  13. #include "panorama/uischeduleddel.h"
  14. namespace panorama
  15. {
  16. class CToggleButton;
  17. class CLabel;
  18. class CSlider;
  19. DECLARE_PANEL_EVENT0( MoviePlayerAudioStart );
  20. DECLARE_PANEL_EVENT0( MoviePlayerAudioStop );
  21. DECLARE_PANEL_EVENT0( MoviePlayerPlaybackStart );
  22. DECLARE_PANEL_EVENT0( MoviePlayerPlaybackStop );
  23. DECLARE_PANEL_EVENT1( MoviePlayerPlaybackEnded, EVideoPlayerPlaybackError );
  24. DECLARE_PANORAMA_EVENT0( MoviePlayerTogglePlayPause );
  25. DECLARE_PANORAMA_EVENT0( MoviePlayerFastForward );
  26. DECLARE_PANEL_EVENT0( MoviePlayerUIVisible );
  27. DECLARE_PANORAMA_EVENT0( MoviePlayerJumpBack );
  28. DECLARE_PANORAMA_EVENT0( MoviePlayerVolumeControl );
  29. DECLARE_PANORAMA_EVENT0( MoviePlayerFullscreenControl );
  30. DECLARE_PANORAMA_EVENT1( MoviePlayerSetRepresentation, int );
  31. DECLARE_PANORAMA_EVENT0( MoviePlayerSelectVideoQuality );
  32. //-----------------------------------------------------------------------------
  33. // Purpose: Base class for controls that pop above movie button bar
  34. //-----------------------------------------------------------------------------
  35. class CMovieControlPopupBase : public CPanel2D
  36. {
  37. public:
  38. CMovieControlPopupBase( CPanel2D *pInvokingPanel, const char *pchPanelID );
  39. virtual ~CMovieControlPopupBase() {}
  40. void Show( float flVolume );
  41. void Close();
  42. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight ) OVERRIDE;
  43. protected:
  44. bool EventCancelled( const CPanelPtr< IUIPanel > &pPanel, EPanelEventSource_t eSource );
  45. CPanel2D *m_pInvisibleBackground;
  46. CPanel2D *m_pInvokingPanel;
  47. CPanel2D *m_pPopupBackground;
  48. };
  49. //-----------------------------------------------------------------------------
  50. // Purpose: Top level menu for volume slider
  51. //-----------------------------------------------------------------------------
  52. class CVolumeSliderPopup : public CMovieControlPopupBase
  53. {
  54. DECLARE_PANEL2D( CVolumeSliderPopup, CMovieControlPopupBase );
  55. public:
  56. CVolumeSliderPopup( CPanel2D *pInvokingPanel, const char *pchPanelID );
  57. virtual ~CVolumeSliderPopup() {}
  58. void Show( float flVolume );
  59. virtual bool OnKeyDown( const KeyData_t &unichar ) OVERRIDE;
  60. private:
  61. bool EventSliderValueChanged( const CPanelPtr< IUIPanel > &pPanel, float flValue );
  62. CSlider *m_pSlider;
  63. };
  64. //-----------------------------------------------------------------------------
  65. // Purpose: Top level menu for showing video resolutions to select
  66. //-----------------------------------------------------------------------------
  67. class CMovieVideoQualityPopup : public CMovieControlPopupBase
  68. {
  69. DECLARE_PANEL2D( CMovieVideoQualityPopup, CMovieControlPopupBase );
  70. public:
  71. CMovieVideoQualityPopup( CPanel2D *pInvokingPanel, const char *pchPanelID );
  72. virtual ~CMovieVideoQualityPopup() {}
  73. void AddRepresentation( int iRep, int nHeight );
  74. void Show( int iFocusRep, int nVideoHeight );
  75. private:
  76. struct Representation_t
  77. {
  78. int m_iRep;
  79. int m_nHeight;
  80. };
  81. bool EventSetRepresentation( int iRep );
  82. static bool SortRepresentations( const Representation_t &lhs, const Representation_t &rhs );
  83. CUtlVector< Representation_t > m_vecRepresentations;
  84. };
  85. //-----------------------------------------------------------------------------
  86. // Purpose: Movie panel. Just displays the movie
  87. //-----------------------------------------------------------------------------
  88. class CMoviePanel : public CPanel2D
  89. {
  90. DECLARE_PANEL2D( CMoviePanel, CPanel2D );
  91. public:
  92. CMoviePanel( CPanel2D *parent, const char *pchPanelID );
  93. virtual ~CMoviePanel();
  94. CVideoPlayerPtr GetMovie() { return m_pVideoPlayer; }
  95. void SetMovie( const char *pchFile );
  96. void SetMovie( CVideoPlayerPtr pVideoPlayer );
  97. bool IsSet() { return (m_pVideoPlayer != NULL); }
  98. void Clear();
  99. void SetPlaybackVolume( float flVolume );
  100. void SuggestMovieHeight();
  101. virtual void Paint();
  102. #ifdef DBGFLAG_VALIDATE
  103. virtual void ValidateClientPanel( CValidator &validator, const tchar *pchName ) OVERRIDE;
  104. #endif
  105. protected:
  106. virtual void OnContentSizeTraverse( float *pflContentWidth, float *pflContentHeight, float flMaxWidth, float flMaxHeight, bool bFinalDimensions ) OVERRIDE;
  107. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight ) OVERRIDE;
  108. bool EventVideoPlayerInitialized( IVideoPlayer *pIMovie );
  109. private:
  110. CVideoPlayerPtr m_pVideoPlayer;
  111. };
  112. //-----------------------------------------------------------------------------
  113. // Purpose: Displays debug info for a movie
  114. //-----------------------------------------------------------------------------
  115. class CMovieDebug : public CPanel2D
  116. {
  117. DECLARE_PANEL2D( CMovieDebug, CPanel2D );
  118. public:
  119. CMovieDebug( CPanel2D *pParent, const char *pchID );
  120. virtual ~CMovieDebug() {}
  121. void Show( CVideoPlayerPtr pVideoPlayer );
  122. private:
  123. void Update();
  124. CVideoPlayerPtr m_pVideoPlayer;
  125. CLabel *m_pDimensions;
  126. CLabel *m_pResolution;
  127. CLabel *m_pFileType;
  128. CLabel *m_pVideoSegment;
  129. CLabel *m_pVideoBandwidth;
  130. panorama::CUIScheduledDel m_scheduledUpdate;
  131. };
  132. //-----------------------------------------------------------------------------
  133. // Purpose: Movie player. Includes UI
  134. //-----------------------------------------------------------------------------
  135. class CMoviePlayer : public CPanel2D
  136. {
  137. DECLARE_PANEL2D( CMoviePlayer, CPanel2D );
  138. public:
  139. CMoviePlayer( CPanel2D *parent, const char *pchPanelID );
  140. virtual ~CMoviePlayer();
  141. virtual void SetupJavascriptObjectTemplate() OVERRIDE;
  142. CVideoPlayerPtr GetMovie() { return m_pMoviePanel->GetMovie(); }
  143. void SetMovie( const char *pchFile );
  144. void SetMovie( CVideoPlayerPtr pVideoPlayer );
  145. bool IsSet() { return m_pMoviePanel->IsSet(); }
  146. void Clear();
  147. enum EAutoplay
  148. {
  149. k_EAutoplayOff,
  150. k_EAutoplayOnLoad,
  151. k_EAutoplayOnFocus
  152. };
  153. enum EControls
  154. {
  155. k_EControlsNone,
  156. k_EControlsMinimal,
  157. k_EControlsFull,
  158. k_EControlsInvalid
  159. };
  160. void SetAutoplay( EAutoplay eAutoPlay, bool bSkipPlay = false );
  161. void SetRepeat( bool bRepeat );
  162. void SetControls( EControls eControls );
  163. void SetControls( const char *pchControls );
  164. virtual bool OnGamePadDown( const GamePadData_t &code ) OVERRIDE;
  165. virtual bool OnKeyTyped( const KeyData_t &unichar ) OVERRIDE;
  166. virtual panorama::IUIPanel *OnGetDefaultInputFocus() OVERRIDE;
  167. void Play();
  168. void Pause();
  169. void Stop();
  170. void TogglePlayPause();
  171. void FastForward();
  172. void Rewind();
  173. void SetPlaybackVolume( float flVolume );
  174. // title control
  175. void SetTitleText( const char *pchText );
  176. void ShowTitle( bool bImmediatelyVisible = false );
  177. void HideTitle();
  178. bool BAdjustingVolume();
  179. virtual bool OnMouseButtonDown( const MouseData_t &code );
  180. protected:
  181. virtual bool BSetProperties( const CUtlVector< ParsedPanelProperty_t > &vecProperties );
  182. static EControls EControlsFromString( const char *pchControls );
  183. bool EventInputFocusSet( const CPanelPtr< IUIPanel > &ptrPanel );
  184. bool EventInputFocusLost( const CPanelPtr< IUIPanel > &ptrPanel );
  185. bool EventMovieInitialized( IVideoPlayer *pIMovie );
  186. bool EventVideoPlayerPlaybackStateChanged( IVideoPlayer *pIMovie );
  187. bool EventVideoPlayerChangedRepresentation( IVideoPlayer *pIMovie );
  188. bool EventVideoPlayerEnded( IVideoPlayer *pIMovie );
  189. bool EventActivated( const CPanelPtr< IUIPanel > &ptrPanel, EPanelEventSource_t eSource );
  190. bool EventCancelled( const CPanelPtr< IUIPanel > &ptrPanel, EPanelEventSource_t eSource );
  191. bool EventMovieTogglePlayPause();
  192. bool EventMoviePlayerFastForward();
  193. bool EventMoviePlayerJumpBack();
  194. bool EventMoviePlayerVolumeControl();
  195. bool EventMoviePlayerSelectQuality();
  196. bool EventSoundVolumeChanged( ESoundType eSoundType, float flVolume );
  197. bool EventSoundMuteChanged( bool bMute );
  198. bool EventSetRepresentation( int iRep );
  199. void UpdateFullUI();
  200. void UpdateTimeline();
  201. void UpdatePlayPauseButton();
  202. void UpdatePlaybackSpeed();
  203. void Seek( uint unOffset );
  204. void RaisePlaybackStartEvents();
  205. void RaisePlaybackStopEvents();
  206. void DisplayControls( bool bVisible );
  207. void DisplayTimeline( bool bVisible );
  208. bool BAnyControlsVisible();
  209. bool BControlBarVisible();
  210. bool BTimelineVisible();
  211. void UpdateMovingPlayingStyle();
  212. void UpdateVolumeControls();
  213. void SetAudioVolumeStyle( CPanoramaSymbol symStyle );
  214. void ShowTitleInternal( bool bImmediatelyVisible = false );
  215. void HideTitleInternal();
  216. private:
  217. CMoviePanel *m_pMoviePanel;
  218. CPanelPtr< CMovieDebug > m_ptrDebug;
  219. // minimal UI
  220. CPanel2D *m_pLoadingThrobber;
  221. CPanel2D *m_pPlayIndicator;
  222. CPanoramaSymbol m_symMoviePlaybackStyle;
  223. // title sections
  224. CPanel2D *m_pPlaybackTitleAndControls;
  225. CLabel *m_pPlaybackTitle;
  226. bool m_bExternalShowTitle;
  227. // full UI
  228. CPanel2D *m_pPlaybackControls;
  229. CPanel2D *m_pPlaybackProgressBar;
  230. CToggleButton *m_pPlayPauseBtn;
  231. CLabel *m_pPlaybackSpeed;
  232. CPanel2D *m_pTimeline;
  233. CPanel2D *m_pControlBarRow;
  234. CPanel2D *m_pVolumeControl;
  235. CLabel *m_pErrorMessage;
  236. CPanelPtr< CVolumeSliderPopup > m_ptrVolumeSlider;
  237. CPanelPtr< CMovieVideoQualityPopup > m_ptrVideoQualityPopup;
  238. CButton *m_pVideoQualityBtn;
  239. bool m_bInConstructor;
  240. bool m_bRaisedAudioStartEvent;
  241. bool m_bRaisedPlaybackStartEvent;
  242. bool m_bHadFocus;
  243. bool m_bCloseControlsOnPlay;
  244. EAutoplay m_eAutoplay;
  245. EControls m_eControls;
  246. bool m_bDisableActivatePause;
  247. bool m_bShowControlsNotFullscreen;
  248. bool m_bRepeat;
  249. bool m_bMuted; // muted flag
  250. float m_flVolume; // playback volume, defaults to movie volume setting
  251. int m_iDesiredVideoRepresentation; // representation selected by user or -1. Video player might not yet have changed to playing this rep
  252. };
  253. } // namespace panorama
  254. #endif // PANORAMA_MOVIEPLAYER_H