DModelPanel Overflow

Hi,

Just wondering if there’s a way to fix this:

http://puu.sh/3vDeR.jpg

I was considering overlaying a panel, but noticed that is goes of of all Gui >.<

http://puu.sh/3vDiy.jpg

(If you don’t know what’s happening, the DModelPanel, is showing the contents even when like 1px of the actual panel is visible )

Thanks

-snip-

You detour the Paint function of the panel. First save the old Paint, then make a new one with some fancy stuff then use render.SetScissorRect() with your fancy arguments, then call the old paint then do render.SetScissorRect( 0, 0, 0, 0, false ).

Here’s example code:



concommand.Add("open", function()
	local f = vgui.Create("DFrame")
	f:SetSize(ScrW()/2, ScrH()/2)
	f:Center()
	f:MakePopup()
	
	local bdcontrolspanel = vgui.Create( "DPanelList", f  )
	bdcontrolspanel:EnableVerticalScrollbar( true )
	bdcontrolspanel:Dock( FILL )
	bdcontrolspanel:DockPadding( 30, 8, 8, 8 )
	
	for i=1, 20 do
	local mdl = vgui.Create( "DModelPanel" )
	mdl:SetModel( "models/error.mdl" )
	mdl:SetHeight( 100 )
	
	-- This is the fix
	local oldpaint = mdl.Paint
	function mdl:Paint()
		
		local pnl = self:GetParent():GetParent()
		local x2, y2 = pnl:LocalToScreen( 0, 0 )
		local w2, h2 = pnl:GetSize()
		render.SetScissorRect( x2, y2, x2 + w2, y2 + h2, true )

		oldpaint( self )
		
		render.SetScissorRect( 0, 0, 0, 0, false )

	end

	bdcontrolspanel:AddItem( mdl ) end
end)

Thanks, this worked a charm.

Quick question though, why is it necessary to disable the scissorrect after?

So it doesn’t cut everything else that is drawn.

Cheers, marking thread as solved now.

Hopefully it will help others out in the future.

Results:

http://puu.sh/3wbBM.jpg