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.

261 lines
9.2 KiB

  1. //===== Copyright � Valve Corporation, All rights reserved. ======//
  2. #ifndef IGAMEUISYSTEMMGR_H
  3. #define IGAMEUISYSTEMMGR_H
  4. #ifdef _WIN32
  5. #pragma once
  6. #endif
  7. // Forward declarations
  8. class IGameUISystemMgr;
  9. class IGameUIScreenController;
  10. class IGameUIScreenControllerFactory;
  11. class IGameUISystem;
  12. class IGameUIMiscUtils;
  13. class IGameUISystemSurface;
  14. class IGameUISchemeMgr;
  15. class IGameUIScheme;
  16. class IGameUISoundPlayback;
  17. class IMaterialProxy;
  18. // External includes
  19. #include "tier1/timeutils.h"
  20. #include "tier1/utlsymbol.h"
  21. #include "materialsystem/MaterialSystemUtil.h"
  22. #include "materialsystem/imaterialsystem.h"
  23. #include "vgui_surfacelib/ifontsurface.h"
  24. #include "rendersystem/irenderdevice.h"
  25. #include "inputsystem/InputEnums.h"
  26. // Game controls includes
  27. #include "miscutils.h"
  28. // Types
  29. FORWARD_DECLARE_HANDLE( InputContextHandle_t );
  30. //-----------------------------------------------------------------------------
  31. // Interface used to drive gameui (tier3)
  32. //-----------------------------------------------------------------------------
  33. #define GAMEUISYSTEMMGR_INTERFACE_VERSION "GameUISystemMgr001"
  34. abstract_class IGameUISystemMgr : public IAppSystem
  35. {
  36. public:
  37. virtual void SetGameUIVisible( bool bVisible ) = 0;
  38. virtual bool GetGameUIVisible() = 0;
  39. // Load the game UI menu screen
  40. // key values are owned and released by caller
  41. virtual IGameUISystem * LoadGameUIScreen( KeyValues *kvScreenLoadSettings ) = 0;
  42. virtual void ReleaseAllGameUIScreens() = 0;
  43. virtual void SetSoundPlayback( IGameUISoundPlayback *pPlayback ) = 0;
  44. virtual void UseGameInputSystemEventQueue( bool bEnable ) = 0;
  45. virtual void SetInputContext( InputContextHandle_t hInputContext ) = 0;
  46. virtual void RegisterInputEvent( const InputEvent_t &iEvent ) = 0;
  47. virtual void RunFrame() = 0;
  48. virtual void Render( const Rect_t &viewport, DmeTime_t flCurrentTime ) = 0;
  49. virtual void Render( IRenderContext *pRenderContext, PlatWindow_t hWnd, const Rect_t &viewport, DmeTime_t flCurrentTime ) = 0;
  50. virtual void RegisterScreenControllerFactory( char const *szControllerName, IGameUIScreenControllerFactory *pFactory ) = 0;
  51. virtual IGameUIScreenControllerFactory * GetScreenControllerFactory( char const *szControllerName ) = 0;
  52. virtual void SendEventToAllScreens( KeyValues *kvGlobalEvent ) = 0;
  53. virtual IGameUISystemSurface * GetSurface() = 0;
  54. virtual IGameUISchemeMgr * GetSchemeMgr() = 0;
  55. virtual IGameUIMiscUtils * GetMiscUtils() = 0;
  56. // Init any render targets needed by the UI.
  57. virtual void InitRenderTargets() = 0;
  58. virtual IMaterialProxy *CreateProxy( const char *proxyName ) = 0;
  59. };
  60. //-----------------------------------------------------------------------------
  61. // Used to allow clients to install code hooks to the gui screens
  62. //-----------------------------------------------------------------------------
  63. abstract_class IGameUIScreenController
  64. {
  65. public:
  66. // Connects a screen to the controller, returns number of
  67. // remaining connected screens (or 1 for the first connection)
  68. virtual int OnScreenConnected( IGameUISystem *pScreenView ) = 0;
  69. // Releases the screen from controller, returns number of
  70. // remaining connected screens (returns 0 if no screens are
  71. // connected - new object must be reacquired from factory
  72. // in this case)
  73. virtual int OnScreenDisconnected( IGameUISystem *pScreenView ) = 0;
  74. // Callback for screen events handling (caller retains ownership of keyvalues)
  75. virtual KeyValues * OnScreenEvent( IGameUISystem *pScreenView, KeyValues *kvEvent ) = 0;
  76. // Broadcast an event to all connected screens (caller retains ownership of keyvalues)
  77. virtual void BroadcastEventToScreens( KeyValues *kvEvent ) = 0;
  78. };
  79. abstract_class IGameUIScreenControllerFactory
  80. {
  81. public:
  82. // Returns an instance of a controller interface (keyvalues owned by caller)
  83. virtual IGameUIScreenController * GetController( KeyValues *kvRequest ) = 0;
  84. // Access controller instances
  85. virtual int GetControllerInstancesCount() = 0;
  86. virtual IGameUIScreenController * GetControllerInstance( int iIndex ) = 0;
  87. };
  88. //-----------------------------------------------------------------------------
  89. // IGameUISystem represents a logical collection of UI screens
  90. //-----------------------------------------------------------------------------
  91. abstract_class IGameUISystem
  92. {
  93. public:
  94. virtual char const * GetName() = 0;
  95. virtual bool ExecuteScript( KeyValues *kvEvent, KeyValues **ppResult = NULL ) = 0;
  96. virtual int32 GetScriptHandle() = 0;
  97. virtual void SetStageSize( int nWide, int nTall ) = 0;
  98. virtual void GetStageSize( Vector2D &stageSize ) = 0;
  99. };
  100. //-----------------------------------------------------------------------------
  101. // This class is the interface to the font and font texture, systems.
  102. // Load fonts given by schemes into the systems using this class.
  103. //-----------------------------------------------------------------------------
  104. class IGameUISystemSurface
  105. {
  106. public:
  107. virtual InitReturnVal_t Init() = 0;
  108. virtual void Shutdown() = 0;
  109. virtual void PrecacheFontCharacters( FontHandle_t font, wchar_t *pCharacterString = NULL ) = 0;
  110. virtual FontHandle_t CreateFont() = 0;
  111. virtual bool SetFontGlyphSet( FontHandle_t font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin = 0, int nRangeMax = 0 ) = 0;
  112. virtual int GetFontTall( FontHandle_t font ) = 0;
  113. virtual void GetCharABCwide( FontHandle_t font, int ch, int &a, int &b, int &c ) = 0;
  114. virtual int GetCharacterWidth( FontHandle_t font, int ch ) = 0;
  115. virtual const char *GetFontName( FontHandle_t font ) = 0;
  116. virtual bool AddCustomFontFile( const char *fontFileName ) = 0;
  117. // Helper fxns for loading bitmap fonts
  118. virtual bool AddBitmapFontFile( const char *fontFileName ) = 0;
  119. virtual void SetBitmapFontName( const char *pName, const char *pFontFilename ) = 0;
  120. virtual const char *GetBitmapFontName( const char *pName ) = 0;
  121. virtual bool SetBitmapFontGlyphSet( FontHandle_t font, const char *windowsFontName, float scalex, float scaley, int flags) = 0;
  122. virtual void ClearTemporaryFontCache( void ) = 0;
  123. // Causes fonts to get reloaded, etc.
  124. virtual void ResetFontCaches() = 0;
  125. virtual bool SupportsFontFeature( FontFeature_t feature ) = 0;
  126. virtual bool GetUnicodeCharRenderPositions( FontCharRenderInfo& info, Vector2D *pPositions ) = 0;
  127. virtual IMaterial *GetTextureForChar( FontCharRenderInfo &info, float **texCoords ) = 0;
  128. virtual IMaterial *GetTextureAndCoordsForChar( FontCharRenderInfo &info, float *texCoords ) = 0;
  129. // Used for debugging.
  130. virtual void DrawFontTexture( int textureId, int xPos, int yPos ) = 0;
  131. virtual void DrawFontTexture( IRenderContext *pRenderContext, int textureId, int xPos, int yPos ) = 0;
  132. virtual IMaterial *GetMaterial( int textureId ) = 0;
  133. virtual HRenderTexture GetTextureHandle( int textureId ) = 0;
  134. virtual void SetLanguage( const char *pLanguage ) = 0;
  135. virtual const char *GetLanguage() = 0;
  136. };
  137. //-----------------------------------------------------------------------------
  138. // Game UI scheme manager
  139. //-----------------------------------------------------------------------------
  140. abstract_class IGameUISchemeMgr
  141. {
  142. public:
  143. // loads a scheme from a file
  144. // first scheme loaded becomes the default scheme, and all subsequent loaded scheme are derivitives of that
  145. // tag is friendly string representing the name of the loaded scheme
  146. virtual IGameUIScheme * LoadSchemeFromFile( const char *fileName, const char *tag ) = 0;
  147. // reloads the schemes from the file
  148. virtual void ReloadSchemes() = 0;
  149. // reloads scheme fonts
  150. virtual void ReloadFonts( int inScreenTall = -1 ) = 0;
  151. // returns a handle to the default (first loaded) scheme
  152. virtual IGameUIScheme * GetDefaultScheme() = 0;
  153. // returns a handle to the scheme identified by "tag"
  154. virtual IGameUIScheme * GetScheme( const char *tag ) = 0;
  155. virtual void SetLanguage( const char *pLanguage ) = 0;
  156. virtual char const * GetLanguage() = 0;
  157. };
  158. //-----------------------------------------------------------------------------
  159. // Game UI version of a vgui scheme
  160. //-----------------------------------------------------------------------------
  161. abstract_class IGameUIScheme
  162. {
  163. public:
  164. // Gets at the scheme's name
  165. virtual const char *GetName() = 0;
  166. virtual const char *GetFileName() = 0;
  167. virtual FontHandle_t GetFont( const char *fontName, bool proportional = false ) = 0;
  168. virtual FontHandle_t GetFontNextSize( bool bUp, const char *fontName, bool proportional = false ) = 0;
  169. virtual char const * GetFontName( const FontHandle_t &font ) = 0;
  170. };
  171. //-----------------------------------------------------------------------------
  172. // Used to allow clients to install different sound playback systems
  173. //-----------------------------------------------------------------------------
  174. abstract_class IGameUISoundPlayback
  175. {
  176. public:
  177. // EmitSound will return a handle to the sound being played.
  178. // StopSound stops the sound given the handle to the sound
  179. virtual void *EmitSound( const char *pSoundName ) = 0;
  180. virtual void StopSound( void *pSoundHandle ) = 0;
  181. };
  182. //
  183. // LINK_GAME_CONTROLS_LIB() macro must be included in the outer .dll code
  184. // to force all required lib objects linked into the DLL.
  185. //
  186. extern void LinkGameControlsLib();
  187. #define LINK_GAME_CONTROLS_LIB() \
  188. namespace { \
  189. static class CLinkGameControlsLib { \
  190. public: \
  191. CLinkGameControlsLib() { \
  192. LinkGameControlsLib(); \
  193. } \
  194. } s_LinkHelper; \
  195. };
  196. #endif // IGAMEUISYSTEMMGR_H