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.

391 lines
15 KiB

  1. //===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef ISURFACE_H
  8. #define ISURFACE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vgui/vgui.h"
  13. #include "vgui/IHTML.h" // CreateHTML, PaintHTML
  14. #include "tier1/interface.h"
  15. #include "bitmap/imageformat.h"
  16. #include "appframework/iappsystem.h"
  17. #include "mathlib/vector2d.h" // must be before the namespace line
  18. #include "vgui/ischemesurface.h"
  19. #include "IVguiMatInfo.h"
  20. #ifdef PlaySound
  21. #undef PlaySound
  22. #endif
  23. #define MENUROLLOVERSOUND "UI/menu_click04.wav"
  24. #define MENUROLLOVERSOUNDSMALL "UI/buttonrollover.wav"
  25. #define MENUCLOSESOUND "UI/menu_back.wav"
  26. #define MENUACCEPTSOUND "UI/menu_accept.wav"
  27. #define MENUOPTIONSOUND "UI/buttonclick_L4D.wav"
  28. #define MENUBINDSOUND "UI/buttonclick.wav"
  29. class Color;
  30. namespace vgui
  31. {
  32. class IImage;
  33. class Image;
  34. class Point;
  35. typedef FontHandle_t HFont;
  36. typedef FontVertex_t Vertex_t;
  37. struct IntRect
  38. {
  39. int x0;
  40. int y0;
  41. int x1;
  42. int y1;
  43. };
  44. struct DrawTexturedRectParms_t
  45. {
  46. DrawTexturedRectParms_t()
  47. {
  48. s0 = t0 = 0;
  49. s1 = t1 = 1.0f;
  50. alpha_ul = alpha_ur = alpha_lr = alpha_ll = 255;
  51. angle = 0;
  52. }
  53. int x0;
  54. int y0;
  55. int x1;
  56. int y1;
  57. float s0;
  58. float t0;
  59. float s1;
  60. float t1;
  61. unsigned char alpha_ul;
  62. unsigned char alpha_ur;
  63. unsigned char alpha_lr;
  64. unsigned char alpha_ll;
  65. float angle;
  66. };
  67. //-----------------------------------------------------------------------------
  68. // Purpose: Wraps contextless windows system functions
  69. //-----------------------------------------------------------------------------
  70. class ISurface : public IAppSystem
  71. {
  72. public:
  73. // call to Shutdown surface; surface can no longer be used after this is called
  74. virtual void Shutdown() = 0;
  75. // frame
  76. virtual void RunFrame() = 0;
  77. // hierarchy root
  78. virtual VPANEL GetEmbeddedPanel() = 0;
  79. virtual void SetEmbeddedPanel( VPANEL pPanel ) = 0;
  80. // drawing context
  81. virtual void PushMakeCurrent(VPANEL panel, bool useInsets) = 0;
  82. virtual void PopMakeCurrent(VPANEL panel) = 0;
  83. // rendering functions
  84. virtual void DrawSetColor(int r, int g, int b, int a) = 0;
  85. virtual void DrawSetColor(Color col) = 0;
  86. virtual void DrawFilledRect(int x0, int y0, int x1, int y1) = 0;
  87. virtual void DrawFilledRectArray( IntRect *pRects, int numRects ) = 0;
  88. virtual void DrawOutlinedRect(int x0, int y0, int x1, int y1) = 0;
  89. virtual void DrawLine(int x0, int y0, int x1, int y1) = 0;
  90. virtual void DrawPolyLine(int *px, int *py, int numPoints) = 0;
  91. virtual void DrawSetApparentDepth( float depth ) = 0;
  92. virtual void DrawClearApparentDepth() = 0;
  93. virtual void DrawSetTextFont(HFont font) = 0;
  94. virtual void DrawSetTextColor(int r, int g, int b, int a) = 0;
  95. virtual void DrawSetTextColor(Color col) = 0;
  96. virtual void DrawSetTextPos(int x, int y) = 0;
  97. virtual void DrawGetTextPos(int& x,int& y) = 0;
  98. virtual void DrawPrintText(const wchar_t *text, int textLen, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  99. virtual void DrawUnicodeChar(wchar_t wch, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  100. virtual void DrawFlushText() = 0; // flushes any buffered text (for rendering optimizations)
  101. virtual IHTML *CreateHTMLWindow(vgui::IHTMLEvents *events,VPANEL context)=0;
  102. virtual void PaintHTMLWindow(vgui::IHTML *htmlwin) =0;
  103. virtual void DeleteHTMLWindow(IHTML *htmlwin)=0;
  104. enum ETextureFormat
  105. {
  106. eTextureFormat_RGBA,
  107. eTextureFormat_BGRA,
  108. eTextureFormat_BGRA_Opaque, // bgra format but alpha is always 255, CEF does this, we can use this fact for better perf on win32 gdi
  109. };
  110. virtual int DrawGetTextureId( char const *filename ) = 0;
  111. virtual bool DrawGetTextureFile( int id, char *filename, int maxlen ) = 0;
  112. virtual void DrawSetTextureFile( int id, const char *filename, int hardwareFilter, bool forceReload ) = 0;
  113. virtual void DrawSetTextureRGBA( int id, const unsigned char *rgba, int wide, int tall ) = 0 ;
  114. virtual void DrawSetTexture(int id) = 0;
  115. virtual bool DeleteTextureByID(int id) = 0;
  116. #if defined( _X360 )
  117. //
  118. // Local gamerpic
  119. //
  120. // Get the texture id for the local gamerpic.
  121. virtual int GetLocalGamerpicTextureID( void ) = 0;
  122. // Update the local gamerpic texture. Use the given texture if a gamerpic cannot be loaded.
  123. virtual bool SetLocalGamerpicTexture( DWORD userIndex, const char *pDefaultGamerpicFileName ) = 0;
  124. // Set the current texture to be the local gamerpic.
  125. // Returns false if the local gamerpic texture has not been set.
  126. virtual bool DrawSetTextureLocalGamerpic( void ) = 0;
  127. //
  128. // Remote gamerpic
  129. //
  130. // Get the texture id for a remote gamerpic with the given xuid.
  131. virtual int GetRemoteGamerpicTextureID( XUID xuid ) = 0;
  132. // Update the remote gamerpic texture for the given xuid. Use the given texture if a gamerpic cannot be loaded.
  133. virtual bool SetRemoteGamerpicTextureID( XUID xuid, const char *pDefaultGamerpicFileName ) = 0;
  134. // Set the current texture to be the remote player's gamerpic.
  135. // Returns false if the remote gamerpic texture has not been set for the given xuid.
  136. virtual bool DrawSetTextureRemoteGamerpic( XUID xuid ) = 0;
  137. #endif // _X360
  138. virtual void DrawGetTextureSize(int id, int &wide, int &tall) = 0;
  139. virtual void DrawTexturedRect(int x0, int y0, int x1, int y1) = 0;
  140. virtual bool IsTextureIDValid(int id) = 0;
  141. virtual int CreateNewTextureID( bool procedural = false ) = 0;
  142. virtual void GetScreenSize(int &wide, int &tall) = 0;
  143. virtual void SetAsTopMost(VPANEL panel, bool state) = 0;
  144. virtual void BringToFront(VPANEL panel) = 0;
  145. virtual void SetForegroundWindow (VPANEL panel) = 0;
  146. virtual void SetPanelVisible(VPANEL panel, bool state) = 0;
  147. virtual void SetMinimized(VPANEL panel, bool state) = 0;
  148. virtual bool IsMinimized(VPANEL panel) = 0;
  149. virtual void FlashWindow(VPANEL panel, bool state) = 0;
  150. virtual void SetTitle(VPANEL panel, const wchar_t *title) = 0;
  151. virtual void SetAsToolBar(VPANEL panel, bool state) = 0; // removes the window's task bar entry (for context menu's, etc.)
  152. // windows stuff
  153. virtual void CreatePopup(VPANEL panel, bool minimised, bool showTaskbarIcon = true, bool disabled = false, bool mouseInput = true , bool kbInput = true) = 0;
  154. virtual void SwapBuffers(VPANEL panel) = 0;
  155. virtual void Invalidate(VPANEL panel) = 0;
  156. virtual void SetCursor(HCursor cursor) = 0;
  157. virtual bool IsCursorVisible() = 0;
  158. virtual void ApplyChanges() = 0;
  159. virtual bool IsWithin(int x, int y) = 0;
  160. virtual bool HasFocus() = 0;
  161. // returns true if the surface supports minimize & maximize capabilities
  162. enum SurfaceFeature_t
  163. {
  164. ANTIALIASED_FONTS = FONT_FEATURE_ANTIALIASED_FONTS,
  165. DROPSHADOW_FONTS = FONT_FEATURE_DROPSHADOW_FONTS,
  166. ESCAPE_KEY = 3,
  167. OPENING_NEW_HTML_WINDOWS = 4,
  168. FRAME_MINIMIZE_MAXIMIZE = 5,
  169. OUTLINE_FONTS = FONT_FEATURE_OUTLINE_FONTS,
  170. DIRECT_HWND_RENDER = 7,
  171. };
  172. virtual bool SupportsFeature( SurfaceFeature_t feature ) = 0;
  173. // restricts what gets drawn to one panel and it's children
  174. // currently only works in the game
  175. virtual void RestrictPaintToSinglePanel(VPANEL panel, bool bForceAllowNonModalSurface = false) = 0;
  176. // these two functions obselete, use IInput::SetAppModalSurface() instead
  177. virtual void SetModalPanel(VPANEL ) = 0;
  178. virtual VPANEL GetModalPanel() = 0;
  179. virtual void UnlockCursor() = 0;
  180. virtual void LockCursor() = 0;
  181. virtual void SetTranslateExtendedKeys(bool state) = 0;
  182. virtual VPANEL GetTopmostPopup() = 0;
  183. // engine-only focus handling (replacing WM_FOCUS windows handling)
  184. virtual void SetTopLevelFocus(VPANEL panel) = 0;
  185. // fonts
  186. // creates an empty handle to a vgui font. windows fonts can be add to this via SetFontGlyphSet().
  187. virtual HFont CreateFont() = 0;
  188. virtual bool SetFontGlyphSet(HFont font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin = 0, int nRangeMax = 0) = 0;
  189. // adds a custom font file (only supports true type font files (.ttf) for now)
  190. virtual bool AddCustomFontFile(const char *fontFileName) = 0;
  191. // returns the details about the font
  192. virtual int GetFontTall(HFont font) = 0;
  193. virtual int GetFontAscent(HFont font, wchar_t wch) = 0;
  194. virtual bool IsFontAdditive(HFont font) = 0;
  195. virtual void GetCharABCwide(HFont font, int ch, int &a, int &b, int &c) = 0;
  196. virtual int GetCharacterWidth(HFont font, int ch) = 0;
  197. virtual void GetTextSize(HFont font, const wchar_t *text, int &wide, int &tall) = 0;
  198. // notify icons?!?
  199. virtual VPANEL GetNotifyPanel() = 0;
  200. virtual void SetNotifyIcon(VPANEL context, HTexture icon, VPANEL panelToReceiveMessages, const char *text) = 0;
  201. // plays a sound
  202. virtual void PlaySound(const char *fileName) = 0;
  203. //!! these functions should not be accessed directly, but only through other vgui items
  204. //!! need to move these to seperate interface
  205. virtual int GetPopupCount() = 0;
  206. virtual VPANEL GetPopup(int index) = 0;
  207. virtual bool ShouldPaintChildPanel(VPANEL childPanel) = 0;
  208. virtual bool RecreateContext(VPANEL panel) = 0;
  209. virtual void AddPanel(VPANEL panel) = 0;
  210. virtual void ReleasePanel(VPANEL panel) = 0;
  211. virtual void MovePopupToFront(VPANEL panel) = 0;
  212. virtual void MovePopupToBack(VPANEL panel) = 0;
  213. virtual void SolveTraverse(VPANEL panel, bool forceApplySchemeSettings = false) = 0;
  214. virtual void PaintTraverse(VPANEL panel) = 0;
  215. virtual void EnableMouseCapture(VPANEL panel, bool state) = 0;
  216. // returns the size of the workspace
  217. virtual void GetWorkspaceBounds(int &x, int &y, int &wide, int &tall) = 0;
  218. // gets the absolute coordinates of the screen (in windows space)
  219. virtual void GetAbsoluteWindowBounds(int &x, int &y, int &wide, int &tall) = 0;
  220. // gets the base resolution used in proportional mode
  221. virtual void GetProportionalBase( int &width, int &height ) = 0;
  222. virtual void CalculateMouseVisible() = 0;
  223. virtual bool NeedKBInput() = 0;
  224. virtual bool HasCursorPosFunctions() = 0;
  225. virtual void SurfaceGetCursorPos(int &x, int &y) = 0;
  226. virtual void SurfaceSetCursorPos(int x, int y) = 0;
  227. // SRC only functions!!!
  228. virtual void DrawTexturedLine( const Vertex_t &a, const Vertex_t &b ) = 0;
  229. virtual void DrawOutlinedCircle(int x, int y, int radius, int segments) = 0;
  230. virtual void DrawTexturedPolyLine( const Vertex_t *p,int n ) = 0; // (Note: this connects the first and last points).
  231. virtual void DrawTexturedSubRect( int x0, int y0, int x1, int y1, float texs0, float text0, float texs1, float text1 ) = 0;
  232. virtual void DrawTexturedPolygon(int n, Vertex_t *pVertice, bool bClipVertices = true ) = 0;
  233. virtual const wchar_t *GetTitle(VPANEL panel) = 0;
  234. virtual bool IsCursorLocked( void ) const = 0;
  235. virtual void SetWorkspaceInsets( int left, int top, int right, int bottom ) = 0;
  236. // squarish comic book word bubble with pointer, rect params specify the space inside the bubble
  237. virtual void DrawWordBubble( int x0, int y0, int x1, int y1, int nBorderThickness, Color rgbaBackground, Color rgbaBorder,
  238. bool bPointer = false, int nPointerX = 0, int nPointerY = 0, int nPointerBaseThickness = 16 ) = 0;
  239. // Lower level char drawing code, call DrawGet then pass in info to DrawRender
  240. virtual bool DrawGetUnicodeCharRenderInfo( wchar_t ch, FontCharRenderInfo& info ) = 0;
  241. virtual void DrawRenderCharFromInfo( const FontCharRenderInfo& info ) = 0;
  242. // global alpha setting functions
  243. // affect all subsequent draw calls - shouldn't normally be used directly, only in Panel::PaintTraverse()
  244. virtual void DrawSetAlphaMultiplier( float alpha /* [0..1] */ ) = 0;
  245. virtual float DrawGetAlphaMultiplier() = 0;
  246. // web browser
  247. virtual void SetAllowHTMLJavaScript( bool state ) = 0;
  248. // video mode changing
  249. virtual void OnScreenSizeChanged( int nOldWidth, int nOldHeight ) = 0;
  250. virtual vgui::HCursor CreateCursorFromFile( char const *curOrAniFile, char const *pPathID = 0 ) = 0;
  251. // create IVguiMatInfo object ( IMaterial wrapper in VguiMatSurface, NULL in CWin32Surface )
  252. virtual IVguiMatInfo *DrawGetTextureMatInfoFactory( int id ) = 0;
  253. virtual void PaintTraverseEx(VPANEL panel, bool paintPopups = false ) = 0;
  254. virtual float GetZPos() const = 0;
  255. // From the Xbox
  256. virtual void SetPanelForInput( VPANEL vpanel ) = 0;
  257. virtual void DrawFilledRectFastFade( int x0, int y0, int x1, int y1, int fadeStartPt, int fadeEndPt, unsigned int alpha0, unsigned int alpha1, bool bHorizontal ) = 0;
  258. virtual void DrawFilledRectFade( int x0, int y0, int x1, int y1, unsigned int alpha0, unsigned int alpha1, bool bHorizontal ) = 0;
  259. virtual void DrawSetTextureRGBAEx(int id, const unsigned char *rgba, int wide, int tall, ImageFormat imageFormat ) = 0;
  260. virtual void DrawSetTextScale(float sx, float sy) = 0;
  261. virtual bool SetBitmapFontGlyphSet(HFont font, const char *windowsFontName, float scalex, float scaley, int flags) = 0;
  262. // adds a bitmap font file
  263. virtual bool AddBitmapFontFile(const char *fontFileName) = 0;
  264. // sets a symbol for the bitmap font
  265. virtual void SetBitmapFontName( const char *pName, const char *pFontFilename ) = 0;
  266. // gets the bitmap font filename
  267. virtual const char *GetBitmapFontName( const char *pName ) = 0;
  268. virtual void ClearTemporaryFontCache( void ) = 0;
  269. virtual IImage *GetIconImageForFullPath( char const *pFullPath ) = 0;
  270. virtual void DrawUnicodeString( const wchar_t *pwString, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  271. virtual void PrecacheFontCharacters(HFont font, wchar_t *pCharacters) = 0;
  272. virtual const char *GetFontName( HFont font ) = 0;
  273. virtual bool ForceScreenSizeOverride( bool bState, int wide, int tall ) = 0;
  274. // LocalToScreen, ParentLocalToScreen fixups for explicit PaintTraverse calls on Panels not at 0, 0 position
  275. virtual bool ForceScreenPosOffset( bool bState, int x, int y ) = 0;
  276. virtual void OffsetAbsPos( int &x, int &y ) = 0;
  277. virtual void SetAbsPosForContext( int id, int x, int y ) = 0;
  278. virtual void GetAbsPosForContext( int id, int &x, int& y ) = 0;
  279. // Causes fonts to get reloaded, etc.
  280. virtual void ResetFontCaches() = 0;
  281. virtual bool IsScreenSizeOverrideActive( void ) = 0;
  282. virtual bool IsScreenPosOverrideActive( void ) = 0;
  283. virtual void DestroyTextureID( int id ) = 0;
  284. virtual int GetTextureNumFrames( int id ) = 0;
  285. virtual void DrawSetTextureFrame( int id, int nFrame, unsigned int *pFrameCache ) = 0;
  286. virtual void GetClipRect( int &x0, int &y0, int &x1, int &y1 ) = 0;
  287. virtual void SetClipRect( int x0, int y0, int x1, int y1 ) = 0;
  288. virtual void DrawTexturedRectEx( DrawTexturedRectParms_t *pDrawParms ) = 0;
  289. virtual void GetKernedCharWidth( HFont font, wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA, float &abcC ) = 0;
  290. virtual void DrawUpdateRegionTextureRGBA( int nTextureID, int x, int y, const unsigned char *pchData, int wide, int tall, ImageFormat imageFormat ) = 0;
  291. virtual bool BHTMLWindowNeedsPaint(IHTML *htmlwin) = 0 ;
  292. virtual void DrawSetTextureRGBALinear( int id, const unsigned char *rgba, int wide, int tall ) = 0 ;
  293. virtual const char *GetWebkitHTMLUserAgentString() = 0;
  294. virtual void *Deprecated_AccessChromeHTMLController() = 0;
  295. };
  296. }
  297. #endif // ISURFACE_H