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.

190 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include "cbase.h"
  9. #include "c_baseentity.h"
  10. #include "hud.h"
  11. #include "hudelement.h"
  12. #include "clientmode.h"
  13. #include <vgui_controls/Panel.h>
  14. #include <vgui/IScheme.h>
  15. #include <vgui/ISurface.h>
  16. #include <vgui/ILocalize.h>
  17. #include <vgui_controls/AnimationController.h>
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. class CHudFilmDemo : public CHudElement, public vgui::Panel
  24. {
  25. DECLARE_CLASS_SIMPLE( CHudFilmDemo, vgui::Panel );
  26. public:
  27. CHudFilmDemo( const char *name );
  28. // vgui overrides
  29. virtual void ApplySchemeSettings(vgui::IScheme *pScheme );
  30. virtual void Paint( void );
  31. virtual bool ShouldDraw( void );
  32. void SetFilmDemoActive( bool bActive );
  33. void SetLeftStringID( const char *id );
  34. void SetRightStringID( const char *id );
  35. private:
  36. bool m_bFilmDemoActive;
  37. char m_pLeftStringID[ 256 ];
  38. char m_pRightStringID[ 256 ];
  39. // Painting
  40. //CPanelAnimationVar( float, m_flAlphaOverride, "Alpha", "0" );
  41. CPanelAnimationVar( Color, m_BorderColor, "BorderColor", "0 0 0 255" );
  42. CPanelAnimationVar( Color, m_TextColor, "TextColor", "255 255 255 255" );
  43. CPanelAnimationVarAliasType( int, m_iBorderLeft, "BorderLeft", "8", "proportional_int" );
  44. CPanelAnimationVarAliasType( int, m_iBorderRight, "BorderRight", "8", "proportional_int" );
  45. CPanelAnimationVarAliasType( int, m_iBorderTop, "BorderTop", "8", "proportional_int" );
  46. CPanelAnimationVarAliasType( int, m_iBorderBottom, "BorderBottom", "48", "proportional_int" );
  47. CPanelAnimationVarAliasType( int, m_iBorderCenter, "BorderCenter", "8", "proportional_int" );
  48. CPanelAnimationVarAliasType( int, m_iLeftY, "LeftTitleY", "440", "proportional_int" );
  49. CPanelAnimationVarAliasType( int, m_iRightY, "RightTitleY", "440", "proportional_int" );
  50. };
  51. DECLARE_HUDELEMENT( CHudFilmDemo );
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. CHudFilmDemo::CHudFilmDemo( const char *name ) : vgui::Panel( NULL, "HudHDRDemo" ), CHudElement( name )
  56. {
  57. vgui::Panel *pParent = g_pClientMode->GetViewport();
  58. SetParent( pParent );
  59. SetPaintBorderEnabled( false );
  60. SetPaintBackgroundEnabled( false );
  61. m_bFilmDemoActive = false;
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose:
  65. //-----------------------------------------------------------------------------
  66. void CHudFilmDemo::ApplySchemeSettings( vgui::IScheme *pScheme )
  67. {
  68. BaseClass::ApplySchemeSettings(pScheme);
  69. SetSize( ScreenWidth(), ScreenHeight() );
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose:
  73. //-----------------------------------------------------------------------------
  74. void CHudFilmDemo::Paint()
  75. {
  76. int x, y, wide, tall;
  77. GetBounds( x, y, wide, tall );
  78. // Draw the borders
  79. vgui::surface()->DrawSetColor( m_BorderColor );
  80. vgui::surface()->DrawFilledRect( 0, 0, m_iBorderLeft, tall ); // Left
  81. vgui::surface()->DrawFilledRect( wide-m_iBorderRight, 0, wide, tall ); // Right
  82. vgui::surface()->DrawFilledRect( m_iBorderLeft, 0, wide-m_iBorderRight, m_iBorderTop ); // Top
  83. vgui::surface()->DrawFilledRect( m_iBorderLeft, tall-m_iBorderBottom, wide-m_iBorderRight, tall ); // Bottom
  84. vgui::surface()->DrawFilledRect( ((wide-m_iBorderCenter)/2), m_iBorderTop, ((wide+m_iBorderCenter)/2), tall-m_iBorderBottom ); // Center
  85. // Get our scheme and font information
  86. vgui::HScheme scheme = vgui::scheme()->GetScheme( "ClientScheme" );
  87. vgui::HFont hFont = vgui::scheme()->GetIScheme(scheme)->GetFont( "MenuTitle" );
  88. vgui::surface()->DrawSetTextFont( hFont );
  89. vgui::surface()->DrawSetTextColor( m_TextColor );
  90. wchar_t *tempString = g_pVGuiLocalize->Find( m_pLeftStringID );
  91. if( tempString )
  92. {
  93. int iLength = 0;
  94. for ( wchar_t *wch = tempString; *wch != 0; wch++ )
  95. {
  96. iLength += vgui::surface()->GetCharacterWidth( hFont, *wch );
  97. }
  98. vgui::surface()->DrawSetTextPos( floor(wide * 0.25) - (iLength / 2), m_iLeftY );
  99. vgui::surface()->DrawPrintText( tempString, wcslen(tempString) );
  100. }
  101. tempString = g_pVGuiLocalize->Find( m_pRightStringID );
  102. if( tempString )
  103. {
  104. int iLength = 0;
  105. for ( wchar_t *wch = tempString; *wch != 0; wch++ )
  106. {
  107. iLength += vgui::surface()->GetCharacterWidth( hFont, *wch );
  108. }
  109. vgui::surface()->DrawSetTextPos( ceil(wide * 0.75) - (iLength / 2), m_iRightY );
  110. vgui::surface()->DrawPrintText( tempString, wcslen(tempString) );
  111. }
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Purpose:
  115. //-----------------------------------------------------------------------------
  116. bool CHudFilmDemo::ShouldDraw()
  117. {
  118. return ( m_bFilmDemoActive ); //&& m_flAlphaOverride > 0 );
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. // Input : bActive -
  123. //-----------------------------------------------------------------------------
  124. void CHudFilmDemo::SetFilmDemoActive( bool bActive )
  125. {
  126. if ( bActive && !m_bFilmDemoActive )
  127. {
  128. ConVarRef hideHud( "hidehud" );
  129. hideHud.SetValue( 15 );
  130. }
  131. else if ( !bActive && m_bFilmDemoActive )
  132. {
  133. ConVarRef hideHud( "hidehud" );
  134. hideHud.SetValue( 0 );
  135. }
  136. m_bFilmDemoActive = bActive;
  137. }
  138. void CHudFilmDemo::SetLeftStringID( const char *id )
  139. {
  140. Q_strcpy( m_pLeftStringID, id );
  141. }
  142. void CHudFilmDemo::SetRightStringID( const char *id )
  143. {
  144. Q_strcpy( m_pRightStringID, id );
  145. }
  146. void EnableHUDFilmDemo( bool bEnable, const char *left_string_id, const char *right_string_id )
  147. {
  148. CHudFilmDemo *pHudDemo = (CHudFilmDemo*)GET_HUDELEMENT( CHudFilmDemo );
  149. if ( pHudDemo )
  150. {
  151. if( left_string_id )
  152. {
  153. pHudDemo->SetLeftStringID( left_string_id );
  154. }
  155. if( right_string_id )
  156. {
  157. pHudDemo->SetRightStringID( right_string_id );
  158. }
  159. pHudDemo->SetFilmDemoActive( bEnable );
  160. }
  161. }