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.

113 lines
1.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hud.h"
  8. #include "hudelement.h"
  9. #include "hud_macros.h"
  10. #include "iclientmode.h"
  11. #include "hl1_hud_numbers.h"
  12. // This is a bad way to implement HL1 style sprite fonts, but it will work for now
  13. CHL1HudNumbers::CHL1HudNumbers( vgui::Panel *parent, const char *name ) : BaseClass( parent, name )
  14. {
  15. vgui::Panel *pParent = g_pClientMode->GetViewport();
  16. SetParent( pParent );
  17. }
  18. void CHL1HudNumbers::VidInit( void )
  19. {
  20. for ( int i = 0; i < 10; i++ )
  21. {
  22. char szNumString[ 10 ];
  23. sprintf( szNumString, "number_%d", i );
  24. icon_digits[ i ] = gHUD.GetIcon( szNumString );
  25. }
  26. }
  27. int CHL1HudNumbers::GetNumberFontHeight( void )
  28. {
  29. if ( icon_digits[ 0 ] )
  30. {
  31. return icon_digits[ 0 ]->Height();
  32. }
  33. else
  34. {
  35. return 0;
  36. }
  37. }
  38. int CHL1HudNumbers::GetNumberFontWidth( void )
  39. {
  40. if ( icon_digits[ 0 ] )
  41. {
  42. return icon_digits[ 0 ]->Width();
  43. }
  44. else
  45. {
  46. return 0;
  47. }
  48. }
  49. int CHL1HudNumbers::DrawHudNumber( int x, int y, int iNumber, Color &clrDraw )
  50. {
  51. int iWidth = GetNumberFontWidth();
  52. int k;
  53. if ( iNumber > 0 )
  54. {
  55. // SPR_Draw 100's
  56. if ( iNumber >= 100 )
  57. {
  58. k = iNumber / 100;
  59. icon_digits[ k ]->DrawSelf( x, y, clrDraw );
  60. x += iWidth;
  61. }
  62. else
  63. {
  64. x += iWidth;
  65. }
  66. // SPR_Draw 10's
  67. if ( iNumber >= 10 )
  68. {
  69. k = ( iNumber % 100 ) / 10;
  70. icon_digits[ k ]->DrawSelf( x, y, clrDraw );
  71. x += iWidth;
  72. }
  73. else
  74. {
  75. x += iWidth;
  76. }
  77. // SPR_Draw ones
  78. k = iNumber % 10;
  79. icon_digits[ k ]->DrawSelf( x, y, clrDraw );
  80. x += iWidth;
  81. }
  82. else
  83. {
  84. // SPR_Draw 100's
  85. x += iWidth;
  86. // SPR_Draw 10's
  87. x += iWidth;
  88. // SPR_Draw ones
  89. k = 0;
  90. icon_digits[ k ]->DrawSelf( x, y, clrDraw );
  91. x += iWidth;
  92. }
  93. return x;
  94. }