Advertisement
Phyksar

ISurface.h for GMod

Oct 12th, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.84 KB | None | 0 0
  1. /*  Information:
  2.     This header should be used with GMod .dll modules to
  3.     prevent crashes when calling ISurface methods.
  4.     Original header was taken from Source SKD 2013
  5.    
  6.     If you are expecting chashes even with this header,
  7.     try to move around this block (line 268):
  8.    
  9.         // GMod stuff to fix misaligned header
  10.         virtual bool Connect(CreateInterfaceFn* factory);
  11.         virtual void Disconnect();
  12.         virtual void* QueryInterface(const char *pInterfaceName);
  13.         virtual InitReturnVal_t Init();
  14. */ 
  15.  
  16. //========= Copyright Valve Corporation, All rights reserved. ============//
  17. //
  18. // Purpose:
  19. //
  20. // $NoKeywords: $
  21. //===========================================================================//
  22.  
  23. #ifndef ISURFACE_H
  24. #define ISURFACE_H
  25.  
  26. #ifdef _WIN32
  27. #pragma once
  28. #endif
  29.  
  30. #include <vgui/VGUI.h>
  31. #include <vgui/IHTML.h> // CreateHTML, PaintHTML
  32. #include "tier1/interface.h"
  33. #include "bitmap/imageformat.h"
  34.  
  35. #include "appframework/IAppSystem.h"
  36. #include "mathlib/vector2d.h"  // must be before the namespace line
  37.  
  38. #include "IVguiMatInfo.h"
  39.  
  40. #ifdef CreateFont
  41. #undef CreateFont
  42. #endif
  43.  
  44. #ifdef PlaySound
  45. #undef PlaySound
  46. #endif
  47.  
  48. class Color;
  49. class ITexture;
  50.  
  51. namespace vgui
  52. {
  53.  
  54. class IImage;
  55. class Image;
  56. class Point;
  57.  
  58. // handles
  59. typedef unsigned long HCursor;
  60. typedef unsigned long HTexture;
  61. typedef unsigned long HFont;
  62.  
  63.  
  64. //SRC only defines
  65.  
  66.  
  67. struct Vertex_t
  68. {
  69.     Vertex_t() {}
  70.     Vertex_t( const Vector2D &pos, const Vector2D &coord = Vector2D( 0, 0 ) )
  71.     {
  72.         m_Position = pos;
  73.         m_TexCoord = coord;
  74.     }
  75.     void Init( const Vector2D &pos, const Vector2D &coord = Vector2D( 0, 0 ) )
  76.     {
  77.         m_Position = pos;
  78.         m_TexCoord = coord;
  79.     }
  80.    
  81.     Vector2D    m_Position;
  82.     Vector2D    m_TexCoord;
  83. };
  84.  
  85.  
  86. enum FontDrawType_t
  87. {
  88.     // Use the "additive" value from the scheme file
  89.     FONT_DRAW_DEFAULT = 0,
  90.  
  91.     // Overrides
  92.     FONT_DRAW_NONADDITIVE,
  93.     FONT_DRAW_ADDITIVE,
  94.  
  95.     FONT_DRAW_TYPE_COUNT = 2,
  96. };
  97.  
  98.  
  99. // Refactor these two
  100. struct CharRenderInfo
  101. {
  102.     // Text pos
  103.     int             x, y;
  104.     // Top left and bottom right
  105.     // This is now a pointer to an array maintained by the surface, to avoid copying the data on the 360
  106.     Vertex_t        *verts;
  107.     int             textureId;
  108.     int             abcA;
  109.     int             abcB;
  110.     int             abcC;
  111.     int             fontTall;
  112.     HFont           currentFont;
  113.     // In:
  114.     FontDrawType_t  drawType;
  115.     wchar_t         ch;
  116.  
  117.     // Out
  118.     bool            valid;
  119.     // In/Out (true by default)
  120.     bool            shouldclip;
  121. };
  122.  
  123.  
  124. struct IntRect
  125. {
  126.     int x0;
  127.     int y0;
  128.     int x1;
  129.     int y1;
  130. };
  131.  
  132. //-----------------------------------------------------------------------------
  133. // Purpose: Wraps contextless windows system functions
  134. //-----------------------------------------------------------------------------
  135. class ISurface : public IAppSystem
  136. {
  137. public:
  138.     // call to Shutdown surface; surface can no longer be used after this is called
  139.     virtual void Shutdown() = 0;
  140.  
  141.     // frame
  142.     virtual void RunFrame() = 0;
  143.  
  144.     // hierarchy root
  145.     virtual VPANEL GetEmbeddedPanel() = 0;
  146.     virtual void SetEmbeddedPanel( VPANEL pPanel ) = 0;
  147.  
  148.     // drawing context
  149.     virtual void PushMakeCurrent(VPANEL panel, bool useInsets) = 0;
  150.     virtual void PopMakeCurrent(VPANEL panel) = 0;
  151.  
  152.     // rendering functions
  153.     virtual void DrawSetColor(int r, int g, int b, int a) = 0;
  154.     virtual void DrawSetColor(Color col) = 0;
  155.    
  156.     virtual void DrawFilledRect(int x0, int y0, int x1, int y1) = 0;
  157.     virtual void DrawFilledRectArray( IntRect *pRects, int numRects ) = 0;
  158.     virtual void DrawOutlinedRect(int x0, int y0, int x1, int y1) = 0;
  159.  
  160.     virtual void DrawLine(int x0, int y0, int x1, int y1) = 0;
  161.     virtual void DrawPolyLine(int *px, int *py, int numPoints) = 0;
  162.  
  163.     virtual void DrawSetTextFont(HFont font) = 0;
  164.     virtual void DrawSetTextColor(int r, int g, int b, int a) = 0;
  165.     virtual void DrawSetTextColor(Color col) = 0;
  166.     virtual void DrawSetTextPos(int x, int y) = 0;
  167.     virtual void DrawGetTextPos(int& x,int& y) = 0;
  168.     virtual void DrawPrintText(const wchar_t *text, int textLen, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  169.     virtual void DrawUnicodeChar(wchar_t wch, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  170.  
  171.     virtual void DrawFlushText() = 0;       // flushes any buffered text (for rendering optimizations)
  172.     virtual IHTML *CreateHTMLWindow(vgui::IHTMLEvents *events,VPANEL context)=0;
  173.     virtual void PaintHTMLWindow(vgui::IHTML *htmlwin) =0;
  174.     virtual void DeleteHTMLWindow(IHTML *htmlwin)=0;
  175.  
  176.     enum ETextureFormat
  177.     {
  178.         eTextureFormat_RGBA,
  179.         eTextureFormat_BGRA,
  180.         eTextureFormat_BGRA_Opaque, // bgra format but alpha is always 255, CEF does this, we can use this fact for better perf on win32 gdi
  181.     };
  182.  
  183.     virtual int  DrawGetTextureId( char const *filename ) = 0;
  184.     virtual bool DrawGetTextureFile(int id, char *filename, int maxlen ) = 0;
  185.     virtual void DrawSetTextureFile(int id, const char *filename, int hardwareFilter, bool forceReload) = 0;
  186.     virtual void DrawSetTextureRGBA(int id, const unsigned char *rgba, int wide, int tall, int hardwareFilter, bool forceReload)=0;
  187.     virtual void DrawSetTexture(int id) = 0;
  188.     virtual void DrawGetTextureSize(int id, int &wide, int &tall) = 0;
  189.     virtual void DrawTexturedRect(int x0, int y0, int x1, int y1) = 0;
  190.     virtual bool IsTextureIDValid(int id) = 0;
  191.     virtual void DeleteTextureByID(int id) = 0;
  192.  
  193.     virtual int CreateNewTextureID( bool procedural = false ) = 0;
  194.  
  195.     virtual void GetScreenSize(int &wide, int &tall) = 0;
  196.     virtual void SetAsTopMost(VPANEL panel, bool state) = 0;
  197.     virtual void BringToFront(VPANEL panel) = 0;
  198.     virtual void SetForegroundWindow (VPANEL panel) = 0;
  199.     virtual void SetPanelVisible(VPANEL panel, bool state) = 0;
  200.     virtual void SetMinimized(VPANEL panel, bool state) = 0;
  201.     virtual bool IsMinimized(VPANEL panel) = 0;
  202.     virtual void FlashWindow(VPANEL panel, bool state) = 0;
  203.     virtual void SetTitle(VPANEL panel, const wchar_t *title) = 0;
  204.     virtual void SetAsToolBar(VPANEL panel, bool state) = 0;        // removes the window's task bar entry (for context menu's, etc.)
  205.  
  206.     // windows stuff
  207.     virtual void CreatePopup(VPANEL panel, bool minimised, bool showTaskbarIcon = true, bool disabled = false, bool mouseInput = true , bool kbInput = true) = 0;
  208.     virtual void SwapBuffers(VPANEL panel) = 0;
  209.     virtual void Invalidate(VPANEL panel) = 0;
  210.     virtual void SetCursor(HCursor cursor) = 0;
  211.     virtual void SetCursorAlwaysVisible( bool visible ) = 0;
  212.     virtual bool IsCursorVisible() = 0;
  213.     virtual void ApplyChanges() = 0;
  214.     virtual bool IsWithin(int x, int y) = 0;
  215.     virtual bool HasFocus() = 0;
  216.    
  217.     // returns true if the surface supports minimize & maximize capabilities
  218.     enum SurfaceFeature_e
  219.     {
  220.         ANTIALIASED_FONTS   = 1,
  221.         DROPSHADOW_FONTS    = 2,
  222.         ESCAPE_KEY          = 3,
  223.         OPENING_NEW_HTML_WINDOWS = 4,
  224.         FRAME_MINIMIZE_MAXIMIZE  = 5,
  225.         OUTLINE_FONTS   = 6,
  226.         DIRECT_HWND_RENDER      = 7,
  227.     };
  228.     virtual bool SupportsFeature(SurfaceFeature_e feature) = 0;
  229.  
  230.     // restricts what gets drawn to one panel and it's children
  231.     // currently only works in the game
  232.     virtual void RestrictPaintToSinglePanel(VPANEL panel) = 0;
  233.  
  234.     // these two functions obselete, use IInput::SetAppModalSurface() instead
  235.     virtual void SetModalPanel(VPANEL ) = 0;
  236.     virtual VPANEL GetModalPanel() = 0;
  237.  
  238.     virtual void UnlockCursor() = 0;
  239.     virtual void LockCursor() = 0;
  240.     virtual void SetTranslateExtendedKeys(bool state) = 0;
  241.     virtual VPANEL GetTopmostPopup() = 0;
  242.  
  243.     // engine-only focus handling (replacing WM_FOCUS windows handling)
  244.     virtual void SetTopLevelFocus(VPANEL panel) = 0;
  245.  
  246.     // fonts
  247.     // creates an empty handle to a vgui font.  windows fonts can be add to this via SetFontGlyphSet().
  248.     virtual HFont CreateFont() = 0;
  249.  
  250.     // adds to the font
  251.     enum EFontFlags
  252.     {
  253.         FONTFLAG_NONE,
  254.         FONTFLAG_ITALIC         = 0x001,
  255.         FONTFLAG_UNDERLINE      = 0x002,
  256.         FONTFLAG_STRIKEOUT      = 0x004,
  257.         FONTFLAG_SYMBOL         = 0x008,
  258.         FONTFLAG_ANTIALIAS      = 0x010,
  259.         FONTFLAG_GAUSSIANBLUR   = 0x020,
  260.         FONTFLAG_ROTARY         = 0x040,
  261.         FONTFLAG_DROPSHADOW     = 0x080,
  262.         FONTFLAG_ADDITIVE       = 0x100,
  263.         FONTFLAG_OUTLINE        = 0x200,
  264.         FONTFLAG_CUSTOM         = 0x400,        // custom generated font - never fall back to asian compatibility mode
  265.         FONTFLAG_BITMAP         = 0x800,        // compiled bitmap font - no fallbacks
  266.     };
  267.  
  268.     // GMod stuff to fix misaligned header
  269.     virtual bool Connect(CreateInterfaceFn* factory);
  270.     virtual void Disconnect();
  271.     virtual void* QueryInterface(const char *pInterfaceName);
  272.     virtual InitReturnVal_t Init();
  273.    
  274.     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;
  275.  
  276.     // adds a custom font file (only supports true type font files (.ttf) for now)
  277.     virtual bool AddCustomFontFile(const char *fontFileName) = 0;
  278.  
  279.     // returns the details about the font
  280.     virtual int GetFontTall(HFont font) = 0;
  281.     virtual int GetFontTallRequested(HFont font) = 0;
  282.     virtual int GetFontAscent(HFont font, wchar_t wch) = 0;
  283.     virtual bool IsFontAdditive(HFont font) = 0;
  284.     virtual void GetCharABCwide(HFont font, int ch, int &a, int &b, int &c) = 0;
  285.     virtual int GetCharacterWidth(HFont font, int ch) = 0;
  286.     virtual void GetTextSize(HFont font, const wchar_t *text, int &wide, int &tall) = 0;
  287.  
  288.     // notify icons?!?
  289.     virtual VPANEL GetNotifyPanel() = 0;
  290.     virtual void SetNotifyIcon(VPANEL context, HTexture icon, VPANEL panelToReceiveMessages, const char *text) = 0;
  291.  
  292.     // plays a sound
  293.     virtual void PlaySound(const char *fileName) = 0;
  294.  
  295.     //!! these functions should not be accessed directly, but only through other vgui items
  296.     //!! need to move these to seperate interface
  297.     virtual int GetPopupCount() = 0;
  298.     virtual VPANEL GetPopup(int index) = 0;
  299.     virtual bool ShouldPaintChildPanel(VPANEL childPanel) = 0;
  300.     virtual bool RecreateContext(VPANEL panel) = 0;
  301.     virtual void AddPanel(VPANEL panel) = 0;
  302.     virtual void ReleasePanel(VPANEL panel) = 0;
  303.     virtual void MovePopupToFront(VPANEL panel) = 0;
  304.     virtual void MovePopupToBack(VPANEL panel) = 0;
  305.  
  306.     virtual void SolveTraverse(VPANEL panel, bool forceApplySchemeSettings = false) = 0;
  307.     virtual void PaintTraverse(VPANEL panel) = 0;
  308.  
  309.     virtual void EnableMouseCapture(VPANEL panel, bool state) = 0;
  310.  
  311.     // returns the size of the workspace
  312.     virtual void GetWorkspaceBounds(int &x, int &y, int &wide, int &tall) = 0;
  313.  
  314.     // gets the absolute coordinates of the screen (in windows space)
  315.     virtual void GetAbsoluteWindowBounds(int &x, int &y, int &wide, int &tall) = 0;
  316.  
  317.     // gets the base resolution used in proportional mode
  318.     virtual void GetProportionalBase( int &width, int &height ) = 0;
  319.  
  320.     virtual void CalculateMouseVisible() = 0;
  321.     virtual bool NeedKBInput() = 0;
  322.  
  323.     virtual bool HasCursorPosFunctions() = 0;
  324.     virtual void SurfaceGetCursorPos(int &x, int &y) = 0;
  325.     virtual void SurfaceSetCursorPos(int x, int y) = 0;
  326.  
  327.     // SRC only functions!!!
  328.     virtual void DrawTexturedLine( const Vertex_t &a, const Vertex_t &b ) = 0;
  329.     virtual void DrawOutlinedCircle(int x, int y, int radius, int segments) = 0;
  330.     virtual void DrawTexturedPolyLine( const Vertex_t *p,int n ) = 0; // (Note: this connects the first and last points).
  331.     virtual void DrawTexturedSubRect( int x0, int y0, int x1, int y1, float texs0, float text0, float texs1, float text1 ) = 0;
  332.     virtual void DrawTexturedPolygon(int n, Vertex_t *pVertice, bool bClipVertices = true ) = 0;
  333.     virtual const wchar_t *GetTitle(VPANEL panel) = 0;
  334.     virtual bool IsCursorLocked( void ) const = 0;
  335.     virtual void SetWorkspaceInsets( int left, int top, int right, int bottom ) = 0;
  336.  
  337.     // Lower level char drawing code, call DrawGet then pass in info to DrawRender
  338.     virtual bool DrawGetUnicodeCharRenderInfo( wchar_t ch, CharRenderInfo& info ) = 0;
  339.     virtual void DrawRenderCharFromInfo( const CharRenderInfo& info ) = 0;
  340.  
  341.     // global alpha setting functions
  342.     // affect all subsequent draw calls - shouldn't normally be used directly, only in Panel::PaintTraverse()
  343.     virtual void DrawSetAlphaMultiplier( float alpha /* [0..1] */ ) = 0;
  344.     virtual float DrawGetAlphaMultiplier() = 0;
  345.  
  346.     // web browser
  347.     virtual void SetAllowHTMLJavaScript( bool state ) = 0;
  348.  
  349.     // video mode changing
  350.     virtual void OnScreenSizeChanged( int nOldWidth, int nOldHeight ) = 0;
  351.  
  352.     virtual vgui::HCursor CreateCursorFromFile( char const *curOrAniFile, char const *pPathID = 0 ) = 0;
  353.  
  354.     // create IVguiMatInfo object ( IMaterial wrapper in VguiMatSurface, NULL in CWin32Surface )
  355.     virtual IVguiMatInfo *DrawGetTextureMatInfoFactory( int id ) = 0;
  356.  
  357.     virtual void PaintTraverseEx(VPANEL panel, bool paintPopups = false ) = 0;
  358.  
  359.     virtual float GetZPos() const = 0;
  360.  
  361.     // From the Xbox
  362.     virtual void SetPanelForInput( VPANEL vpanel ) = 0;
  363.     virtual void DrawFilledRectFastFade( int x0, int y0, int x1, int y1, int fadeStartPt, int fadeEndPt, unsigned int alpha0, unsigned int alpha1, bool bHorizontal ) = 0;
  364.     virtual void DrawFilledRectFade( int x0, int y0, int x1, int y1, unsigned int alpha0, unsigned int alpha1, bool bHorizontal ) = 0;
  365.     virtual void DrawSetTextureRGBAEx(int id, const unsigned char *rgba, int wide, int tall, ImageFormat imageFormat ) = 0;
  366.     virtual void DrawSetTextScale(float sx, float sy) = 0;
  367.     virtual bool SetBitmapFontGlyphSet(HFont font, const char *windowsFontName, float scalex, float scaley, int flags) = 0;
  368.     // adds a bitmap font file
  369.     virtual bool AddBitmapFontFile(const char *fontFileName) = 0;
  370.     // sets a symbol for the bitmap font
  371.     virtual void SetBitmapFontName( const char *pName, const char *pFontFilename ) = 0;
  372.     // gets the bitmap font filename
  373.     virtual const char *GetBitmapFontName( const char *pName ) = 0;
  374.     virtual void ClearTemporaryFontCache( void ) = 0;
  375.  
  376.     virtual IImage *GetIconImageForFullPath( char const *pFullPath ) = 0;
  377.     virtual void DrawUnicodeString( const wchar_t *pwString, FontDrawType_t drawType = FONT_DRAW_DEFAULT ) = 0;
  378.     virtual void PrecacheFontCharacters(HFont font, const wchar_t *pCharacters) = 0;
  379.     // Console-only.  Get the string to use for the current video mode for layout files.
  380.     virtual const char *GetResolutionKey( void ) const = 0;
  381.    
  382.     virtual const char *GetFontName( HFont font ) = 0;
  383.     virtual const char *GetFontFamilyName( HFont font ) = 0;
  384.     virtual void GetKernedCharWidth( HFont font, wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA ) = 0;
  385.  
  386.     virtual bool ForceScreenSizeOverride( bool bState, int wide, int tall ) = 0;
  387.     // LocalToScreen, ParentLocalToScreen fixups for explicit PaintTraverse calls on Panels not at 0, 0 position
  388.     virtual bool ForceScreenPosOffset( bool bState, int x, int y ) = 0;
  389.     virtual void OffsetAbsPos( int &x, int &y ) = 0;
  390.  
  391.  
  392.     // Causes fonts to get reloaded, etc.
  393.     virtual void ResetFontCaches() = 0;
  394.  
  395.     virtual int GetTextureNumFrames( int id ) = 0;
  396.     virtual void DrawSetTextureFrame( int id, int nFrame, unsigned int *pFrameCache ) = 0;
  397.     virtual bool IsScreenSizeOverrideActive( void ) = 0;
  398.     virtual bool IsScreenPosOverrideActive( void ) = 0;
  399.  
  400.     virtual void DestroyTextureID( int id ) = 0;
  401.  
  402.     virtual void DrawUpdateRegionTextureRGBA( int nTextureID, int x, int y, const unsigned char *pchData, int wide, int tall, ImageFormat imageFormat ) = 0;
  403.     virtual bool BHTMLWindowNeedsPaint(IHTML *htmlwin) = 0 ;
  404.  
  405.     virtual const char *GetWebkitHTMLUserAgentString() = 0;
  406.  
  407.     virtual void *Deprecated_AccessChromeHTMLController() = 0;
  408.  
  409.     // the origin of the viewport on the framebuffer (Which might not be 0,0 for stereo)
  410.     virtual void SetFullscreenViewport( int x, int y, int w, int h ) = 0; // this uses NULL for the render target.
  411.     virtual void GetFullscreenViewport( int & x, int & y, int & w, int & h ) = 0;
  412.     virtual void PushFullscreenViewport() = 0;
  413.     virtual void PopFullscreenViewport() = 0;
  414.  
  415.     // handles support for software cursors
  416.     virtual void SetSoftwareCursor( bool bUseSoftwareCursor ) = 0;
  417.     virtual void PaintSoftwareCursor() = 0;
  418.  
  419.  
  420.     // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  421.     // !! WARNING! YOU MUST NOT ADD YOUR NEW METHOD HERE OR YOU WILL BREAK MODS !!
  422.     // !! Add your new stuff to the bottom of IMatSystemSurface instead.        !!
  423.     // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  424. };
  425.  
  426. }
  427.  
  428. #define VGUI_SURFACE_INTERFACE_VERSION "VGUI_Surface030"
  429.  
  430. #endif // ISURFACE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement