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.

276 lines
8.2 KiB

  1. //========= Copyright 1996-2005, 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. #include "usermessages.h"
  19. namespace vgui
  20. {
  21. class IScheme;
  22. class Panel;
  23. }
  24. // basic rectangle struct used for drawing
  25. typedef struct wrect_s
  26. {
  27. int left;
  28. int right;
  29. int top;
  30. int bottom;
  31. } wrect_t;
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. //-----------------------------------------------------------------------------
  35. class CHudTexture
  36. {
  37. public:
  38. CHudTexture()
  39. {
  40. Q_memset( szShortName, 0, sizeof( szShortName ) );
  41. Q_memset( szTextureFile, 0, sizeof( szTextureFile ) );
  42. Q_memset( texCoords, 0, sizeof( texCoords ) );
  43. Q_memset( &rc, 0, sizeof( rc ) );
  44. textureId = -1;
  45. bRenderUsingFont = false;
  46. bPrecached = false;
  47. cCharacterInFont = 0;
  48. hFont = NULL;
  49. }
  50. CHudTexture& operator =( const CHudTexture& src )
  51. {
  52. if ( this == &src )
  53. return *this;
  54. Q_strncpy( szShortName, src.szShortName, sizeof( szShortName ) );
  55. Q_strncpy( szTextureFile, src.szTextureFile, sizeof( szTextureFile ) );
  56. Q_memcpy( texCoords, src.texCoords, sizeof( texCoords ) );
  57. textureId = src.textureId;
  58. rc = src.rc;
  59. bRenderUsingFont = src.bRenderUsingFont;
  60. cCharacterInFont = src.cCharacterInFont;
  61. hFont = src.hFont;
  62. return *this;
  63. }
  64. int Width() const
  65. {
  66. return rc.right - rc.left;
  67. }
  68. int Height() const
  69. {
  70. return rc.bottom - rc.top;
  71. }
  72. // causes the font manager to generate the glyph, prevents run time hitches on platforms that have slow font managers
  73. void Precache( void );
  74. // returns width & height of icon with scale applied (scale is ignored if font is used to render)
  75. int EffectiveWidth( float flScale ) const;
  76. int EffectiveHeight( float flScale ) const;
  77. void DrawSelf( int x, int y, const Color& clr, float flApparentZ = vgui::STEREO_NOOP ) const;
  78. void DrawSelf( int x, int y, int w, int h, const Color& clr, float flApparentZ = vgui::STEREO_NOOP ) const;
  79. void DrawSelfCropped( int x, int y, int cropx, int cropy, int cropw, int croph, Color clr, float flApparentZ = vgui::STEREO_NOOP ) const;
  80. // new version to scale the texture over a finalWidth and finalHeight passed in
  81. void DrawSelfCropped( int x, int y, int cropx, int cropy, int cropw, int croph, int finalWidth, int finalHeight, Color clr, float flApparentZ = vgui::STEREO_NOOP ) const;
  82. void DrawSelfScalableCorners( int x, int y, int w, int h, int iSrcCornerW, int iSrcCornerH, int iDrawCornerW, int iDrawCornerH, Color clr, float flApparentZ = vgui::STEREO_NOOP ) const;
  83. char szShortName[ 64 ];
  84. char szTextureFile[ 64 ];
  85. bool bRenderUsingFont;
  86. bool bPrecached;
  87. char cCharacterInFont;
  88. vgui::HFont hFont;
  89. // vgui texture Id assigned to this item
  90. int textureId;
  91. // s0, t0, s1, t1
  92. float texCoords[ 4 ];
  93. // Original bounds
  94. wrect_t rc;
  95. };
  96. #include "hudtexturehandle.h"
  97. class CHudElement;
  98. class CHudRenderGroup;
  99. //-----------------------------------------------------------------------------
  100. // Purpose: Main hud manager
  101. //-----------------------------------------------------------------------------
  102. class CHud
  103. {
  104. public:
  105. //For progress bar orientations
  106. static const int HUDPB_HORIZONTAL;
  107. static const int HUDPB_VERTICAL;
  108. static const int HUDPB_HORIZONTAL_INV;
  109. public:
  110. CHud();
  111. ~CHud();
  112. // Init's called when the HUD's created at DLL load
  113. void Init( void );
  114. // VidInit's called when the video mode's changed
  115. void VidInit( void );
  116. // Shutdown's called when the engine's shutting down
  117. void Shutdown( void );
  118. // LevelInit's called whenever a new level's starting
  119. void LevelInit( void );
  120. // LevelShutdown's called whenever a level's finishing
  121. void LevelShutdown( void );
  122. void ResetHUD( void );
  123. // A saved game has just been loaded
  124. void OnRestore();
  125. // called during simulation, Players and other moving actors
  126. // may not be in their final position when this is called
  127. void Think( void );
  128. // called just before rendering, Players will be in the right
  129. // position, but scaleform update may not be called between LateThink()
  130. // and when the scaleform display is updated (this is probably not an issue
  131. // just a good-to-know
  132. // Also, late think is only called when in the game.
  133. void LateThink( void );
  134. void ProcessInput( bool bActive );
  135. void OnTimeJump();
  136. void UpdateHud( bool bActive );
  137. void InitColors( vgui::IScheme *pScheme );
  138. // Hud element registration
  139. void AddHudElement( CHudElement *pHudElement );
  140. void RemoveHudElement( CHudElement *pHudElement );
  141. // Search list for "name" and return the hud element if it exists
  142. CHudElement *FindElement( const char *pName );
  143. bool IsHidden( int iHudFlags );
  144. float GetSensitivity();
  145. float GetFOVSensitivityAdjust();
  146. void DrawProgressBar( int x, int y, int width, int height, float percentage, Color& clr, unsigned char type );
  147. void DrawIconProgressBar( int x, int y, CHudTexture *icon, CHudTexture *icon2, float percentage, Color& clr, int type );
  148. // User messages
  149. bool MsgFunc_ResetHUD( const CCSUsrMsg_ResetHud& msg );
  150. bool MsgFunc_SendAudio( const CCSUsrMsg_SendAudio& msg );
  151. // Hud Render group
  152. int LookupRenderGroupIndexByName( const char *pszGroupName );
  153. bool LockRenderGroup( int iGroupIndex, CHudElement *pLocker = NULL );
  154. bool UnlockRenderGroup( int iGroupIndex, CHudElement *pLocker = NULL );
  155. bool IsRenderGroupLockedFor( CHudElement *pHudElement, int iGroupIndex );
  156. int RegisterForRenderGroup( const char *pszGroupName );
  157. int AddHudRenderGroup( const char *pszGroupName );
  158. bool DoesRenderGroupExist( int iGroupIndex );
  159. void SetScreenShotTime( float flTime ){ m_flScreenShotTime = flTime; }
  160. CUtlVector< CHudElement * > &GetHudList();
  161. const CUtlVector< CHudElement * > &GetHudList() const;
  162. CUtlVector< vgui::Panel * > &GetHudPanelList();
  163. const CUtlVector< vgui::Panel * > &GetHudPanelList() const;
  164. void OnSplitScreenStateChanged();
  165. void DisableHud( void );
  166. void EnableHud( void );
  167. bool HudDisabled( void );
  168. public:
  169. int m_iKeyBits;
  170. float m_flMouseSensitivity;
  171. float m_flMouseSensitivityFactor;
  172. float m_flFOVSensitivityAdjust;
  173. Color m_clrNormal;
  174. Color m_clrCaution;
  175. Color m_clrYellowish;
  176. CUtlVector< CHudElement * > m_HudList;
  177. // Same list as above, but with vgui::Panel dynamic_cast precomputed. These should all be non-NULL!!!
  178. CUtlVector< vgui::Panel * > m_HudPanelList;
  179. private:
  180. void InitFonts();
  181. void DoElementThink( CHudElement* pElement, vgui::Panel* pPanel );
  182. CUtlVector< const char * > m_RenderGroupNames;
  183. CUtlMap< int, CHudRenderGroup * > m_RenderGroups;
  184. float m_flScreenShotTime; // used to take end-game screenshots
  185. int m_nSplitScreenSlot;
  186. bool m_bEngineIsInGame;
  187. int m_iDisabledCount;
  188. };
  189. CHud &GetHud( int nSlot = -1 );
  190. class CHudIcons
  191. {
  192. public:
  193. CHudIcons();
  194. ~CHudIcons();
  195. void Init();
  196. void Shutdown();
  197. CHudTexture *GetIcon( const char *szIcon );
  198. // loads a new icon into the list, without duplicates
  199. CHudTexture *AddUnsearchableHudIconToList( CHudTexture& texture );
  200. CHudTexture *AddSearchableHudIconToList( CHudTexture& texture );
  201. void RefreshHudTextures();
  202. private:
  203. void SetupNewHudTexture( CHudTexture *t );
  204. bool m_bHudTexturesLoaded;
  205. // Global list of known icons
  206. CUtlDict< CHudTexture *, int > m_Icons;
  207. };
  208. CHudIcons &HudIcons();
  209. //-----------------------------------------------------------------------------
  210. // Global fonts used in the client DLL
  211. //-----------------------------------------------------------------------------
  212. extern vgui::HFont g_hFontTrebuchet24;
  213. void LoadHudTextures( CUtlDict< CHudTexture *, int >& list, char *szFilenameWithoutExtension, const unsigned char *pICEKey );
  214. void GetHudSize( int& w, int &h );
  215. #endif // HUD_H