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.

375 lines
13 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // Purpose:
  9. //
  10. // $NoKeywords: $
  11. //=============================================================================
  12. #ifndef ISURFACE_V30_H
  13. #define ISURFACE_V30_H
  14. #ifdef _WIN32
  15. #pragma once
  16. #endif
  17. #include <vgui/VGUI.h>
  18. #include <vgui/IHTML.h> // CreateHTML, PaintHTML
  19. #include "interface.h"
  20. #include "IVguiMatInfo.h"
  21. #include "appframework/IAppSystem.h"
  22. #include "bitmap/ImageFormat.h"
  23. #include "Vector2D.h" // must be before the namespace line
  24. #ifdef CreateFont
  25. #undef CreateFont
  26. #endif
  27. #ifdef PlaySound
  28. #undef PlaySound
  29. #endif
  30. class Color;
  31. namespace vgui
  32. {
  33. class Image;
  34. class Point;
  35. // handles
  36. typedef unsigned long HCursor;
  37. typedef unsigned long HTexture;
  38. typedef unsigned long HFont;
  39. }
  40. namespace SurfaceV30
  41. {
  42. //SRC only defines
  43. struct Vertex_t
  44. {
  45. Vertex_t() {}
  46. Vertex_t( const Vector2D &pos, const Vector2D &coord = Vector2D( 0, 0 ) )
  47. {
  48. m_Position = pos;
  49. m_TexCoord = coord;
  50. }
  51. void Init( const Vector2D &pos, const Vector2D &coord = Vector2D( 0, 0 ) )
  52. {
  53. m_Position = pos;
  54. m_TexCoord = coord;
  55. }
  56. Vector2D m_Position;
  57. Vector2D m_TexCoord;
  58. };
  59. enum FontDrawType_t
  60. {
  61. // Use the "additive" value from the scheme file
  62. FONT_DRAW_DEFAULT = 0,
  63. // Overrides
  64. FONT_DRAW_NONADDITIVE,
  65. FONT_DRAW_ADDITIVE,
  66. FONT_DRAW_TYPE_COUNT = 2,
  67. };
  68. // Refactor these two
  69. struct CharRenderInfo
  70. {
  71. // In:
  72. FontDrawType_t drawType;
  73. wchar_t ch;
  74. // Out
  75. bool valid;
  76. // In/Out (true by default)
  77. bool shouldclip;
  78. // Text pos
  79. int x, y;
  80. // Top left and bottom right
  81. Vertex_t verts[ 2 ];
  82. int textureId;
  83. int abcA;
  84. int abcB;
  85. int abcC;
  86. int fontTall;
  87. vgui::HFont currentFont;
  88. };
  89. struct IntRect
  90. {
  91. int x0;
  92. int y0;
  93. int x1;
  94. int y1;
  95. };
  96. //-----------------------------------------------------------------------------
  97. // Purpose: Wraps contextless windows system functions
  98. //-----------------------------------------------------------------------------
  99. class ISurface : public IAppSystem
  100. {
  101. public:
  102. // call to Shutdown surface; surface can no longer be used after this is called
  103. virtual void Shutdown() = 0;
  104. // frame
  105. virtual void RunFrame() = 0;
  106. // hierarchy root
  107. virtual vgui::VPANEL GetEmbeddedPanel() = 0;
  108. virtual void SetEmbeddedPanel( vgui::VPANEL pPanel ) = 0;
  109. // drawing context
  110. virtual void PushMakeCurrent(vgui::VPANEL panel, bool useInsets) = 0;
  111. virtual void PopMakeCurrent(vgui::VPANEL panel) = 0;
  112. // rendering functions
  113. virtual void DrawSetColor(int r, int g, int b, int a) = 0;
  114. virtual void DrawSetColor(Color col) = 0;
  115. virtual void DrawFilledRect(int x0, int y0, int x1, int y1) = 0;
  116. virtual void DrawFilledRectArray( IntRect *pRects, int numRects ) = 0;
  117. virtual void DrawOutlinedRect(int x0, int y0, int x1, int y1) = 0;
  118. virtual void DrawLine(int x0, int y0, int x1, int y1) = 0;
  119. virtual void DrawPolyLine(int *px, int *py, int numPoints) = 0;
  120. virtual void DrawSetTextFont(vgui::HFont font) = 0;
  121. virtual void DrawSetTextColor(int r, int g, int b, int a) = 0;
  122. virtual void DrawSetTextColor(Color col) = 0;
  123. virtual void DrawSetTextPos(int x, int y) = 0;
  124. virtual void DrawGetTextPos(int& x,int& y) = 0;
  125. virtual void DrawPrintText(const wchar_t *text, int textLen, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  126. virtual void DrawUnicodeChar(wchar_t wch, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  127. virtual void DrawFlushText() = 0; // flushes any buffered text (for rendering optimizations)
  128. virtual vgui::IHTML *CreateHTMLWindow(vgui::IHTMLEvents *events,vgui::VPANEL context)=0;
  129. virtual void PaintHTMLWindow(vgui::IHTML *htmlwin) =0;
  130. virtual void DeleteHTMLWindow(vgui::IHTML *htmlwin)=0;
  131. virtual int DrawGetTextureId( char const *filename ) = 0;
  132. virtual bool DrawGetTextureFile(int id, char *filename, int maxlen ) = 0;
  133. virtual void DrawSetTextureFile(int id, const char *filename, int hardwareFilter, bool forceReload) = 0;
  134. virtual void DrawSetTextureRGBA(int id, const unsigned char *rgba, int wide, int tall, int hardwareFilter, bool forceReload)=0;
  135. virtual void DrawSetTexture(int id) = 0;
  136. virtual void DrawGetTextureSize(int id, int &wide, int &tall) = 0;
  137. virtual void DrawTexturedRect(int x0, int y0, int x1, int y1) = 0;
  138. virtual bool IsTextureIDValid(int id) = 0;
  139. virtual int CreateNewTextureID( bool procedural = false ) = 0;
  140. #ifdef _XBOX
  141. virtual void DestroyTextureID( int id ) = 0;
  142. virtual bool IsCachedForRendering( int id, bool bSyncWait ) = 0;
  143. virtual void CopyFrontBufferToBackBuffer() = 0;
  144. virtual void UncacheUnusedMaterials() = 0;
  145. #endif
  146. virtual void GetScreenSize(int &wide, int &tall) = 0;
  147. virtual void SetAsTopMost(vgui::VPANEL panel, bool state) = 0;
  148. virtual void BringToFront(vgui::VPANEL panel) = 0;
  149. virtual void SetForegroundWindow (vgui::VPANEL panel) = 0;
  150. virtual void SetPanelVisible(vgui::VPANEL panel, bool state) = 0;
  151. virtual void SetMinimized(vgui::VPANEL panel, bool state) = 0;
  152. virtual bool IsMinimized(vgui::VPANEL panel) = 0;
  153. virtual void FlashWindow(vgui::VPANEL panel, bool state) = 0;
  154. virtual void SetTitle(vgui::VPANEL panel, const wchar_t *title) = 0;
  155. virtual void SetAsToolBar(vgui::VPANEL panel, bool state) = 0; // removes the window's task bar entry (for context menu's, etc.)
  156. // windows stuff
  157. virtual void CreatePopup(vgui::VPANEL panel, bool minimised, bool showTaskbarIcon = true, bool disabled = false, bool mouseInput = true , bool kbInput = true) = 0;
  158. virtual void SwapBuffers(vgui::VPANEL panel) = 0;
  159. virtual void Invalidate(vgui::VPANEL panel) = 0;
  160. virtual void SetCursor(vgui::HCursor cursor) = 0;
  161. virtual bool IsCursorVisible() = 0;
  162. virtual void ApplyChanges() = 0;
  163. virtual bool IsWithin(int x, int y) = 0;
  164. virtual bool HasFocus() = 0;
  165. // returns true if the surface supports minimize & maximize capabilities
  166. enum SurfaceFeature_e
  167. {
  168. ANTIALIASED_FONTS = 1,
  169. DROPSHADOW_FONTS = 2,
  170. ESCAPE_KEY = 3,
  171. OPENING_NEW_HTML_WINDOWS = 4,
  172. FRAME_MINIMIZE_MAXIMIZE = 5,
  173. OUTLINE_FONTS = 6,
  174. DIRECT_HWND_RENDER = 7,
  175. };
  176. virtual bool SupportsFeature(SurfaceFeature_e feature) = 0;
  177. // restricts what gets drawn to one panel and it's children
  178. // currently only works in the game
  179. virtual void RestrictPaintToSinglePanel(vgui::VPANEL panel) = 0;
  180. // these two functions obselete, use IInput::SetAppModalSurface() instead
  181. virtual void SetModalPanel(vgui::VPANEL ) = 0;
  182. virtual vgui::VPANEL GetModalPanel() = 0;
  183. virtual void UnlockCursor() = 0;
  184. virtual void LockCursor() = 0;
  185. virtual void SetTranslateExtendedKeys(bool state) = 0;
  186. virtual vgui::VPANEL GetTopmostPopup() = 0;
  187. // engine-only focus handling (replacing WM_FOCUS windows handling)
  188. virtual void SetTopLevelFocus(vgui::VPANEL panel) = 0;
  189. // fonts
  190. // creates an empty handle to a vgui font. windows fonts can be add to this via SetFontGlyphSet().
  191. virtual vgui::HFont CreateFont() = 0;
  192. // adds to the font
  193. enum EFontFlags
  194. {
  195. FONTFLAG_NONE,
  196. FONTFLAG_ITALIC = 0x001,
  197. FONTFLAG_UNDERLINE = 0x002,
  198. FONTFLAG_STRIKEOUT = 0x004,
  199. FONTFLAG_SYMBOL = 0x008,
  200. FONTFLAG_ANTIALIAS = 0x010,
  201. FONTFLAG_GAUSSIANBLUR = 0x020,
  202. FONTFLAG_ROTARY = 0x040,
  203. FONTFLAG_DROPSHADOW = 0x080,
  204. FONTFLAG_ADDITIVE = 0x100,
  205. FONTFLAG_OUTLINE = 0x200,
  206. FONTFLAG_CUSTOM = 0x400, // custom generated font - never fall back to asian compatibility mode
  207. FONTFLAG_BITMAP = 0x800, // compiled bitmap font - no fallbacks
  208. };
  209. virtual bool SetFontGlyphSet(vgui::HFont font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags) = 0;
  210. // adds a custom font file (only supports true type font files (.ttf) for now)
  211. virtual bool AddCustomFontFile(const char *fontName, const char *fontFileName) = 0;
  212. // returns the details about the font
  213. virtual int GetFontTall(vgui::HFont font) = 0;
  214. virtual int GetFontAscent(vgui::HFont font, wchar_t wch) = 0;
  215. virtual bool IsFontAdditive(vgui::HFont font) = 0;
  216. virtual void GetCharABCwide(vgui::HFont font, int ch, int &a, int &b, int &c) = 0;
  217. virtual int GetCharacterWidth(vgui::HFont font, int ch) = 0;
  218. virtual void GetTextSize(vgui::HFont font, const wchar_t *text, int &wide, int &tall) = 0;
  219. // notify icons?!?
  220. virtual vgui::VPANEL GetNotifyPanel() = 0;
  221. virtual void SetNotifyIcon(vgui::VPANEL context, vgui::HTexture icon, vgui::VPANEL panelToReceiveMessages, const char *text) = 0;
  222. // plays a sound
  223. virtual void PlaySound(const char *fileName) = 0;
  224. //!! these functions should not be accessed directly, but only through other vgui items
  225. //!! need to move these to seperate interface
  226. virtual int GetPopupCount() = 0;
  227. virtual vgui::VPANEL GetPopup(int index) = 0;
  228. virtual bool ShouldPaintChildPanel(vgui::VPANEL childPanel) = 0;
  229. virtual bool RecreateContext(vgui::VPANEL panel) = 0;
  230. virtual void AddPanel(vgui::VPANEL panel) = 0;
  231. virtual void ReleasePanel(vgui::VPANEL panel) = 0;
  232. virtual void MovePopupToFront(vgui::VPANEL panel) = 0;
  233. virtual void MovePopupToBack(vgui::VPANEL panel) = 0;
  234. virtual void SolveTraverse(vgui::VPANEL panel, bool forceApplySchemeSettings = false) = 0;
  235. virtual void PaintTraverse(vgui::VPANEL panel) = 0;
  236. virtual void EnableMouseCapture(vgui::VPANEL panel, bool state) = 0;
  237. // returns the size of the workspace
  238. virtual void GetWorkspaceBounds(int &x, int &y, int &wide, int &tall) = 0;
  239. // gets the absolute coordinates of the screen (in windows space)
  240. virtual void GetAbsoluteWindowBounds(int &x, int &y, int &wide, int &tall) = 0;
  241. // gets the base resolution used in proportional mode
  242. virtual void GetProportionalBase( int &width, int &height ) = 0;
  243. virtual void CalculateMouseVisible() = 0;
  244. virtual bool NeedKBInput() = 0;
  245. virtual bool HasCursorPosFunctions() = 0;
  246. virtual void SurfaceGetCursorPos(int &x, int &y) = 0;
  247. virtual void SurfaceSetCursorPos(int x, int y) = 0;
  248. // SRC only functions!!!
  249. virtual void DrawTexturedLine( const Vertex_t &a, const Vertex_t &b ) = 0;
  250. virtual void DrawOutlinedCircle(int x, int y, int radius, int segments) = 0;
  251. virtual void DrawTexturedPolyLine( const Vertex_t *p,int n ) = 0; // (Note: this connects the first and last points).
  252. virtual void DrawTexturedSubRect( int x0, int y0, int x1, int y1, float texs0, float text0, float texs1, float text1 ) = 0;
  253. virtual void DrawTexturedPolygon(int n, Vertex_t *pVertices) = 0;
  254. virtual const wchar_t *GetTitle(vgui::VPANEL panel) = 0;
  255. virtual bool IsCursorLocked( void ) const = 0;
  256. virtual void SetWorkspaceInsets( int left, int top, int right, int bottom ) = 0;
  257. // Lower level char drawing code, call DrawGet then pass in info to DrawRender
  258. virtual bool DrawGetUnicodeCharRenderInfo( wchar_t ch, CharRenderInfo& info ) = 0;
  259. virtual void DrawRenderCharFromInfo( const CharRenderInfo& info ) = 0;
  260. // global alpha setting functions
  261. // affect all subsequent draw calls - shouldn't normally be used directly, only in Panel::PaintTraverse()
  262. virtual void DrawSetAlphaMultiplier( float alpha /* [0..1] */ ) = 0;
  263. virtual float DrawGetAlphaMultiplier() = 0;
  264. // web browser
  265. virtual void SetAllowHTMLJavaScript( bool state ) = 0;
  266. // video mode changing
  267. virtual void OnScreenSizeChanged( int nOldWidth, int nOldHeight ) = 0;
  268. #if !defined( _XBOX )
  269. virtual vgui::HCursor CreateCursorFromFile( char const *curOrAniFile, char const *pPathID = 0 ) = 0;
  270. #endif
  271. // create IVguiMatInfo object ( IMaterial wrapper in VguiMatSurface, NULL in CWin32Surface )
  272. virtual IVguiMatInfo *DrawGetTextureMatInfoFactory( int id ) = 0;
  273. virtual void PaintTraverseEx(vgui::VPANEL panel, bool paintPopups = false ) = 0;
  274. virtual float GetZPos() const = 0;
  275. // From the Xbox
  276. virtual void SetPanelForInput( vgui::VPANEL vpanel ) = 0;
  277. virtual void DrawFilledRectFade( int x0, int y0, int x1, int y1, unsigned int alpha0, unsigned int alpha1, bool bHorizontal ) = 0;
  278. virtual void DrawSetTextureRGBAEx(int id, const unsigned char *rgba, int wide, int tall, ImageFormat imageFormat ) = 0;
  279. virtual void DrawSetTextScale(float sx, float sy) = 0;
  280. virtual bool SetBitmapFontGlyphSet(vgui::HFont font, const char *windowsFontName, float scalex, float scaley, int flags) = 0;
  281. // adds a bitmap font file
  282. virtual bool AddBitmapFontFile(const char *fontFileName) = 0;
  283. // sets a symbol for the bitmap font
  284. virtual void SetBitmapFontName( const char *pName, const char *pFontFilename ) = 0;
  285. // gets the bitmap font filename
  286. virtual const char *GetBitmapFontName( const char *pName ) = 0;
  287. virtual vgui::IImage *GetIconImageForFullPath( char const *pFullPath ) = 0;
  288. virtual void DrawUnicodeString( const wchar_t *pwString, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  289. };
  290. } // end namespace
  291. //-----------------------------------------------------------------------------
  292. // FIXME: This works around using scoped interfaces w/ EXPOSE_SINGLE_INTERFACE
  293. //-----------------------------------------------------------------------------
  294. class ISurfaceV30 : public SurfaceV30::ISurface
  295. {
  296. public:
  297. };
  298. #define VGUI_SURFACE_INTERFACE_VERSION_30 "VGUI_Surface030"
  299. #endif // ISURFACE_V30_H