Facepunch / garrysmod-requests

Feature requests for Garry's Mod
83 stars 24 forks source link

Get absolute panel position through the surface active panel stack #2406

Open WardenPotato opened 2 weeks ago

WardenPotato commented 2 weeks ago

Details

The goal is to get the absolute panel position to offset rendering functions relative towards the screens 0,0 position without having to pass references. Internally in the engine this is done through void CMatSystemSurface::PushMakeCurrent(VPANEL pPanel, bool useInSets) before calling functions like Paint() as seen in this snippet

https://github.com/lua9520/source-engine-2018-hl2_src/blob/master/vgui2/vgui_controls/Panel.cpp#L1209-L1211

        // draw the front of the panel with the inset
        if ( _flags.IsFlagSet( PAINT_ENABLED ) )
        {
            surface()->PushMakeCurrent( vpanel, true );
            Paint();
            surface()->PopMakeCurrent( vpanel );
        }

This is very similar to #2394 but would solve the issue of getting a panel reference out of thin air, it just scopes the usability to this stack being set, which would make almost no practical difference as its only intended to be used within Paint() functions to begin with.

After this stack is set it seems that surface calls in the engine happen as follows surface()->someRenderingFunction to which i assume surface() its g_pVGuiSurface return value goes back to the PushMakeCurrent stack.

robotboy655 commented 2 weeks ago

Related: https://github.com/Facepunch/garrysmod-requests/issues/2356

WardenPotato commented 2 weeks ago

To add onto my original post, the stack seems to calculate the following values and throws them into a PaintState

Calculated inset
Calculated Absolute position
Calculated scissor/clip rect
Corrected top left origin

Would be sweet to return all of those if they arent already as they all come from the same place surface.GetPaintState() maybe?