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.

84 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Draws a timer in the format "Minutes:Seconds"
  4. // Seconds are padded with zeros
  5. //
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hudelement.h"
  9. #include <vgui_controls/Panel.h>
  10. #include <vgui/ISurface.h>
  11. #include "hud_basetimer.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. using namespace vgui;
  15. CHudBaseTimer::CHudBaseTimer(vgui::Panel *parent, const char *name) : BaseClass(parent, name)
  16. {
  17. m_iMinutes = 0;
  18. m_iSeconds = 0;
  19. SetLabelText(L"");
  20. }
  21. void CHudBaseTimer::SetMinutes(int minutes)
  22. {
  23. m_iMinutes = minutes;
  24. }
  25. void CHudBaseTimer::SetSeconds(int seconds)
  26. {
  27. m_iSeconds = seconds;
  28. }
  29. void CHudBaseTimer::PaintTime(HFont font, int xpos, int ypos, int mins, int secs)
  30. {
  31. surface()->DrawSetTextFont(font);
  32. wchar_t unicode[6];
  33. V_snwprintf(unicode, ARRAYSIZE(unicode), L"%d:%.2d", mins, secs);
  34. surface()->DrawSetTextPos(xpos, ypos);
  35. surface()->DrawUnicodeString( unicode );
  36. }
  37. void CHudBaseTimer::Paint()
  38. {
  39. float alpha = m_flAlphaOverride / 255;
  40. Color fgColor = GetFgColor();
  41. fgColor[3] *= alpha;
  42. SetFgColor( fgColor );
  43. surface()->DrawSetTextColor(GetFgColor());
  44. PaintTime( m_hNumberFont, digit_xpos, digit_ypos, m_iMinutes, m_iSeconds );
  45. // draw the overbright blur
  46. for (float fl = m_flBlur; fl > 0.0f; fl -= 1.0f)
  47. {
  48. if (fl >= 1.0f)
  49. {
  50. PaintTime(m_hNumberGlowFont, digit_xpos, digit_ypos, m_iMinutes, m_iSeconds);
  51. }
  52. else
  53. {
  54. // draw a percentage of the last one
  55. Color col = GetFgColor();
  56. col[3] *= fl;
  57. surface()->DrawSetTextColor(col);
  58. PaintTime(m_hNumberGlowFont, digit_xpos, digit_ypos, m_iMinutes, m_iSeconds);
  59. }
  60. }
  61. BaseClass::PaintLabel();
  62. }
  63. void CHudBaseTimer::SetToPrimaryColor()
  64. {
  65. SetFgColor(m_TextColor);
  66. }
  67. void CHudBaseTimer::SetToSecondaryColor()
  68. {
  69. SetFgColor(m_FlashColor);
  70. }