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.

130 lines
3.4 KiB

  1. //========= Copyright 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. ConVar vgui_nav_lock( "vgui_nav_lock", "0", FCVAR_DEVELOPMENTONLY );
  13. ConVar vgui_nav_lock_default_button( "vgui_nav_lock_default_button", "0", FCVAR_DEVELOPMENTONLY );
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Determine length of text string
  16. // Input : *font -
  17. // *fmt -
  18. // ... -
  19. // Output :
  20. //-----------------------------------------------------------------------------
  21. int DrawTextLen( vgui::HFont font, const wchar_t *text )
  22. {
  23. int len = wcslen( text );
  24. int x = 0;
  25. vgui::surface()->DrawSetTextFont( font );
  26. for ( int i = 0 ; i < len; i++ )
  27. {
  28. int a, b, c;
  29. vgui::surface()->GetCharABCwide( font, text[i], a, b, c );
  30. // Ignore a
  31. if ( i != 0 )
  32. x += a;
  33. x += b;
  34. if ( i != len - 1 )
  35. x += c;
  36. }
  37. return x;
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose: Draws colored text to a vgui panel
  41. // Input : *font - font to use
  42. // x - position of text
  43. // y -
  44. // r - color of text
  45. // g -
  46. // b -
  47. // a - alpha ( 0 = opaque, 255 = transparent )
  48. // *fmt - va_* text string
  49. // ... -
  50. // Output : int - horizontal # of pixels drawn
  51. //-----------------------------------------------------------------------------
  52. int DrawColoredText( vgui::HFont font, int x, int y, int r, int g, int b, int a, const wchar_t *text )
  53. {
  54. int len = wcslen( text );
  55. if ( len <= 0 )
  56. return x;
  57. MatSysQueueMark( g_pMaterialSystem, "DrawColoredText\n" );
  58. vgui::surface()->DrawSetTextFont( font );
  59. vgui::surface()->DrawSetTextPos( x, y );
  60. vgui::surface()->DrawSetTextColor( r, g, b, a );
  61. int pixels = DrawTextLen( font, text );
  62. vgui::surface()->DrawPrintText( text, len );
  63. MatSysQueueMark( g_pMaterialSystem, "END DrawColoredText\n" );
  64. return x + pixels;
  65. }
  66. int DrawColoredText( vgui::HFont font, int x, int y, Color clr, const wchar_t *text )
  67. {
  68. int r, g, b, a;
  69. clr.GetColor( r, g, b, a );
  70. return ::DrawColoredText( font, x, y, r, g, b, a, text);
  71. }
  72. int DrawCenteredColoredText( vgui::HFont font, int left, int top, int right, int bottom, Color clr, const wchar_t *text )
  73. {
  74. int textHeight = vgui::surface()->GetFontTall( font );
  75. int textWidth = DrawTextLen( font, text );
  76. return DrawColoredText( font, (right + left) / 2 - textWidth / 2, (bottom + top) / 2 - textHeight / 2, clr, text );
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose:
  80. //-----------------------------------------------------------------------------
  81. CBasePanel::CBasePanel( vgui::Panel *parent, char const *panelName )
  82. : vgui::Panel( parent, panelName )
  83. {
  84. vgui::ivgui()->AddTickSignal( GetVPanel() );
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. //-----------------------------------------------------------------------------
  89. CBasePanel::~CBasePanel( void )
  90. {
  91. }
  92. void CBasePanel::OnTick()
  93. {
  94. if ( vgui_nav_lock.GetInt() > 0 )
  95. {
  96. vgui_nav_lock.SetValue( vgui_nav_lock.GetInt() - 1 );
  97. }
  98. if ( vgui_nav_lock_default_button.GetInt() > 0 )
  99. {
  100. vgui_nav_lock_default_button.SetValue( vgui_nav_lock_default_button.GetInt() - 1 );
  101. }
  102. SetVisible( ShouldDraw() );
  103. }