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.

409 lines
15 KiB

  1. //========= Copyright 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 "IVguiMatInfo.h"
  19. #ifdef CreateFont
  20. #undef CreateFont
  21. #endif
  22. #ifdef PlaySound
  23. #undef PlaySound
  24. #endif
  25. class Color;
  26. class ITexture;
  27. namespace vgui
  28. {
  29. class IImage;
  30. class Image;
  31. class Point;
  32. // handles
  33. typedef unsigned long HCursor;
  34. typedef unsigned long HTexture;
  35. typedef unsigned long HFont;
  36. //SRC only defines
  37. struct Vertex_t
  38. {
  39. Vertex_t() {}
  40. Vertex_t( const Vector2D &pos, const Vector2D &coord = Vector2D( 0, 0 ) )
  41. {
  42. m_Position = pos;
  43. m_TexCoord = coord;
  44. }
  45. void Init( const Vector2D &pos, const Vector2D &coord = Vector2D( 0, 0 ) )
  46. {
  47. m_Position = pos;
  48. m_TexCoord = coord;
  49. }
  50. Vector2D m_Position;
  51. Vector2D m_TexCoord;
  52. };
  53. enum FontDrawType_t
  54. {
  55. // Use the "additive" value from the scheme file
  56. FONT_DRAW_DEFAULT = 0,
  57. // Overrides
  58. FONT_DRAW_NONADDITIVE,
  59. FONT_DRAW_ADDITIVE,
  60. FONT_DRAW_TYPE_COUNT = 2,
  61. };
  62. // Refactor these two
  63. struct CharRenderInfo
  64. {
  65. // Text pos
  66. int x, y;
  67. // Top left and bottom right
  68. // This is now a pointer to an array maintained by the surface, to avoid copying the data on the 360
  69. Vertex_t *verts;
  70. int textureId;
  71. int abcA;
  72. int abcB;
  73. int abcC;
  74. int fontTall;
  75. HFont currentFont;
  76. // In:
  77. FontDrawType_t drawType;
  78. wchar_t ch;
  79. // Out
  80. bool valid;
  81. // In/Out (true by default)
  82. bool shouldclip;
  83. };
  84. struct IntRect
  85. {
  86. int x0;
  87. int y0;
  88. int x1;
  89. int y1;
  90. };
  91. //-----------------------------------------------------------------------------
  92. // Purpose: Wraps contextless windows system functions
  93. //-----------------------------------------------------------------------------
  94. class ISurface : public IAppSystem
  95. {
  96. public:
  97. // call to Shutdown surface; surface can no longer be used after this is called
  98. virtual void Shutdown() = 0;
  99. // frame
  100. virtual void RunFrame() = 0;
  101. // hierarchy root
  102. virtual VPANEL GetEmbeddedPanel() = 0;
  103. virtual void SetEmbeddedPanel( VPANEL pPanel ) = 0;
  104. // drawing context
  105. virtual void PushMakeCurrent(VPANEL panel, bool useInsets) = 0;
  106. virtual void PopMakeCurrent(VPANEL panel) = 0;
  107. // rendering functions
  108. virtual void DrawSetColor(int r, int g, int b, int a) = 0;
  109. virtual void DrawSetColor(Color col) = 0;
  110. virtual void DrawFilledRect(int x0, int y0, int x1, int y1) = 0;
  111. virtual void DrawFilledRectArray( IntRect *pRects, int numRects ) = 0;
  112. virtual void DrawOutlinedRect(int x0, int y0, int x1, int y1) = 0;
  113. virtual void DrawLine(int x0, int y0, int x1, int y1) = 0;
  114. virtual void DrawPolyLine(int *px, int *py, int numPoints) = 0;
  115. virtual void DrawSetTextFont(HFont font) = 0;
  116. virtual void DrawSetTextColor(int r, int g, int b, int a) = 0;
  117. virtual void DrawSetTextColor(Color col) = 0;
  118. virtual void DrawSetTextPos(int x, int y) = 0;
  119. virtual void DrawGetTextPos(int& x,int& y) = 0;
  120. virtual void DrawPrintText(const wchar_t *text, int textLen, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  121. virtual void DrawUnicodeChar(wchar_t wch, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  122. virtual void DrawFlushText() = 0; // flushes any buffered text (for rendering optimizations)
  123. virtual IHTML *CreateHTMLWindow(vgui::IHTMLEvents *events,VPANEL context)=0;
  124. virtual void PaintHTMLWindow(vgui::IHTML *htmlwin) =0;
  125. virtual void DeleteHTMLWindow(IHTML *htmlwin)=0;
  126. enum ETextureFormat
  127. {
  128. eTextureFormat_RGBA,
  129. eTextureFormat_BGRA,
  130. eTextureFormat_BGRA_Opaque, // bgra format but alpha is always 255, CEF does this, we can use this fact for better perf on win32 gdi
  131. };
  132. virtual int DrawGetTextureId( char const *filename ) = 0;
  133. virtual bool DrawGetTextureFile(int id, char *filename, int maxlen ) = 0;
  134. virtual void DrawSetTextureFile(int id, const char *filename, int hardwareFilter, bool forceReload) = 0;
  135. virtual void DrawSetTextureRGBA(int id, const unsigned char *rgba, int wide, int tall, int hardwareFilter, bool forceReload)=0;
  136. virtual void DrawSetTexture(int id) = 0;
  137. virtual void DrawGetTextureSize(int id, int &wide, int &tall) = 0;
  138. virtual void DrawTexturedRect(int x0, int y0, int x1, int y1) = 0;
  139. virtual bool IsTextureIDValid(int id) = 0;
  140. virtual bool DeleteTextureByID(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 void SetCursorAlwaysVisible( bool visible ) = 0;
  158. virtual bool IsCursorVisible() = 0;
  159. virtual void ApplyChanges() = 0;
  160. virtual bool IsWithin(int x, int y) = 0;
  161. virtual bool HasFocus() = 0;
  162. // returns true if the surface supports minimize & maximize capabilities
  163. enum SurfaceFeature_e
  164. {
  165. ANTIALIASED_FONTS = 1,
  166. DROPSHADOW_FONTS = 2,
  167. ESCAPE_KEY = 3,
  168. OPENING_NEW_HTML_WINDOWS = 4,
  169. FRAME_MINIMIZE_MAXIMIZE = 5,
  170. OUTLINE_FONTS = 6,
  171. DIRECT_HWND_RENDER = 7,
  172. };
  173. virtual bool SupportsFeature(SurfaceFeature_e feature) = 0;
  174. // restricts what gets drawn to one panel and it's children
  175. // currently only works in the game
  176. virtual void RestrictPaintToSinglePanel(VPANEL panel) = 0;
  177. // these two functions obselete, use IInput::SetAppModalSurface() instead
  178. virtual void SetModalPanel(VPANEL ) = 0;
  179. virtual VPANEL GetModalPanel() = 0;
  180. virtual void UnlockCursor() = 0;
  181. virtual void LockCursor() = 0;
  182. virtual void SetTranslateExtendedKeys(bool state) = 0;
  183. virtual VPANEL GetTopmostPopup() = 0;
  184. // engine-only focus handling (replacing WM_FOCUS windows handling)
  185. virtual void SetTopLevelFocus(VPANEL panel) = 0;
  186. // fonts
  187. // creates an empty handle to a vgui font. windows fonts can be add to this via SetFontGlyphSet().
  188. virtual HFont CreateFont() = 0;
  189. // adds to the font
  190. enum EFontFlags
  191. {
  192. FONTFLAG_NONE,
  193. FONTFLAG_ITALIC = 0x001,
  194. FONTFLAG_UNDERLINE = 0x002,
  195. FONTFLAG_STRIKEOUT = 0x004,
  196. FONTFLAG_SYMBOL = 0x008,
  197. FONTFLAG_ANTIALIAS = 0x010,
  198. FONTFLAG_GAUSSIANBLUR = 0x020,
  199. FONTFLAG_ROTARY = 0x040,
  200. FONTFLAG_DROPSHADOW = 0x080,
  201. FONTFLAG_ADDITIVE = 0x100,
  202. FONTFLAG_OUTLINE = 0x200,
  203. FONTFLAG_CUSTOM = 0x400, // custom generated font - never fall back to asian compatibility mode
  204. FONTFLAG_BITMAP = 0x800, // compiled bitmap font - no fallbacks
  205. };
  206. 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;
  207. // adds a custom font file (only supports true type font files (.ttf) for now)
  208. virtual bool AddCustomFontFile(const char *fontName, const char *fontFileName) = 0;
  209. // returns the details about the font
  210. virtual int GetFontTall(HFont font) = 0;
  211. virtual int GetFontTallRequested(HFont font) = 0;
  212. virtual int GetFontAscent(HFont font, wchar_t wch) = 0;
  213. virtual bool IsFontAdditive(HFont font) = 0;
  214. virtual void GetCharABCwide(HFont font, int ch, int &a, int &b, int &c) = 0;
  215. virtual int GetCharacterWidth(HFont font, int ch) = 0;
  216. virtual void GetTextSize(HFont font, const wchar_t *text, int &wide, int &tall) = 0;
  217. // notify icons?!?
  218. virtual VPANEL GetNotifyPanel() = 0;
  219. virtual void SetNotifyIcon(VPANEL context, HTexture icon, VPANEL panelToReceiveMessages, const char *text) = 0;
  220. // plays a sound
  221. virtual void PlaySound(const char *fileName) = 0;
  222. //!! these functions should not be accessed directly, but only through other vgui items
  223. //!! need to move these to seperate interface
  224. virtual int GetPopupCount() = 0;
  225. virtual VPANEL GetPopup(int index) = 0;
  226. virtual bool ShouldPaintChildPanel(VPANEL childPanel) = 0;
  227. virtual bool RecreateContext(VPANEL panel) = 0;
  228. virtual void AddPanel(VPANEL panel) = 0;
  229. virtual void ReleasePanel(VPANEL panel) = 0;
  230. virtual void MovePopupToFront(VPANEL panel) = 0;
  231. virtual void MovePopupToBack(VPANEL panel) = 0;
  232. virtual void SolveTraverse(VPANEL panel, bool forceApplySchemeSettings = false) = 0;
  233. virtual void PaintTraverse(VPANEL panel) = 0;
  234. virtual void EnableMouseCapture(VPANEL panel, bool state) = 0;
  235. // returns the size of the workspace
  236. virtual void GetWorkspaceBounds(int &x, int &y, int &wide, int &tall) = 0;
  237. // gets the absolute coordinates of the screen (in windows space)
  238. virtual void GetAbsoluteWindowBounds(int &x, int &y, int &wide, int &tall) = 0;
  239. // gets the base resolution used in proportional mode
  240. virtual void GetProportionalBase( int &width, int &height ) = 0;
  241. virtual void CalculateMouseVisible() = 0;
  242. virtual bool NeedKBInput() = 0;
  243. virtual bool HasCursorPosFunctions() = 0;
  244. virtual void SurfaceGetCursorPos(int &x, int &y) = 0;
  245. virtual void SurfaceSetCursorPos(int x, int y) = 0;
  246. // SRC only functions!!!
  247. virtual void DrawTexturedLine( const Vertex_t &a, const Vertex_t &b ) = 0;
  248. virtual void DrawOutlinedCircle(int x, int y, int radius, int segments) = 0;
  249. virtual void DrawTexturedPolyLine( const Vertex_t *p,int n ) = 0; // (Note: this connects the first and last points).
  250. virtual void DrawTexturedSubRect( int x0, int y0, int x1, int y1, float texs0, float text0, float texs1, float text1 ) = 0;
  251. virtual void DrawTexturedPolygon(int n, Vertex_t *pVertice, bool bClipVertices = true ) = 0;
  252. virtual const wchar_t *GetTitle(VPANEL panel) = 0;
  253. virtual bool IsCursorLocked( void ) const = 0;
  254. virtual void SetWorkspaceInsets( int left, int top, int right, int bottom ) = 0;
  255. // Lower level char drawing code, call DrawGet then pass in info to DrawRender
  256. virtual bool DrawGetUnicodeCharRenderInfo( wchar_t ch, CharRenderInfo& info ) = 0;
  257. virtual void DrawRenderCharFromInfo( const CharRenderInfo& info ) = 0;
  258. // global alpha setting functions
  259. // affect all subsequent draw calls - shouldn't normally be used directly, only in Panel::PaintTraverse()
  260. virtual void DrawSetAlphaMultiplier( float alpha /* [0..1] */ ) = 0;
  261. virtual float DrawGetAlphaMultiplier() = 0;
  262. // web browser
  263. virtual void SetAllowHTMLJavaScript( bool state ) = 0;
  264. // video mode changing
  265. virtual void OnScreenSizeChanged( int nOldWidth, int nOldHeight ) = 0;
  266. virtual vgui::HCursor CreateCursorFromFile( char const *curOrAniFile, char const *pPathID = 0 ) = 0;
  267. // create IVguiMatInfo object ( IMaterial wrapper in VguiMatSurface, NULL in CWin32Surface )
  268. virtual IVguiMatInfo *DrawGetTextureMatInfoFactory( int id ) = 0;
  269. virtual void PaintTraverseEx(VPANEL panel, bool paintPopups = false ) = 0;
  270. virtual float GetZPos() const = 0;
  271. // From the Xbox
  272. virtual void SetPanelForInput( VPANEL vpanel ) = 0;
  273. virtual void DrawFilledRectFastFade( int x0, int y0, int x1, int y1, int fadeStartPt, int fadeEndPt, unsigned int alpha0, unsigned int alpha1, bool bHorizontal ) = 0;
  274. virtual void DrawFilledRectFade( int x0, int y0, int x1, int y1, unsigned int alpha0, unsigned int alpha1, bool bHorizontal ) = 0;
  275. virtual void DrawSetTextureRGBAEx(int id, const unsigned char *rgba, int wide, int tall, ImageFormat imageFormat ) = 0;
  276. virtual void DrawSetTextScale(float sx, float sy) = 0;
  277. virtual bool SetBitmapFontGlyphSet(HFont font, const char *windowsFontName, float scalex, float scaley, int flags) = 0;
  278. // adds a bitmap font file
  279. virtual bool AddBitmapFontFile(const char *fontFileName) = 0;
  280. // sets a symbol for the bitmap font
  281. virtual void SetBitmapFontName( const char *pName, const char *pFontFilename ) = 0;
  282. // gets the bitmap font filename
  283. virtual const char *GetBitmapFontName( const char *pName ) = 0;
  284. virtual void ClearTemporaryFontCache( void ) = 0;
  285. virtual IImage *GetIconImageForFullPath( char const *pFullPath ) = 0;
  286. virtual void DrawUnicodeString( const wchar_t *pwString, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  287. virtual void PrecacheFontCharacters(HFont font, const wchar_t *pCharacters) = 0;
  288. // Console-only. Get the string to use for the current video mode for layout files.
  289. virtual const char *GetResolutionKey( void ) const = 0;
  290. virtual const char *GetFontName( HFont font ) = 0;
  291. virtual const char *GetFontFamilyName( HFont font ) = 0;
  292. virtual void GetKernedCharWidth( HFont font, wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA ) = 0;
  293. virtual bool ForceScreenSizeOverride( bool bState, int wide, int tall ) = 0;
  294. // LocalToScreen, ParentLocalToScreen fixups for explicit PaintTraverse calls on Panels not at 0, 0 position
  295. virtual bool ForceScreenPosOffset( bool bState, int x, int y ) = 0;
  296. virtual void OffsetAbsPos( int &x, int &y ) = 0;
  297. // Causes fonts to get reloaded, etc.
  298. virtual void ResetFontCaches() = 0;
  299. virtual int GetTextureNumFrames( int id ) = 0;
  300. virtual void DrawSetTextureFrame( int id, int nFrame, unsigned int *pFrameCache ) = 0;
  301. virtual bool IsScreenSizeOverrideActive( void ) = 0;
  302. virtual bool IsScreenPosOverrideActive( void ) = 0;
  303. virtual void DestroyTextureID( int id ) = 0;
  304. virtual void DrawUpdateRegionTextureRGBA( int nTextureID, int x, int y, const unsigned char *pchData, int wide, int tall, ImageFormat imageFormat ) = 0;
  305. virtual bool BHTMLWindowNeedsPaint(IHTML *htmlwin) = 0 ;
  306. virtual const char *GetWebkitHTMLUserAgentString() = 0;
  307. virtual void *Deprecated_AccessChromeHTMLController() = 0;
  308. // the origin of the viewport on the framebuffer (Which might not be 0,0 for stereo)
  309. virtual void SetFullscreenViewport( int x, int y, int w, int h ) = 0; // this uses NULL for the render target.
  310. virtual void GetFullscreenViewport( int & x, int & y, int & w, int & h ) = 0;
  311. virtual void PushFullscreenViewport() = 0;
  312. virtual void PopFullscreenViewport() = 0;
  313. // handles support for software cursors
  314. virtual void SetSoftwareCursor( bool bUseSoftwareCursor ) = 0;
  315. virtual void PaintSoftwareCursor() = 0;
  316. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  317. // !! WARNING! YOU MUST NOT ADD YOUR NEW METHOD HERE OR YOU WILL BREAK MODS !!
  318. // !! Add your new stuff to the bottom of IMatSystemSurface instead. !!
  319. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  320. };
  321. }
  322. #define VGUI_SURFACE_INTERFACE_VERSION "VGUI_Surface030"
  323. #endif // ISURFACE_H