micro-optimize background poly to only update when size changes
This commit is contained in:
parent
3d10c63702
commit
10e902ddcf
1 changed files with 17 additions and 5 deletions
|
@ -99,9 +99,11 @@ local function add_rounded_poly(poly, x, y, rad, seg, offset)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function RoundedBoxPoly(x, y, w, h, rad, seg)
|
local function RoundedBoxPoly(w, h, rad, seg)
|
||||||
local poly = {}
|
local poly = {}
|
||||||
|
|
||||||
|
local x, y = 0, 0
|
||||||
|
|
||||||
add_rounded_poly(poly, x + rad, y + rad, rad, seg, seg)
|
add_rounded_poly(poly, x + rad, y + rad, rad, seg, seg)
|
||||||
|
|
||||||
poly[#poly + 1] = {
|
poly[#poly + 1] = {
|
||||||
|
@ -131,9 +133,11 @@ local function RoundedBoxPoly(x, y, w, h, rad, seg)
|
||||||
|
|
||||||
add_rounded_poly(poly, x + rad, y + (h - rad), rad, seg)
|
add_rounded_poly(poly, x + rad, y + (h - rad), rad, seg)
|
||||||
|
|
||||||
surface_DrawPoly(poly)
|
return poly
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local PREV_W, PREV_H, BACKGROUND_POLY
|
||||||
|
|
||||||
local function CreateChatbox()
|
local function CreateChatbox()
|
||||||
if IsValid(cbox.chatbox.panels.frame) then
|
if IsValid(cbox.chatbox.panels.frame) then
|
||||||
cbox.chatbox.panels.frame:Remove()
|
cbox.chatbox.panels.frame:Remove()
|
||||||
|
@ -150,7 +154,7 @@ local function CreateChatbox()
|
||||||
|
|
||||||
-- TODO: make this configurable
|
-- TODO: make this configurable
|
||||||
frame:SetMinWidth(dw)
|
frame:SetMinWidth(dw)
|
||||||
frame:SetMinWidth(dh)
|
frame:SetMinHeight(dh)
|
||||||
|
|
||||||
local x = frame:GetCookie("pos_x", dx)
|
local x = frame:GetCookie("pos_x", dx)
|
||||||
local y = frame:GetCookie("pos_y", dy)
|
local y = frame:GetCookie("pos_y", dy)
|
||||||
|
@ -158,6 +162,9 @@ local function CreateChatbox()
|
||||||
local h = frame:GetCookie("height", dh)
|
local h = frame:GetCookie("height", dh)
|
||||||
frame:SetPos(x, y)
|
frame:SetPos(x, y)
|
||||||
frame:SetSize(w, h)
|
frame:SetSize(w, h)
|
||||||
|
PREV_W = w
|
||||||
|
PREV_H = h
|
||||||
|
BACKGROUND_POLY = RoundedBoxPoly(w, h, 8, 24)
|
||||||
|
|
||||||
frame:SetVisible(false)
|
frame:SetVisible(false)
|
||||||
|
|
||||||
|
@ -197,7 +204,12 @@ local function CreateChatbox()
|
||||||
|
|
||||||
self.animFade:Run()
|
self.animFade:Run()
|
||||||
|
|
||||||
-- TODO: save position and size
|
local w, h = self:GetSize()
|
||||||
|
if w ~= PREV_W or h ~= PREV_H then
|
||||||
|
PREV_W = w
|
||||||
|
PREV_H = h
|
||||||
|
BACKGROUND_POLY = RoundedBoxPoly(w, h, 8, 24)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function frame:Paint(w, h)
|
function frame:Paint(w, h)
|
||||||
|
@ -220,7 +232,7 @@ local function CreateChatbox()
|
||||||
|
|
||||||
draw_NoTexture()
|
draw_NoTexture()
|
||||||
surface_SetDrawColor(255, 255, 255)
|
surface_SetDrawColor(255, 255, 255)
|
||||||
RoundedBoxPoly(0, 0, w, h, 8, 24)
|
surface_DrawPoly(BACKGROUND_POLY)
|
||||||
|
|
||||||
-- Only draw things that are in the stencil buffer
|
-- Only draw things that are in the stencil buffer
|
||||||
render_SetStencilCompareFunction( STENCIL_EQUAL )
|
render_SetStencilCompareFunction( STENCIL_EQUAL )
|
||||||
|
|
Loading…
Reference in a new issue