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.

745 lines
25 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef MATSYSTEMSURFACE_H
  8. #define MATSYSTEMSURFACE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/vgui.h>
  13. #include <vgui/ISurface.h>
  14. #include <vgui/IPanel.h>
  15. #include <vgui/IClientPanel.h>
  16. #include <vgui_controls/Panel.h>
  17. #include <vgui/IInput.h>
  18. #include <vgui_controls/Controls.h>
  19. #include <vgui/Point.h>
  20. #include "materialsystem/imaterialsystem.h"
  21. #include "VGuiMatSurface/IMatSystemSurface.h"
  22. #include "materialsystem/imesh.h"
  23. #include "materialsystem/imaterial.h"
  24. #include "utlvector.h"
  25. #include "utlsymbol.h"
  26. #include "materialsystem/MaterialSystemUtil.h"
  27. #include "tier1/utldict.h"
  28. #include "tier3/tier3.h"
  29. #include "inputsystem/iinputsystem.h"
  30. #include "inputsystem/iinputstacksystem.h"
  31. #include "vgui/ILocalize.h"
  32. #ifdef LINUX
  33. #include <ft2build.h>
  34. #include FT_FREETYPE_H
  35. #endif
  36. using namespace vgui;
  37. class IImage;
  38. class HtmlWindow;
  39. //-----------------------------------------------------------------------------
  40. // The default material system embedded panel
  41. //-----------------------------------------------------------------------------
  42. class CMatEmbeddedPanel : public vgui::Panel
  43. {
  44. typedef vgui::Panel BaseClass;
  45. public:
  46. CMatEmbeddedPanel();
  47. virtual void OnThink();
  48. VPANEL IsWithinTraverse(int x, int y, bool traversePopups);
  49. };
  50. //-----------------------------------------------------------------------------
  51. //
  52. // Implementation of the VGUI surface on top of the material system
  53. //
  54. //-----------------------------------------------------------------------------
  55. class CMatSystemSurface : public CTier3AppSystem< IMatSystemSurface >, public ISchemeSurface, public ILocalizeTextQuery
  56. {
  57. typedef CTier3AppSystem< IMatSystemSurface > BaseClass;
  58. public:
  59. CMatSystemSurface();
  60. virtual ~CMatSystemSurface();
  61. // Methods of IAppSystem
  62. virtual bool Connect( CreateInterfaceFn factory );
  63. virtual void Disconnect();
  64. virtual void *QueryInterface( const char *pInterfaceName );
  65. virtual InitReturnVal_t Init();
  66. virtual void Shutdown();
  67. virtual const AppSystemInfo_t* GetDependencies();
  68. virtual AppSystemTier_t GetTier() { return BaseClass::GetTier(); }
  69. virtual void Reconnect( CreateInterfaceFn factory, const char *pInterfaceName ) { BaseClass::Reconnect( factory, pInterfaceName ); }
  70. // initialization
  71. virtual void SetEmbeddedPanel(vgui::VPANEL pEmbeddedPanel);
  72. // returns true if a panel is minimzed
  73. bool IsMinimized(vgui::VPANEL panel);
  74. // Sets the only panel to draw. Set to NULL to clear.
  75. virtual void RestrictPaintToSinglePanel(vgui::VPANEL panel, bool bForceAllowNonModalSurface = false);
  76. // frame
  77. virtual void RunFrame();
  78. // implementation of vgui::ISurface
  79. virtual vgui::VPANEL GetEmbeddedPanel();
  80. // drawing context
  81. virtual void PushMakeCurrent(vgui::VPANEL panel,bool useInSets);
  82. virtual void PopMakeCurrent(vgui::VPANEL panel);
  83. // rendering functions
  84. virtual void DrawSetColor(int r,int g,int b,int a);
  85. virtual void DrawSetColor(Color col);
  86. virtual void DrawSetApparentDepth( float flDepth );
  87. virtual void DrawClearApparentDepth();
  88. virtual void DrawLine( int x0, int y0, int x1, int y1 );
  89. virtual void DrawTexturedLine( const Vertex_t &a, const Vertex_t &b );
  90. virtual void DrawPolyLine(int *px, int *py, int numPoints);
  91. virtual void DrawTexturedPolyLine( const Vertex_t *p, int n );
  92. virtual void DrawFilledRect(int x0, int y0, int x1, int y1);
  93. virtual void DrawFilledRectArray( IntRect *pRects, int numRects );
  94. virtual void DrawFilledRectFastFade( int x0, int y0, int x1, int y1, int fadeStartPt, int fadeEndPt, unsigned int alpha0, unsigned int alpha1, bool bHorizontal );
  95. virtual void DrawFilledRectFade( int x0, int y0, int x1, int y1, unsigned int alpha0, unsigned int alpha1, bool bHorizontal );
  96. virtual void DrawOutlinedRect(int x0, int y0, int x1, int y1);
  97. virtual void DrawOutlinedCircle(int x, int y, int radius, int segments);
  98. // textured rendering functions
  99. virtual int CreateNewTextureID( bool procedural = false );
  100. virtual bool IsTextureIDValid(int id);
  101. virtual bool DrawGetTextureFile(int id, char *filename, int maxlen );
  102. virtual int DrawGetTextureId( char const *filename );
  103. virtual void DrawSetTextureFile(int id, const char *filename, int hardwareFilter, bool forceReload);
  104. virtual void DrawSetTexture(int id);
  105. virtual void DrawGetTextureSize(int id, int &wide, int &tall);
  106. virtual bool DeleteTextureByID(int id);
  107. virtual IVguiMatInfo *DrawGetTextureMatInfoFactory( int id );
  108. virtual void DrawSetTextureRGBA( int id, const unsigned char *rgba, int wide, int tall );
  109. virtual void DrawSetTextureRGBALinear( int id, const unsigned char *rgba, int wide, int tall );
  110. #if defined( _X360 )
  111. //
  112. // Local gamerpic
  113. //
  114. // Get the texture id for the local gamerpic.
  115. virtual int GetLocalGamerpicTextureID( void );
  116. // Update the local gamerpic texture. Use the given texture if a gamerpic cannot be loaded.
  117. virtual bool SetLocalGamerpicTexture( DWORD userIndex, const char *pDefaultGamerpicFileName );
  118. // Set the current texture to be the local gamerpic.
  119. // Returns false if the local gamerpic texture has not been set.
  120. virtual bool DrawSetTextureLocalGamerpic( void );
  121. //
  122. // Remote gamerpic
  123. //
  124. // Get the texture id for a remote gamerpic with the given xuid.
  125. virtual int GetRemoteGamerpicTextureID( XUID xuid );
  126. // Update the remote gamerpic texture for the given xuid. Use the given texture if a gamerpic cannot be loaded.
  127. virtual bool SetRemoteGamerpicTextureID( XUID xuid, const char *pDefaultGamerpicFileName );
  128. // Set the current texture to be the remote player's gamerpic.
  129. // Returns false if the remote gamerpic texture has not been set for the given xuid.
  130. virtual bool DrawSetTextureRemoteGamerpic( XUID xuid );
  131. #endif // _X360
  132. virtual void DrawTexturedRect( int x0, int y0, int x1, int y1 );
  133. virtual void DrawTexturedSubRect( int x0, int y0, int x1, int y1, float texs0, float text0, float texs1, float text1 );
  134. virtual void DrawTexturedSubRectGradient( int x0, int y0, int x1, int y1, float texs0, float text0, float texs1, float text1, Color colStart, Color colEnd, bool bHorizontal );
  135. virtual void DrawTexturedPolygon(int n, Vertex_t *pVertices, bool bClipVertices = true );
  136. virtual void DrawWordBubble( int x0, int y0, int x1, int y1, int nBorderThickness, Color rgbaBackground, Color rgbaBorder,
  137. bool bPointer = false, int nPointerX = 0, int nPointerY = 0, int nPointerBaseThickness = 16 );
  138. virtual void DrawPrintText(const wchar_t *text, int textLen, FontDrawType_t drawType = FONT_DRAW_DEFAULT);
  139. virtual void DrawUnicodeChar(wchar_t wch, FontDrawType_t drawType = FONT_DRAW_DEFAULT );
  140. virtual void DrawUnicodeString( const wchar_t *pwString, FontDrawType_t drawType = FONT_DRAW_DEFAULT );
  141. virtual void DrawSetTextFont(vgui::HFont font);
  142. virtual void DrawFlushText();
  143. virtual void DrawSetTextColor(int r, int g, int b, int a);
  144. virtual void DrawSetTextColor(Color col);
  145. virtual void DrawSetTextScale(float sx, float sy);
  146. virtual void DrawSetTextPos(int x, int y);
  147. virtual void DrawGetTextPos(int& x,int& y);
  148. virtual vgui::IHTML *CreateHTMLWindow(vgui::IHTMLEvents *events,vgui::VPANEL context);
  149. virtual void PaintHTMLWindow(vgui::IHTML *htmlwin);
  150. virtual void DeleteHTMLWindow(vgui::IHTML *htmlwin);
  151. virtual bool BHTMLWindowNeedsPaint(IHTML *htmlwin);
  152. virtual void GetScreenSize(int &wide, int &tall);
  153. virtual void SetAsTopMost(vgui::VPANEL panel, bool state);
  154. virtual void BringToFront(vgui::VPANEL panel);
  155. virtual void SetForegroundWindow (vgui::VPANEL panel);
  156. virtual void SetPanelVisible(vgui::VPANEL panel, bool state);
  157. virtual void SetMinimized(vgui::VPANEL panel, bool state);
  158. virtual void FlashWindow(vgui::VPANEL panel, bool state);
  159. virtual void SetTitle(vgui::VPANEL panel, const wchar_t *title);
  160. virtual const wchar_t *GetTitle( vgui::VPANEL panel );
  161. virtual void SetAsToolBar(vgui::VPANEL panel, bool state); // removes the window's task bar entry (for context menu's, etc.)
  162. // windows stuff
  163. virtual void CreatePopup(VPANEL panel, bool minimized, bool showTaskbarIcon = true, bool disabled = false, bool mouseInput = true , bool kbInput = true);
  164. virtual void SwapBuffers(vgui::VPANEL panel);
  165. virtual void Invalidate(vgui::VPANEL panel);
  166. virtual void SetCursor(vgui::HCursor cursor);
  167. virtual bool IsCursorVisible();
  168. virtual void ApplyChanges();
  169. virtual bool IsWithin(int x, int y);
  170. virtual bool HasFocus();
  171. virtual bool SupportsFontFeature( FontFeature_t feature );
  172. virtual bool SupportsFeature( SurfaceFeature_t feature );
  173. // engine-only focus handling (replacing WM_FOCUS windows handling)
  174. virtual void SetTopLevelFocus(vgui::VPANEL panel);
  175. // fonts
  176. virtual vgui::HFont CreateFont();
  177. virtual bool SetFontGlyphSet(vgui::HFont font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin = 0, int nRangeMax = 0);
  178. virtual bool SetBitmapFontGlyphSet(vgui::HFont font, const char *windowsFontName, float scalex, float scaley, int flags);
  179. virtual int GetFontTall(HFont font);
  180. virtual int GetFontAscent(HFont font, wchar_t wch);
  181. virtual bool IsFontAdditive(HFont font);
  182. virtual void GetCharABCwide(HFont font, int ch, int &a, int &b, int &c);
  183. virtual void GetTextSize(HFont font, const wchar_t *text, int &wide, int &tall);
  184. virtual int GetCharacterWidth(vgui::HFont font, int ch);
  185. virtual bool AddCustomFontFile(const char *fontFileName);
  186. virtual bool AddBitmapFontFile(const char *fontFileName);
  187. virtual void SetBitmapFontName( const char *pName, const char *pFontFilename );
  188. virtual const char *GetBitmapFontName( const char *pName );
  189. virtual void PrecacheFontCharacters(HFont font, wchar_t *pCharacters);
  190. virtual void ClearTemporaryFontCache( void );
  191. virtual const char *GetFontName( HFont font );
  192. // uploads a part of a texture, used for font rendering
  193. void DrawSetSubTextureRGBA(int textureID, int drawX, int drawY, unsigned const char *rgba, int subTextureWide, int subTextureTall);
  194. void DrawUpdateRegionTextureRGBA( int nTextureID, int x, int y, const unsigned char *pchData, int wide, int tall, ImageFormat imageFormat );
  195. // helpers for web browser painting
  196. int GetHTMLWindowCount() { return _htmlWindows.Count(); }
  197. HtmlWindow *GetHTMLWindow(int i) { return _htmlWindows[i]; }
  198. // notify icons?!?
  199. virtual vgui::VPANEL GetNotifyPanel();
  200. virtual void SetNotifyIcon(vgui::VPANEL context, vgui::HTexture icon, vgui::VPANEL panelToReceiveMessages, const char *text);
  201. // plays a sound
  202. virtual void PlaySound(const char *fileName);
  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();
  206. virtual vgui::VPANEL GetPopup( int index );
  207. virtual bool ShouldPaintChildPanel(vgui::VPANEL childPanel);
  208. virtual bool RecreateContext(vgui::VPANEL panel);
  209. virtual void AddPanel(vgui::VPANEL panel);
  210. virtual void ReleasePanel(vgui::VPANEL panel);
  211. virtual void MovePopupToFront(vgui::VPANEL panel);
  212. virtual void SolveTraverse(vgui::VPANEL panel, bool forceApplySchemeSettings);
  213. virtual void PaintTraverse(vgui::VPANEL panel);
  214. virtual void EnableMouseCapture(vgui::VPANEL panel, bool state);
  215. virtual void SetWorkspaceInsets( int left, int top, int right, int bottom );
  216. virtual void GetWorkspaceBounds(int &x, int &y, int &wide, int &tall);
  217. // Hook needed to Get input to work
  218. virtual void SetAppDrivesInput( bool bLetAppDriveInput );
  219. virtual bool HandleInputEvent( const InputEvent_t &event );
  220. void InitFullScreenBuffer( const char *pszRenderTargetName );
  221. virtual void Set3DPaintTempRenderTarget( const char *pRenderTargetName );
  222. virtual void Reset3DPaintTempRenderTarget( void );
  223. // Begins, ends 3D painting
  224. virtual void Begin3DPaint( int iLeft, int iTop, int iRight, int iBottom, bool bSupersampleRT = false );
  225. virtual void End3DPaint( bool bIgnoreAlphaWhenCompositing );
  226. // Disable clipping during rendering
  227. virtual void DisableClipping( bool bDisable );
  228. // Prevents vgui from changing the cursor
  229. virtual bool IsCursorLocked() const;
  230. // Sets the mouse Get + Set callbacks
  231. virtual void SetMouseCallbacks( GetMouseCallback_t GetFunc, SetMouseCallback_t SetFunc );
  232. // Tells the surface to ignore windows messages
  233. virtual void EnableWindowsMessages( bool bEnable );
  234. // Installs a function to play sounds
  235. virtual void InstallPlaySoundFunc( PlaySoundFunc_t soundFunc );
  236. // Some drawing methods that cannot be accomplished under Win32
  237. virtual void DrawColoredCircle( int centerx, int centery, float radius, int r, int g, int b, int a );
  238. virtual void DrawColoredText( vgui::HFont font, int x, int y, int r, int g, int b, int a, const char *fmt, ... ) OVERRIDE;
  239. virtual void DrawColoredTextRect( vgui::HFont font, int x, int y, int w, int h, int r, int g, int b, int a, const char *fmt, ... ) OVERRIDE;
  240. virtual void DrawTextHeight( vgui::HFont font, int w, int& h, char *fmt, ... );
  241. // Returns the length in pixels of the text
  242. virtual int DrawTextLen( vgui::HFont font, const char *fmt, ... );
  243. // Draws a panel in 3D space.
  244. virtual void DrawPanelIn3DSpace( vgui::VPANEL pRootPanel, const VMatrix &panelCenterToWorld, int pw, int ph, float sw, float sh );
  245. // Only visible within vguimatsurface
  246. void DrawSetTextureMaterial(int id, IMaterial *pMaterial);
  247. void ReferenceProceduralMaterial( int id, int referenceId, IMaterial *pMaterial );
  248. // new stuff for Alfreds VGUI2 port!!
  249. virtual bool InEngine() { return true; }
  250. void GetProportionalBase( int &width, int &height ) { width = BASE_WIDTH; height = BASE_HEIGHT; }
  251. virtual bool HasCursorPosFunctions() { return true; }
  252. virtual void SetModalPanel(VPANEL );
  253. virtual VPANEL GetModalPanel();
  254. virtual void UnlockCursor();
  255. virtual void LockCursor();
  256. virtual void SetTranslateExtendedKeys(bool state);
  257. virtual VPANEL GetTopmostPopup();
  258. virtual void GetAbsoluteWindowBounds(int &x, int &y, int &wide, int &tall);
  259. virtual void CalculateMouseVisible();
  260. virtual bool NeedKBInput();
  261. virtual void SurfaceGetCursorPos(int &x, int &y);
  262. virtual void SurfaceSetCursorPos(int x, int y);
  263. virtual void MovePopupToBack(VPANEL panel);
  264. virtual bool IsInThink( VPANEL panel);
  265. virtual bool DrawGetUnicodeCharRenderInfo( wchar_t ch, FontCharRenderInfo& info );
  266. virtual void DrawRenderCharFromInfo( const FontCharRenderInfo& info );
  267. // global alpha setting functions
  268. // affect all subsequent draw calls - shouldn't normally be used directly, only in Panel::PaintTraverse()
  269. virtual void DrawSetAlphaMultiplier( float alpha /* [0..1] */ );
  270. virtual float DrawGetAlphaMultiplier();
  271. // web browser
  272. virtual void SetAllowHTMLJavaScript( bool state );
  273. // video mode changing
  274. virtual void OnScreenSizeChanged( int nOldWidth, int nOldHeight );
  275. virtual vgui::HCursor CreateCursorFromFile( char const *curOrAniFile, char const *pPathID );
  276. virtual void PaintTraverseEx(VPANEL panel, bool paintPopups = false );
  277. virtual float GetZPos() const;
  278. virtual void SetPanelForInput( VPANEL vpanel );
  279. virtual vgui::IImage *GetIconImageForFullPath( char const *pFullPath );
  280. virtual void DestroyTextureID( int id );
  281. virtual void GetKernedCharWidth( HFont font, wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &flabcA, float &abcC );
  282. virtual const char *GetWebkitHTMLUserAgentString() { return "Valve Client"; }
  283. virtual void *Deprecated_AccessChromeHTMLController() OVERRIDE { return NULL; }
  284. // Methods of ILocalizeTextQuery
  285. //virtual int ComputeTextWidth( const wchar_t *pString );
  286. virtual bool ForceScreenSizeOverride( bool bState, int wide, int tall );
  287. // LocalToScreen, ParentLocalToScreen fixups for explicit PaintTraverse calls on Panels not at 0, 0 position
  288. virtual bool ForceScreenPosOffset( bool bState, int x, int y );
  289. virtual void OffsetAbsPos( int &x, int &y );
  290. virtual void SetAbsPosForContext( int id, int x, int y );
  291. virtual void GetAbsPosForContext( int id, int &x, int& y );
  292. // Causes fonts to get reloaded, etc.
  293. virtual void ResetFontCaches();
  294. virtual bool IsScreenSizeOverrideActive( void );
  295. virtual bool IsScreenPosOverrideActive( void );
  296. virtual IMaterial *DrawGetTextureMaterial( int id );
  297. virtual void SetInputContext( InputContextHandle_t hContext );
  298. virtual int GetTextureNumFrames( int id );
  299. virtual void DrawSetTextureFrame( int id, int nFrame, unsigned int *pFrameCache );
  300. virtual void GetClipRect( int &x0, int &y0, int &x1, int &y1 );
  301. virtual void SetClipRect( int x0, int y0, int x1, int y1 );
  302. virtual void SetLanguage( const char *pLanguage );
  303. virtual const char *GetLanguage();
  304. InputContextHandle_t GetInputContext() const;
  305. virtual void DrawTexturedRectEx( DrawTexturedRectParms_t *pDrawParms );
  306. // Methods of ILocalizeTextQuery
  307. public:
  308. virtual int ComputeTextWidth( const wchar_t *pString );
  309. private:
  310. //void DrawRenderCharInternal( const FontCharRenderInfo& info );
  311. void DrawRenderCharInternal( const FontCharRenderInfo& info );
  312. private:
  313. enum { BASE_HEIGHT = 480, BASE_WIDTH = 640 };
  314. struct PaintState_t
  315. {
  316. vgui::VPANEL m_pPanel;
  317. int m_iTranslateX;
  318. int m_iTranslateY;
  319. int m_iScissorLeft;
  320. int m_iScissorRight;
  321. int m_iScissorTop;
  322. int m_iScissorBottom;
  323. };
  324. // material Setting method
  325. void InternalSetMaterial( IMaterial *material = NULL );
  326. // Draws the fullscreen buffer into the panel
  327. void DrawFullScreenBuffer( int nLeft, int nTop, int nRight, int nBottom, int nOffscreenWidth, int nOffscreenHeight, bool bIgnoreAlphaWhenCompositing );
  328. // Helper method to initialize vertices (transforms them into screen space too)
  329. void InitVertex( Vertex_t &vertex, int x, int y, float u, float v );
  330. // Draws a quad + quad array
  331. void DrawQuad( const Vertex_t &ul, const Vertex_t &lr, unsigned char *pColor );
  332. void DrawQuadArray( int numQuads, Vertex_t *pVerts, unsigned char *pColor, bool bShouldClip = true );
  333. // Necessary to wrap the rendering
  334. void StartDrawing( void );
  335. void StartDrawingIn3DSpace( const VMatrix &screenToWorld, int pw, int ph, float sw, float sh );
  336. void FinishDrawing( void );
  337. // Sets up a particular painting state...
  338. void SetupPaintState( const PaintState_t &paintState );
  339. void ResetPopupList();
  340. void AddPopup( vgui::VPANEL panel );
  341. void RemovePopup( vgui::VPANEL panel );
  342. void AddPopupsToList( vgui::VPANEL panel );
  343. // Helper for drawing colored text
  344. void DrawColoredText( vgui::HFont font, int x, int y, int r, int g, int b, int a, const char *fmt, va_list argptr );
  345. void SearchForWordBreak( vgui::HFont font, char *text, int& chars, int& pixels );
  346. void InternalThinkTraverse(VPANEL panel);
  347. void InternalSolveTraverse(VPANEL panel);
  348. void InternalSchemeSettingsTraverse(VPANEL panel, bool forceApplySchemeSettings);
  349. // handles mouse movement
  350. void SetCursorPos(int x, int y);
  351. void GetCursorPos(int &x, int &y);
  352. void DrawTexturedLineInternal( const Vertex_t &a, const Vertex_t &b );
  353. // Gets texture coordinates for drawing the full screen buffer
  354. void GetFullScreenTexCoords( int x, int y, int w, int h, float *pMinU, float *pMinV, float *pMaxU, float *pMaxV );
  355. // Is a panel under the restricted panel?
  356. bool IsPanelUnderRestrictedPanel( VPANEL panel );
  357. // Returns the attached window
  358. PlatWindow_t GetAttachedWindow() const;
  359. void ReloadSchemes();
  360. // Point Translation for current panel
  361. int m_nTranslateX;
  362. int m_nTranslateY;
  363. // alpha multiplier for current panel [0..1]
  364. float m_flAlphaMultiplier;
  365. // the apparent depth we should draw the current object at.
  366. // values <= STEREO_NOOP will be ignored, other values will scale by a matrix
  367. float m_flApparentDepth;
  368. // The size of the window to draw into
  369. int m_pSurfaceExtents[4];
  370. // Color for drawing all non-text things
  371. unsigned char m_DrawColor[4];
  372. // Color for drawing text
  373. unsigned char m_DrawTextColor[4];
  374. // Location of text rendering
  375. int m_pDrawTextPos[2];
  376. // Meshbuilder used for drawing
  377. IMesh* m_pMesh;
  378. CMeshBuilder meshBuilder;
  379. // White material used for drawing non-textured things
  380. CMaterialReference m_pWhite;
  381. // Used for 3D-rendered images
  382. CTextureReference m_FullScreenBuffer;
  383. CMaterialReference m_FullScreenBufferMaterial;
  384. CMaterialReference m_FullScreenBufferMaterialIgnoreAlpha;
  385. int m_nFullScreenBufferMaterialId;
  386. int m_nFullScreenBufferMaterialIgnoreAlphaId;
  387. CUtlString m_FullScreenBufferName;
  388. bool m_bUsingTempFullScreenBufferMaterial;
  389. bool m_bRestrictedPanelOverrodeAppModalPanel;
  390. // Root panel
  391. vgui::VPANEL m_pEmbeddedPanel;
  392. vgui::Panel *m_pDefaultEmbeddedPanel;
  393. vgui::VPANEL m_pRestrictedPanel;
  394. // List of pop-up panels based on the type enum above (draw order vs last clicked)
  395. CUtlVector<VPANEL> m_PopupList;
  396. // Stack of paint state...
  397. CUtlVector< PaintState_t > m_PaintStateStack;
  398. CUtlVector<HtmlWindow *> _htmlWindows;
  399. vgui::HFont m_hCurrentFont;
  400. vgui::HCursor _currentCursor;
  401. // The input context for cursor control
  402. InputContextHandle_t m_hInputContext;
  403. // The currently bound texture
  404. int m_iBoundTexture;
  405. // font drawing batching code
  406. enum { MAX_BATCHED_CHAR_VERTS = 4096 };
  407. Vertex_t m_BatchedCharVerts[ MAX_BATCHED_CHAR_VERTS ];
  408. int m_nBatchedCharVertCount;
  409. // What's the rectangle we're drawing in 3D paint mode?
  410. int m_n3DLeft, m_n3DRight, m_n3DTop, m_n3DBottom;
  411. int m_n3DViewportWidth, m_n3DViewportHeight;
  412. // Curr stencil value
  413. int m_nCurrReferenceValue;
  414. // Are we painting in 3D? (namely drawing 3D objects *inside* the vgui panel)
  415. bool m_bIn3DPaintMode : 1;
  416. // Are we drawing the vgui panel in the 3D world somewhere?
  417. bool m_bDrawingIn3DWorld : 1;
  418. // Is the app gonna call HandleInputEvent?
  419. bool m_bAppDrivesInput : 1;
  420. // Are we currently in the think() loop
  421. bool m_bInThink : 1;
  422. bool m_bNeedsKeyboard : 1;
  423. bool m_bNeedsMouse : 1;
  424. bool m_bAllowJavaScript : 1;
  425. bool m_bEnableInput : 1;
  426. int m_nLastInputPollCount;
  427. VPANEL m_CurrentThinkPanel;
  428. // Installed function to play sounds
  429. PlaySoundFunc_t m_PlaySoundFunc;
  430. int m_WorkSpaceInsets[4];
  431. class TitleEntry
  432. {
  433. public:
  434. TitleEntry()
  435. {
  436. panel = NULL;
  437. title[0] = 0;
  438. }
  439. vgui::VPANEL panel;
  440. wchar_t title[128];
  441. };
  442. CUtlVector< TitleEntry > m_Titles;
  443. CUtlVector< CUtlSymbol > m_CustomFontFileNames;
  444. CUtlVector< CUtlSymbol > m_BitmapFontFileNames;
  445. CUtlDict< int, int > m_BitmapFontFileMapping;
  446. float m_flZPos;
  447. CUtlDict< vgui::IImage *, unsigned short > m_FileTypeImages;
  448. int GetTitleEntry( vgui::VPANEL panel );
  449. virtual void DrawSetTextureRGBAEx( int id, const unsigned char *rgba, int wide, int tall, ImageFormat format );
  450. struct ScreenOverride_t
  451. {
  452. ScreenOverride_t() : m_bActive( false )
  453. {
  454. m_nValue[ 0 ] = m_nValue[ 1 ] = 0;
  455. }
  456. bool m_bActive;
  457. int m_nValue[ 2 ];
  458. };
  459. ScreenOverride_t m_ScreenSizeOverride;
  460. ScreenOverride_t m_ScreenPosOverride;
  461. struct ContextAbsPos_t
  462. {
  463. ContextAbsPos_t() : id( -1 )
  464. {
  465. m_nPos[ 0 ] = m_nPos[ 1 ] = 0;
  466. }
  467. static bool Less( const ContextAbsPos_t &lhs, const ContextAbsPos_t &rhs )
  468. {
  469. return lhs.id < rhs.id;
  470. }
  471. int id;
  472. int m_nPos[ 2 ];
  473. };
  474. CUtlRBTree< ContextAbsPos_t > m_ContextAbsPos;
  475. #ifdef LINUX
  476. struct font_entry
  477. {
  478. void *data;
  479. int size;
  480. };
  481. static CUtlDict< font_entry, unsigned short > m_FontData;
  482. static void *FontDataHelper( const char *pchFontName, int &size );
  483. #endif
  484. #if defined( PLATFORM_WINDOWS_PC )
  485. CUtlVector< HANDLE > m_CustomFontHandles;
  486. #endif
  487. };
  488. FORCEINLINE VPANEL CMatSystemSurface::GetPopup( int index )
  489. {
  490. return m_PopupList[ index ];
  491. }
  492. FORCEINLINE int CMatSystemSurface::GetPopupCount()
  493. {
  494. return m_PopupList.Count();
  495. }
  496. inline PlatWindow_t CMatSystemSurface::GetAttachedWindow() const
  497. {
  498. return g_pInputSystem->GetAttachedWindow();
  499. }
  500. inline InputContextHandle_t CMatSystemSurface::GetInputContext() const
  501. {
  502. Assert( m_hInputContext != INPUT_CONTEXT_HANDLE_INVALID );
  503. return m_hInputContext;
  504. }
  505. #if GLMDEBUG
  506. class MatSurfFuncLogger // rip off of GLMFuncLogger - figure out a way to reunify these soon
  507. {
  508. public:
  509. // simple function log
  510. MatSurfFuncLogger( char *funcName )
  511. {
  512. CMatRenderContextPtr prc( g_pMaterialSystem );
  513. m_funcName = funcName;
  514. m_earlyOut = false;
  515. prc->Printf( ">%s", m_funcName );
  516. };
  517. // more advanced version lets you pass args (i.e. called parameters or anything else of interest)
  518. // no macro for this one, since no easy way to pass through the args as well as the funcname
  519. MatSurfFuncLogger( char *funcName, char *fmt, ... )
  520. {
  521. CMatRenderContextPtr prc( g_pMaterialSystem );
  522. m_funcName = funcName;
  523. m_earlyOut = false;
  524. // this acts like GLMPrintf here
  525. // all the indent policy is down in GLMPrintfVA
  526. // which means we need to inject a ">" at the front of the format string to make this work... sigh.
  527. char modifiedFmt[2000];
  528. modifiedFmt[0] = '>';
  529. strcpy( modifiedFmt+1, fmt );
  530. va_list vargs;
  531. va_start(vargs, fmt);
  532. prc->PrintfVA( modifiedFmt, vargs );
  533. va_end( vargs );
  534. }
  535. ~MatSurfFuncLogger( )
  536. {
  537. CMatRenderContextPtr prc( g_pMaterialSystem );
  538. if (m_earlyOut)
  539. {
  540. prc->Printf( "<%s (early out)", m_funcName );
  541. }
  542. else
  543. {
  544. prc->Printf( "<%s", m_funcName );
  545. }
  546. };
  547. void EarlyOut( void )
  548. {
  549. m_earlyOut = true;
  550. };
  551. char *m_funcName; // set at construction time
  552. bool m_earlyOut;
  553. };
  554. // handy macro to go with the helper class
  555. #define MAT_FUNC MatSurfFuncLogger _logger_ ( __FUNCTION__ )
  556. #else
  557. #define MAT_FUNC
  558. #endif
  559. #endif // MATSYSTEMSURFACE_H