From 0be0932dc6ad27e277b9aa55893d3961b2205f2f Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Wed, 5 Feb 2025 23:14:57 +0100 Subject: [PATCH] improved rounded corner support --- .../gamemode/client/cl_vskin/default_skin.lua | 38 +++++++++++++--- .../client/cl_vskin/vgui/dlabel_ttt2.lua | 45 ++++++++++++++++--- 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua b/gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua index d162aa109..49939e207 100644 --- a/gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua +++ b/gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua @@ -166,27 +166,55 @@ end -- @ignore function SKIN:PaintColoredBox(panel, w, h) if panel:HasCornerRadius() then + local tl, tr, bl, br = panel:GetCornerRadius() + if panel:HasOutline() then local left, top, right, bottom = panel:GetOutline() - drawRoundedBox(sizes.cornerRadius, 0, 0, w, h, panel:GetVSkinColor("outline")) - drawRoundedBox( + drawRoundedBoxEx( + sizes.cornerRadius, + 0, + 0, + w, + h, + panel:GetVSkinColor("outline"), + tl, + tr, + bl, + br + ) + drawRoundedBoxEx( sizes.cornerRadius, left, top, w - left - right, h - top - bottom, - panel:GetVSkinColor("background") + panel:GetVSkinColor("background"), + tl, + tr, + bl, + br ) else - drawRoundedBox(sizes.cornerRadius, 0, 0, w, h, panel:GetVSkinColor("background")) + drawRoundedBoxEx( + sizes.cornerRadius, + 0, + 0, + w, + h, + panel:GetVSkinColor("background"), + tl, + tr, + bl, + br + ) end if panel:HasFlashColor() and panel:IsEnabled() then local colorFlash = panel:GetVSkinColor("flash") colorFlash.a = math.Round(15 * (math.sin((CurTime() % 2 - 1) * math.pi) + 1.1)) - drawRoundedBox(sizes.cornerRadius, 0, 0, w, h, colorFlash) + drawRoundedBoxEx(sizes.cornerRadius, 0, 0, w, h, colorFlash, tl, tr, bl, br) end else if panel:HasOutline() then diff --git a/gamemodes/terrortown/gamemode/client/cl_vskin/vgui/dlabel_ttt2.lua b/gamemodes/terrortown/gamemode/client/cl_vskin/vgui/dlabel_ttt2.lua index 9e9199623..47178335c 100644 --- a/gamemodes/terrortown/gamemode/client/cl_vskin/vgui/dlabel_ttt2.lua +++ b/gamemodes/terrortown/gamemode/client/cl_vskin/vgui/dlabel_ttt2.lua @@ -722,21 +722,52 @@ end -- Enables a corner radius. If set to false, the box is a normal rectange, if set to true, the -- box has rounded corners. -- @note Backgroun drawing has to be enabled. --- @param boolean state Set to true to enable corner radius +-- @param boolean ... Set to true to enable corner radius, can be either 1 or 4 parameters -- @return Panel Returns the panel itself -- @realm client -function PANEL:EnableCornerRadius(state) - self.m_bCornerRadius = state +function PANEL:EnableCornerRadius(...) + local state = { ... } + + if #state == 1 then + self.m_bCornerRadiusTopLeft = state[1] + self.m_bCornerRadiusTopRight = state[1] + self.m_bCornerRadiusBottomLeft = state[1] + self.m_bCornerRadiusBottomRight = state[1] + elseif #state == 4 then + self.m_bCornerRadiusTopLeft = state[1] + self.m_bCornerRadiusTopRight = state[2] + self.m_bCornerRadiusBottomLeft = state[3] + self.m_bCornerRadiusBottomRight = state[4] + else + ErrorNoHaltWithStack( + "[TTT2] PANEL:EnableCornerRadius expects 1 or 4 arguments, " + .. tostring(#sizes) + .. " were provided." + ) + end return self end --- --- Checks whether this panel has corner radius enabled. +-- Checks whether this panel has a simple (all corners are the same) corner radius enabled. -- @return boolean Returns true if the corner radius is enabled -- @realm client function PANEL:HasCornerRadius() - return self.m_bCornerRadius or false + return self.m_bCornerRadiusTopLeft or false +end + +--- +-- Returns a list of all four corners and if they have a defined radius. +-- @return boolean Corner radius state for the top left corner +-- @return boolean Corner radius state for the top right corner +-- @return boolean Corner radius state for the bottom left corner +-- @return boolean Corner radius state for the bottom right corner +function PANEL:GetCornerRadius() + return self.m_bCornerRadiusTopLeft or false, + self.m_bCornerRadiusTopRight or false, + self.m_bCornerRadiusBottomLeft or false, + self.m_bCornerRadiusBottomRight or false end --- @@ -771,7 +802,7 @@ function PANEL:SetOutline(...) self.m_nOutlineRight = sizes[3] self.m_nOutlineBottom = sizes[4] else - error( + ErrorNoHaltWithStack( "[TTT2] PANEL:SetOutline expects 1, 2 or 4 arguments, " .. tostring(#sizes) .. " were provided." @@ -832,7 +863,7 @@ function PANEL:SetPadding(...) self.m_nPaddingRight = padding[3] self.m_nPaddingBottom = padding[4] else - error( + ErrorNoHaltWithStack( "[TTT2] PANEL:SetPadding expects 1, 2 or 4 arguments, " .. tostring(#padding) .. " were provided."