• Why does my background panel draw ontop of other items?
    4 replies, posted
[img]https://dl.dropboxusercontent.com/u/14273442/ontop.png[/img] As you can see the black transparent background draws ontop of my chat messages, which is wrong. I don't know how to change the draw order, so I am asking for help. Here is the code. [code] // Main Panel local mainPanel = { } function mainPanel:Init() end function mainPanel:Paint( w, h ) local x = 0 local y = 0 //Draw the border if vars.main.drawborder then surface.SetDrawColor( colors.main.border ) surface.DrawOutlinedRect(x, y, w, h) x = x + 1 y = y + 1 w = w - 2 h = h - 2 end // Draw the background surface.SetDrawColor( colors.main.background ) surface.DrawRect(x, y, w, h) return true end vgui.Register ( "ChatBoxMainPanel", mainPanel, "EditablePanel") // Hooks function chatbox:HUDPaint() // Draw history at all times if HistoryEnabled then // these are the messages that should be ontop local height = vars.textoutput.height local width = vars.main.width * ScrW( ) local outputx = vars.main.padding + vars.main.marginx local outputy = ScrH( ) - vars.main.marginy - vars.main.padding - vars.textbar.height - vars.main.spacing - vars.textoutput.height chatbox:PaintTextOutput( outputx, outputy, width - 2*vars.main.padding, height, colors.textoutput ) end if Enabled then if DrawChat then //chatbox:PopulateHistory() local width = vars.main.width * ScrW( ) local height = vars.main.spacing + vars.textbar.height + vars.textoutput.height + vars.main.padding*2 local x = vars.main.marginx local y = ScrH( ) - vars.main.marginy - height // Create background and main panel main = vgui.Create("ChatBoxMainPanel") // that is the main panel that draws above the messages main:SetPos(x, y) main:SetSize(width, height) main:Show() local barx = vars.main.padding local bary = height - vars.main.padding - vars.textbar.height chatbox:PaintTextBar( barx, bary, width - 2*vars.main.padding, vars.textbar.height, colors.textbar, main ) // Creates a text entry parented to main DrawChat = false end end return true end [/code] The PaintTextOutput() function doesn't use any vgui objects, only surface and draw lib functions. [b]EDIT:[/b] The issue has been solved by replacing the main panel with generic drawing functions. Apparently the Panel:Paint gets called after HUDPaint hook and this is why it's always ontop.
I'm not sure if its the same for this as huds and such BUT if it is if you draw the background first it should fix the issue
[QUOTE=lilplayer1220;41884824]I'm not sure if its the same for this as huds and such BUT if it is if you draw the background first it should fix the issue[/QUOTE] This uses the HUD paint hook so should be the same as for huds. Let me try. [editline]19th August 2013[/editline] It didn't work.
HUDPaint will always draw behind panels.
[QUOTE=Loures;41885265]HUDPaint will always draw behind panels.[/QUOTE] So the only way to fix it is to not use any panels and use simple drawing?
Sorry, you need to Log In to post a reply to this thread.