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.

215 lines
6.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CHud handles the message, calculation, and drawing the HUD
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef HUD_H
  8. #define HUD_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlvector.h"
  13. #include "utldict.h"
  14. #include "convar.h"
  15. #include <vgui/VGUI.h>
  16. #include <Color.h>
  17. #include <bitbuf.h>
  18. namespace vgui
  19. {
  20. class IScheme;
  21. }
  22. // basic rectangle struct used for drawing
  23. typedef struct wrect_s
  24. {
  25. int left;
  26. int right;
  27. int top;
  28. int bottom;
  29. } wrect_t;
  30. //-----------------------------------------------------------------------------
  31. // Purpose:
  32. //-----------------------------------------------------------------------------
  33. class CHudTexture
  34. {
  35. public:
  36. CHudTexture();
  37. CHudTexture& operator =( const CHudTexture& src );
  38. virtual ~CHudTexture();
  39. int Width() const
  40. {
  41. return rc.right - rc.left;
  42. }
  43. int Height() const
  44. {
  45. return rc.bottom - rc.top;
  46. }
  47. // causes the font manager to generate the glyph, prevents run time hitches on platforms that have slow font managers
  48. void Precache( void );
  49. // returns width & height of icon with scale applied (scale is ignored if font is used to render)
  50. int EffectiveWidth( float flScale ) const;
  51. int EffectiveHeight( float flScale ) const;
  52. void DrawSelf( int x, int y, const Color& clr ) const;
  53. void DrawSelf( int x, int y, int w, int h, const Color& clr ) const;
  54. void DrawSelfCropped( int x, int y, int cropx, int cropy, int cropw, int croph, Color clr ) const;
  55. // new version to scale the texture over a finalWidth and finalHeight passed in
  56. void DrawSelfCropped( int x, int y, int cropx, int cropy, int cropw, int croph, int finalWidth, int finalHeight, Color clr ) const;
  57. char szShortName[ 64 ];
  58. char szTextureFile[ 64 ];
  59. bool bRenderUsingFont;
  60. bool bPrecached;
  61. char cCharacterInFont;
  62. vgui::HFont hFont;
  63. // vgui texture Id assigned to this item
  64. int textureId;
  65. // s0, t0, s1, t1
  66. float texCoords[ 4 ];
  67. // Original bounds
  68. wrect_t rc;
  69. };
  70. #include "hudtexturehandle.h"
  71. class CHudElement;
  72. class CHudRenderGroup;
  73. //-----------------------------------------------------------------------------
  74. // Purpose: Main hud manager
  75. //-----------------------------------------------------------------------------
  76. class CHud
  77. {
  78. public:
  79. //For progress bar orientations
  80. static const int HUDPB_HORIZONTAL;
  81. static const int HUDPB_VERTICAL;
  82. static const int HUDPB_HORIZONTAL_INV;
  83. public:
  84. CHud();
  85. ~CHud();
  86. // Init's called when the HUD's created at DLL load
  87. void Init( void );
  88. // VidInit's called when the video mode's changed
  89. void VidInit( void );
  90. // Shutdown's called when the engine's shutting down
  91. void Shutdown( void );
  92. // LevelInit's called whenever a new level is starting
  93. void LevelInit( void );
  94. // LevelShutdown's called whenever a level is finishing
  95. void LevelShutdown( void );
  96. void ResetHUD( void );
  97. // A saved game has just been loaded
  98. void OnRestore();
  99. void Think();
  100. void ProcessInput( bool bActive );
  101. void UpdateHud( bool bActive );
  102. void InitColors( vgui::IScheme *pScheme );
  103. // Hud element registration
  104. void AddHudElement( CHudElement *pHudElement );
  105. void RemoveHudElement( CHudElement *pHudElement );
  106. // Search list for "name" and return the hud element if it exists
  107. CHudElement *FindElement( const char *pName );
  108. bool IsHidden( int iHudFlags );
  109. float GetSensitivity();
  110. float GetFOVSensitivityAdjust();
  111. void DrawProgressBar( int x, int y, int width, int height, float percentage, Color& clr, unsigned char type );
  112. void DrawIconProgressBar( int x, int y, CHudTexture *icon, CHudTexture *icon2, float percentage, Color& clr, int type );
  113. CHudTexture *GetIcon( const char *szIcon );
  114. // loads a new icon into the list, without duplicates
  115. CHudTexture *AddUnsearchableHudIconToList( CHudTexture& texture );
  116. CHudTexture *AddSearchableHudIconToList( CHudTexture& texture );
  117. void RefreshHudTextures();
  118. // User messages
  119. void MsgFunc_ResetHUD(bf_read &msg);
  120. void MsgFunc_SendAudio(bf_read &msg);
  121. // Hud Render group
  122. int LookupRenderGroupIndexByName( const char *pszGroupName );
  123. bool LockRenderGroup( int iGroupIndex, CHudElement *pLocker = NULL );
  124. bool UnlockRenderGroup( int iGroupIndex, CHudElement *pLocker = NULL );
  125. bool IsRenderGroupLockedFor( CHudElement *pHudElement, int iGroupIndex );
  126. int RegisterForRenderGroup( const char *pszGroupName );
  127. int AddHudRenderGroup( const char *pszGroupName );
  128. bool DoesRenderGroupExist( int iGroupIndex );
  129. void SetScreenShotTime( float flTime ){ m_flScreenShotTime = flTime; }
  130. // Walk through all the HUD elements. Handler should be an object taking a CHudElement*
  131. template<typename THandler> void ForEachHudElement( THandler handler )
  132. {
  133. FOR_EACH_VEC( m_HudList, i )
  134. {
  135. handler( m_HudList[i] );
  136. }
  137. }
  138. public:
  139. int m_iKeyBits;
  140. #ifndef _XBOX
  141. float m_flMouseSensitivity;
  142. float m_flMouseSensitivityFactor;
  143. #endif
  144. float m_flFOVSensitivityAdjust;
  145. Color m_clrNormal;
  146. Color m_clrCaution;
  147. Color m_clrYellowish;
  148. CUtlVector< CHudElement * > m_HudList;
  149. private:
  150. void InitFonts();
  151. void SetupNewHudTexture( CHudTexture *t );
  152. bool m_bHudTexturesLoaded;
  153. // Global list of known icons
  154. CUtlDict< CHudTexture *, int > m_Icons;
  155. CUtlVector< const char * > m_RenderGroupNames;
  156. CUtlMap< int, CHudRenderGroup * > m_RenderGroups;
  157. float m_flScreenShotTime; // used to take end-game screenshots
  158. };
  159. extern CHud gHUD;
  160. //-----------------------------------------------------------------------------
  161. // Global fonts used in the client DLL
  162. //-----------------------------------------------------------------------------
  163. extern vgui::HFont g_hFontTrebuchet24;
  164. void LoadHudTextures( CUtlDict< CHudTexture *, int >& list, const char *szFilenameWithoutExtension, const unsigned char *pICEKey );
  165. void GetHudSize( int& w, int &h );
  166. #endif // HUD_H