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.

113 lines
3.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #include "client_pch.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Determine length of text string
  14. // Input : *font -
  15. // *fmt -
  16. // ... -
  17. // Output :
  18. //-----------------------------------------------------------------------------
  19. int DrawTextLen( vgui::HFont font, const wchar_t *text )
  20. {
  21. int len = wcslen( text );
  22. int x = 0;
  23. vgui::surface()->DrawSetTextFont( font );
  24. for ( int i = 0 ; i < len; i++ )
  25. {
  26. int a, b, c;
  27. vgui::surface()->GetCharABCwide( font, text[i], a, b, c );
  28. // Ignore a
  29. if ( i != 0 )
  30. x += a;
  31. x += b;
  32. if ( i != len - 1 )
  33. x += c;
  34. }
  35. return x;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose: Draws colored text to a vgui panel
  39. // Input : *font - font to use
  40. // x - position of text
  41. // y -
  42. // r - color of text
  43. // g -
  44. // b -
  45. // a - alpha ( 0 = opaque, 255 = transparent )
  46. // *fmt - va_* text string
  47. // ... -
  48. // Output : int - horizontal # of pixels drawn
  49. //-----------------------------------------------------------------------------
  50. void DrawColoredText( vgui::HFont font, int x, int y, int r, int g, int b, int a, const wchar_t *text )
  51. {
  52. int len = wcslen( text );
  53. if ( len <= 0 )
  54. return;
  55. MatSysQueueMark( g_pMaterialSystem, "DrawColoredText\n" );
  56. vgui::surface()->DrawSetTextFont( font );
  57. vgui::surface()->DrawSetTextPos( x, y );
  58. vgui::surface()->DrawSetTextColor( r, g, b, a );
  59. vgui::surface()->DrawPrintText( text, len );
  60. MatSysQueueMark( g_pMaterialSystem, "END DrawColoredText\n" );
  61. }
  62. void DrawColoredText( vgui::HFont font, int x, int y, Color clr, const wchar_t *text )
  63. {
  64. int r, g, b, a;
  65. clr.GetColor( r, g, b, a );
  66. ::DrawColoredText( font, x, y, r, g, b, a, text);
  67. }
  68. void DrawCenteredColoredText( vgui::HFont font, int left, int top, int right, int bottom, Color clr, const wchar_t *text )
  69. {
  70. int textHeight = vgui::surface()->GetFontTall( font );
  71. int textWidth = DrawTextLen( font, text );
  72. DrawColoredText( font, (right + left) / 2 - textWidth / 2, (bottom + top) / 2 - textHeight / 2, clr, text );
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Purpose:
  76. //-----------------------------------------------------------------------------
  77. CBasePanel::CBasePanel( vgui::Panel *parent, char const *panelName )
  78. : vgui::Panel( parent, panelName )
  79. {
  80. vgui::ivgui()->AddTickSignal( GetVPanel() );
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose:
  84. //-----------------------------------------------------------------------------
  85. CBasePanel::~CBasePanel( void )
  86. {
  87. }
  88. void CBasePanel::OnTick()
  89. {
  90. SetVisible( ShouldDraw() );
  91. }