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.

174 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. #include "materialsystem/imaterialsystemhardwareconfig.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include "tier0/memdbgon.h"
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. class CHudHDRDemo : public CHudElement, public vgui::Panel
  25. {
  26. DECLARE_CLASS_SIMPLE( CHudHDRDemo, vgui::Panel );
  27. public:
  28. CHudHDRDemo( const char *name );
  29. // vgui overrides
  30. virtual void ApplySchemeSettings(vgui::IScheme *pScheme );
  31. virtual void Paint( void );
  32. virtual bool ShouldDraw( void );
  33. void SetHDRDemoActive( bool bActive );
  34. private:
  35. bool m_bHDRDemoActive;
  36. // Painting
  37. //CPanelAnimationVar( float, m_flAlphaOverride, "Alpha", "0" );
  38. CPanelAnimationVar( Color, m_BorderColor, "BorderColor", "0 0 0 255" );
  39. CPanelAnimationVar( Color, m_TextColor, "TextColor", "255 255 255 255" );
  40. CPanelAnimationVarAliasType( int, m_iBorderLeft, "BorderLeft", "8", "proportional_int" );
  41. CPanelAnimationVarAliasType( int, m_iBorderRight, "BorderRight", "8", "proportional_int" );
  42. CPanelAnimationVarAliasType( int, m_iBorderTop, "BorderTop", "8", "proportional_int" );
  43. CPanelAnimationVarAliasType( int, m_iBorderBottom, "BorderBottom", "8", "proportional_int" );
  44. CPanelAnimationVarAliasType( int, m_iBorderCenter, "BorderCenter", "8", "proportional_int" );
  45. CPanelAnimationVarAliasType( int, m_iLeftY, "LeftTitleY", "8", "proportional_int" );
  46. CPanelAnimationVarAliasType( int, m_iRightY, "RightTitleY", "8", "proportional_int" );
  47. };
  48. DECLARE_HUDELEMENT( CHudHDRDemo );
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. //-----------------------------------------------------------------------------
  52. CHudHDRDemo::CHudHDRDemo( const char *name ) : vgui::Panel( NULL, "HudHDRDemo" ), CHudElement( name )
  53. {
  54. vgui::Panel *pParent = g_pClientMode->GetViewport();
  55. SetParent( pParent );
  56. SetPaintBorderEnabled( false );
  57. SetPaintBackgroundEnabled( false );
  58. m_bHDRDemoActive = false;
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. void CHudHDRDemo::ApplySchemeSettings( vgui::IScheme *pScheme )
  64. {
  65. BaseClass::ApplySchemeSettings(pScheme);
  66. SetSize( ScreenWidth(), ScreenHeight() );
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. //-----------------------------------------------------------------------------
  71. void CHudHDRDemo::Paint()
  72. {
  73. int x, y, wide, tall;
  74. GetBounds( x, y, wide, tall );
  75. // Draw the borders
  76. vgui::surface()->DrawSetColor( m_BorderColor );
  77. vgui::surface()->DrawFilledRect( 0, 0, m_iBorderLeft, tall ); // Left
  78. vgui::surface()->DrawFilledRect( wide-m_iBorderRight, 0, wide, tall ); // Right
  79. vgui::surface()->DrawFilledRect( m_iBorderLeft, 0, wide-m_iBorderRight, m_iBorderTop ); // Top
  80. vgui::surface()->DrawFilledRect( m_iBorderLeft, tall-m_iBorderBottom, wide-m_iBorderRight, tall ); // Bottom
  81. vgui::surface()->DrawFilledRect( ((wide-m_iBorderCenter)/2), m_iBorderTop, ((wide+m_iBorderCenter)/2), tall-m_iBorderBottom ); // Center
  82. // Get our scheme and font information
  83. vgui::HScheme scheme = vgui::scheme()->GetScheme( "ClientScheme" );
  84. vgui::HFont hFont = vgui::scheme()->GetIScheme(scheme)->GetFont( "HDRDemoText" );
  85. vgui::surface()->DrawSetTextFont( hFont );
  86. vgui::surface()->DrawSetTextColor( m_TextColor );
  87. // Left Title
  88. wchar_t *tempString = g_pVGuiLocalize->Find("#Valve_HDRDEMO_LeftTitle");
  89. if (tempString)
  90. {
  91. int iLength = 0;
  92. for ( wchar_t *wch = tempString; *wch != 0; wch++ )
  93. {
  94. iLength += vgui::surface()->GetCharacterWidth( hFont, *wch );
  95. }
  96. vgui::surface()->DrawSetTextPos( floor(wide * 0.25) - (iLength / 2), m_iLeftY );
  97. vgui::surface()->DrawPrintText(tempString, wcslen(tempString));
  98. }
  99. // Right Title
  100. tempString = g_pVGuiLocalize->Find("#Valve_HDRDEMO_RightTitle");
  101. if (tempString)
  102. {
  103. int iLength = 0;
  104. for ( wchar_t *wch = tempString; *wch != 0; wch++ )
  105. {
  106. iLength += vgui::surface()->GetCharacterWidth( hFont, *wch );
  107. }
  108. vgui::surface()->DrawSetTextPos( ceil(wide * 0.75) - (iLength / 2), m_iRightY );
  109. vgui::surface()->DrawPrintText(tempString, wcslen(tempString));
  110. }
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose:
  114. //-----------------------------------------------------------------------------
  115. bool CHudHDRDemo::ShouldDraw()
  116. {
  117. return (
  118. // no split screen hud if not hdr
  119. (g_pMaterialSystemHardwareConfig->GetHDRType() != HDR_TYPE_NONE) &&
  120. m_bHDRDemoActive
  121. ); //&& m_flAlphaOverride > 0 );
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose:
  125. // Input : bActive -
  126. //-----------------------------------------------------------------------------
  127. void CHudHDRDemo::SetHDRDemoActive( bool bActive )
  128. {
  129. if ( bActive && !m_bHDRDemoActive )
  130. {
  131. ConVarRef pHideHud( "hidehud" );
  132. pHideHud.SetValue( 15 );
  133. }
  134. else if ( !bActive && m_bHDRDemoActive )
  135. {
  136. ConVarRef pHideHud( "hidehud" );
  137. pHideHud.SetValue( 0 );
  138. }
  139. m_bHDRDemoActive = bActive;
  140. }
  141. //=======================================================================================================
  142. // CONVAR to toggle this hud element
  143. void mat_show_ab_hdr_hudelement_changed( IConVar *pConVar, const char *pOldString, float flOldValue )
  144. {
  145. CHudHDRDemo *pHudDemo = (CHudHDRDemo*)GET_HUDELEMENT( CHudHDRDemo );
  146. if ( pHudDemo )
  147. {
  148. ConVarRef var( pConVar );
  149. pHudDemo->SetHDRDemoActive( var.GetBool() );
  150. }
  151. }
  152. ConVar mat_show_ab_hdr_hudelement( "mat_show_ab_hdr_hudelement", "0", FCVAR_CHEAT, "HDR Demo HUD Element toggle.", mat_show_ab_hdr_hudelement_changed );