Counter Strike : Global Offensive Source Code
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.

186 lines
4.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "idebugoverlaypanel.h"
  10. #include "overlaytext.h"
  11. #include <vgui/IVGui.h>
  12. #include "engine/ivdebugoverlay.h"
  13. #include "VGuiMatSurface/IMatSystemSurface.h"
  14. #include <vgui_controls/Panel.h>
  15. #include <vgui_controls/Controls.h>
  16. #include <vgui/IScheme.h>
  17. #include "ienginevgui.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. class CDebugOverlay : public vgui::Panel
  21. {
  22. typedef vgui::Panel BaseClass;
  23. public:
  24. explicit CDebugOverlay( vgui::VPANEL parent );
  25. virtual ~CDebugOverlay( void );
  26. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  27. virtual void Paint();
  28. virtual void OnTick( void );
  29. virtual bool ShouldDraw( void );
  30. private:
  31. vgui::HFont m_hFont;
  32. int m_LineSpacing;
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Instances the overlay object
  36. // Input : *parent -
  37. //-----------------------------------------------------------------------------
  38. CDebugOverlay::CDebugOverlay( vgui::VPANEL parent ) :
  39. BaseClass( NULL, "CDebugOverlay" )
  40. {
  41. int w, h;
  42. vgui::surface()->GetScreenSize( w, h );
  43. SetParent( parent );
  44. SetSize( w, h );
  45. SetPos( 0, 0 );
  46. SetVisible( false );
  47. SetCursor( 0 );
  48. m_hFont = 0;
  49. m_LineSpacing = 13;
  50. SetFgColor( Color( 0, 0, 0, 0 ) );
  51. SetPaintBackgroundEnabled( false );
  52. // set the scheme before any child control is created
  53. SetScheme("ClientScheme");
  54. vgui::ivgui()->AddTickSignal( GetVPanel(), 250 );
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose:
  58. //-----------------------------------------------------------------------------
  59. CDebugOverlay::~CDebugOverlay( void )
  60. {
  61. }
  62. void CDebugOverlay::ApplySchemeSettings(vgui::IScheme *pScheme)
  63. {
  64. BaseClass::ApplySchemeSettings(pScheme);
  65. // Use a large font
  66. m_hFont = pScheme->GetFont( IsGameConsole() ? "DebugFixed" : "DebugOverlay" );
  67. assert( m_hFont );
  68. if ( m_hFont )
  69. {
  70. m_LineSpacing = vgui::surface()->GetFontTall( m_hFont ) * 0.70f;
  71. m_LineSpacing = MAX( m_LineSpacing, 13 );
  72. }
  73. int w, h;
  74. vgui::surface()->GetScreenSize( w, h );
  75. SetSize( w, h );
  76. SetPos( 0, 0 );
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose:
  80. //-----------------------------------------------------------------------------
  81. void CDebugOverlay::OnTick( void )
  82. {
  83. bool bVisible = ShouldDraw();
  84. if ( IsVisible() != bVisible )
  85. {
  86. SetVisible( bVisible );
  87. }
  88. }
  89. bool CDebugOverlay::ShouldDraw( void )
  90. {
  91. if ( debugoverlay->GetFirst() )
  92. return true;
  93. return false;
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Paints the 2D overlay items to the screen
  97. //-----------------------------------------------------------------------------
  98. void CDebugOverlay::Paint()
  99. {
  100. OverlayText_t* pCurrText = debugoverlay->GetFirst();
  101. while ( pCurrText )
  102. {
  103. if ( pCurrText->text != NULL )
  104. {
  105. // --------------
  106. // Draw the text
  107. // --------------
  108. int r = pCurrText->r;
  109. int g = pCurrText->g;
  110. int b = pCurrText->b;
  111. int a = pCurrText->a;
  112. Vector screenPos;
  113. if ( pCurrText->bUseOrigin )
  114. {
  115. if ( !debugoverlay->ScreenPosition( pCurrText->origin, screenPos ) )
  116. {
  117. float xPos = screenPos[0];
  118. float yPos = screenPos[1] + ( pCurrText->lineOffset * m_LineSpacing );
  119. g_pMatSystemSurface->DrawColoredText( m_hFont, xPos, yPos, r, g, b, a, "%s", pCurrText->text );
  120. }
  121. }
  122. else
  123. {
  124. if ( !debugoverlay->ScreenPosition( pCurrText->flXPos,pCurrText->flYPos, screenPos ) )
  125. {
  126. float xPos = screenPos[0];
  127. float yPos = screenPos[1] + ( pCurrText->lineOffset * m_LineSpacing );
  128. g_pMatSystemSurface->DrawColoredText( m_hFont, xPos, yPos, r, g, b, a, "%s", pCurrText->text );
  129. }
  130. }
  131. }
  132. pCurrText = debugoverlay->GetNext( pCurrText );
  133. }
  134. debugoverlay->ClearDeadOverlays();
  135. }
  136. class CDebugOverlayPanel : public IDebugOverlayPanel
  137. {
  138. private:
  139. CDebugOverlay *debugOverlayPanel;
  140. public:
  141. CDebugOverlayPanel( void )
  142. {
  143. debugOverlayPanel = NULL;
  144. }
  145. void Create( vgui::VPANEL parent )
  146. {
  147. debugOverlayPanel = new CDebugOverlay( parent );
  148. }
  149. void Destroy( void )
  150. {
  151. if ( debugOverlayPanel )
  152. {
  153. debugOverlayPanel->SetParent( (vgui::Panel *)NULL );
  154. delete debugOverlayPanel;
  155. }
  156. }
  157. };
  158. static CDebugOverlayPanel g_DebugOverlay;
  159. IDebugOverlayPanel *debugoverlaypanel = ( IDebugOverlayPanel * )&g_DebugOverlay;
  160. void DebugDrawLine( const Vector& vecAbsStart, const Vector& vecAbsEnd, int r, int g, int b, bool test, float duration )
  161. {
  162. debugoverlay->AddLineOverlay( vecAbsStart + Vector( 0,0,0.1), vecAbsEnd + Vector( 0,0,0.1), r,g,b, test, duration );
  163. }