Skip to content

Commit

Permalink
improved rounded corner support
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGoll committed Feb 5, 2025
1 parent 03bfb3c commit 0be0932
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 12 deletions.
38 changes: 33 additions & 5 deletions gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 38 additions & 7 deletions gamemodes/terrortown/gamemode/client/cl_vskin/vgui/dlabel_ttt2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Check failure on line 766 in gamemodes/terrortown/gamemode/client/cl_vskin/vgui/dlabel_ttt2.lua

View workflow job for this annotation

GitHub Actions / doc-check

Missing essential param --> "Missing '@realm' in 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

---
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit 0be0932

Please sign in to comment.