Skip to content

Commit cc97c5d

Browse files
committed
feat: Switch to RNDX for boxes, outlines and stuff
1 parent b314b30 commit cc97c5d

File tree

8 files changed

+442
-181
lines changed

8 files changed

+442
-181
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"GM"
44
],
55
"Lua.diagnostics.disable": [
6-
"duplicate-set-field"
6+
"duplicate-set-field",
7+
"undefined-field"
78
]
89
}
Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,18 @@
1-
local setDrawColor = surface.SetDrawColor
2-
local drawOutlinedRect = surface.DrawOutlinedRect
3-
local mathFloor = math.floor
4-
51
function PulsarUI.DrawOutlinedBox(x, y, w, h, thickness, col)
6-
setDrawColor(col.r, col.g, col.b, col.a)
7-
for i = 0, thickness - 1 do
8-
drawOutlinedRect(x + i, y + i, w - i * 2, h - i * 2)
9-
end
2+
PulsarUI.RNDX.DrawOutlined(0, x, y, w, h, col, thickness)
103
end
114

12-
function PulsarUI.DrawOutlinedRoundedBoxEx(borderSize, x, y, w, h, col, thickness, topLeft, topRight, bottomLeft,
13-
bottomRight)
14-
render.SetStencilPassOperation(STENCIL_KEEP)
15-
render.SetStencilEnable(true)
16-
render.ClearStencil()
17-
18-
render.SetStencilTestMask(255)
19-
render.SetStencilWriteMask(255)
20-
21-
render.SetStencilCompareFunction(STENCIL_NEVER)
22-
render.SetStencilFailOperation(STENCIL_REPLACE)
23-
24-
render.SetStencilReferenceValue(1)
25-
26-
render.PerformFullScreenStencilOperation()
5+
function PulsarUI.DrawOutlinedRoundedBoxEx(borderSize, x, y, w, h, col, thickness, tl, tr, bl, br)
6+
local flags = PulsarUI.RNDX.SHAPE_CIRCLE
277

28-
render.SetStencilReferenceValue(0)
8+
if tl == false then flags = flags + PulsarUI.RNDX.NO_TL end
9+
if tr == false then flags = flags + PulsarUI.RNDX.NO_TR end
10+
if bl == false then flags = flags + PulsarUI.RNDX.NO_BL end
11+
if br == false then flags = flags + PulsarUI.RNDX.NO_BR end
2912

30-
thickness = mathFloor(thickness)
31-
local halfThickness = mathFloor(thickness * 0.5)
32-
33-
PulsarUI.DrawFullRoundedBoxEx(borderSize, x + halfThickness, y + halfThickness, w - thickness, h - thickness, color_white, topLeft, topRight, bottomLeft,
34-
bottomRight)
35-
36-
render.SetStencilCompareFunction(STENCIL_NOTEQUAL)
37-
render.SetStencilFailOperation(STENCIL_KEEP)
38-
render.SetStencilPassOperation(STENCIL_KEEP)
39-
40-
PulsarUI.DrawFullRoundedBoxEx(borderSize, x, y, w, h, col, topLeft, topRight, bottomLeft, bottomRight)
41-
42-
render.SetStencilEnable(false)
13+
PulsarUI.RNDX.DrawOutlined(borderSize, x, y, w, h, col, thickness, flags)
4314
end
4415

4516
function PulsarUI.DrawOutlinedRoundedBox(borderSize, x, y, w, h, col, thickness)
4617
PulsarUI.DrawOutlinedRoundedBoxEx(borderSize, x, y, w, h, col, thickness, true, true, true, true)
47-
end
18+
end

lua/pulsarui/drawing/cl_rounded_box.lua

Lines changed: 8 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,21 @@
1-
local corners = {}
2-
3-
do
4-
local stupid_corners = {
5-
tex_corner8 = "gui/corner8",
6-
tex_corner16 = "gui/corner16",
7-
tex_corner32 = "gui/corner32",
8-
tex_corner64 = "gui/corner64",
9-
tex_corner512 = "gui/corner512"
10-
}
11-
12-
for k, v in next, stupid_corners do
13-
corners[k] = CreateMaterial("better_" .. v:gsub("gui/", ""), "UnlitGeneric", {
14-
["$basetexture"] = v,
15-
["$alphatest"] = 1,
16-
["$alphatestreference"] = 0.5,
17-
["$vertexalpha"] = 1,
18-
["$vertexcolor"] = 1
19-
})
20-
end
21-
end
22-
23-
local cornerTex8 = surface.GetTextureID("gui/corner8")
24-
local cornerTex16 = surface.GetTextureID("gui/corner16")
25-
local cornerTex32 = surface.GetTextureID("gui/corner32")
26-
local cornerTex64 = surface.GetTextureID("gui/corner64")
27-
local cornerTex512 = surface.GetTextureID("gui/corner512")
28-
29-
local round = math.Round
30-
local min = math.min
31-
local floor = math.floor
32-
local setDrawColor = surface.SetDrawColor
33-
local drawRect = surface.DrawRect
34-
local drawTexturedRectUV = surface.DrawTexturedRectUV
35-
local setTexture = surface.SetTexture
36-
local setMaterial = surface.SetMaterial
37-
381
function PulsarUI.DrawRoundedBoxEx(borderSize, x, y, w, h, col, topLeft, topRight, bottomLeft, bottomRight)
39-
setDrawColor(col.r, col.g, col.b, col.a)
40-
41-
if borderSize <= 0 then
42-
drawRect(x, y, w, h)
43-
return
44-
end
45-
46-
x = round(x)
47-
y = round(y)
48-
w = round(w)
49-
h = round(h)
50-
borderSize = min(round(borderSize), floor(w / 2))
51-
52-
drawRect(x + borderSize, y, w - borderSize * 2, h)
53-
drawRect(x, y + borderSize, borderSize, h - borderSize * 2)
54-
drawRect(x + w - borderSize, y + borderSize, borderSize, h - borderSize * 2)
55-
56-
local tex = cornerTex8
57-
if borderSize > 8 then tex = cornerTex16 end
58-
if borderSize > 16 then tex = cornerTex32 end
59-
if borderSize > 32 then tex = cornerTex64 end
60-
if borderSize > 64 then tex = cornerTex512 end
61-
62-
setTexture(tex)
63-
64-
if topLeft then
65-
drawTexturedRectUV(x, y, borderSize, borderSize, 0, 0, 1, 1)
66-
else
67-
drawRect(x, y, borderSize, borderSize)
68-
end
2+
return PulsarUI.DrawFullRoundedBoxEx(borderSize, x, y, w, h, col, topLeft, topRight, bottomLeft, bottomRight)
693

70-
if topRight then
71-
drawTexturedRectUV(x + w - borderSize, y, borderSize, borderSize, 1, 0, 0, 1)
72-
else
73-
drawRect(x + w - borderSize, y, borderSize, borderSize)
74-
end
75-
76-
if bottomLeft then
77-
drawTexturedRectUV(x, y + h -borderSize, borderSize, borderSize, 0, 1, 1, 0)
78-
else
79-
drawRect(x, y + h - borderSize, borderSize, borderSize)
80-
end
81-
82-
if bottomRight then
83-
drawTexturedRectUV(x + w - borderSize, y + h - borderSize, borderSize, borderSize, 1, 1, 0, 0)
84-
else
85-
drawRect(x + w - borderSize, y + h - borderSize, borderSize, borderSize)
86-
end
874
end
885

89-
local drawRoundedBoxEx = PulsarUI.DrawRoundedBoxEx
906
function PulsarUI.DrawRoundedBox(borderSize, x, y, w, h, col)
91-
return drawRoundedBoxEx(borderSize, x, y, w, h, col, true, true, true, true)
7+
return PulsarUI.DrawFullRoundedBoxEx(borderSize, x, y, w, h, col, true, true, true, true)
928
end
939

9410
function PulsarUI.DrawFullRoundedBoxEx(borderSize, x, y, w, h, col, tl, tr, bl, br)
95-
setDrawColor(col.r, col.g, col.b, col.a)
96-
97-
if borderSize <= 0 then
98-
drawRect(x, y, w, h)
99-
100-
return
101-
end
102-
103-
x, y, w, h = round(x), round(y), round(w), round(h)
104-
borderSize = min(round(borderSize), floor(w / 2))
105-
106-
local xAfterBorder, yAfterBorder = x + borderSize, y + borderSize
107-
local doubleHeightWithoutBorder = h - borderSize * 2
108-
local xPlusWidthWithoutBorder, yPlusHeightWithoutBorder = x + w - borderSize, y + h - borderSize
109-
110-
drawRect(xAfterBorder, y, w - borderSize * 2, h)
111-
drawRect(x, yAfterBorder, borderSize, doubleHeightWithoutBorder)
112-
drawRect(xPlusWidthWithoutBorder, yAfterBorder, borderSize, doubleHeightWithoutBorder)
113-
114-
local material = corners.tex_corner8
115-
if borderSize > 8 then material = corners.tex_corner16 end
116-
if borderSize > 16 then material = corners.tex_corner32 end
117-
if borderSize > 32 then material = corners.tex_corner64 end
118-
if borderSize > 64 then material = corners.tex_corner512 end
119-
120-
setMaterial(material)
121-
122-
if tl then
123-
drawTexturedRectUV(x, y, borderSize, borderSize, 0, 0, 1, 1)
124-
else
125-
drawRect(x, y, borderSize, borderSize)
126-
end
127-
128-
if tr then
129-
drawTexturedRectUV(xPlusWidthWithoutBorder, y, borderSize, borderSize, 1, 0, 0, 1)
130-
else
131-
drawRect(xPlusWidthWithoutBorder, y, borderSize, borderSize)
132-
end
11+
local flags = PulsarUI.RNDX.SHAPE_CIRCLE
13312

134-
if bl then
135-
drawTexturedRectUV(x, yPlusHeightWithoutBorder, borderSize, borderSize, 0, 1, 1, 0)
136-
else
137-
drawRect(x, yPlusHeightWithoutBorder, borderSize, borderSize)
138-
end
13+
if tl == false then flags = flags + PulsarUI.RNDX.NO_TL end
14+
if tr == false then flags = flags + PulsarUI.RNDX.NO_TR end
15+
if bl == false then flags = flags + PulsarUI.RNDX.NO_BL end
16+
if br == false then flags = flags + PulsarUI.RNDX.NO_BR end
13917

140-
if br then
141-
drawTexturedRectUV(xPlusWidthWithoutBorder, yPlusHeightWithoutBorder, borderSize, borderSize, 1, 1, 0, 0)
142-
else
143-
drawRect(xPlusWidthWithoutBorder, yPlusHeightWithoutBorder, borderSize, borderSize)
144-
end
18+
PulsarUI.RNDX.Draw(borderSize, x, y, w, h, col, flags)
14519
end
14620

14721
function PulsarUI.DrawFullRoundedBox(borderSize, x, y, w, h, col)

lua/pulsarui/elements/cl_avatar.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ end
3636
function PANEL:Paint(w, h)
3737
PulsarUI.Mask(
3838
function()
39-
PulsarUI.DrawFullRoundedBox(self:GetRounded(), 0, 0, w, h, color_white)
39+
PulsarUI.RNDX.Draw(self:GetRounded(), 0, 0, w, h, Color(255, 0, 0, 150), PulsarUI.RNDX.SHAPE_CIRCLE)
4040
end,
4141
function()
4242
self.Avatar:PaintManual()

lua/pulsarui/elements/cl_text_entry.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ function PANEL:Paint(w, h)
5050
col = self.OverrideCol
5151
end
5252

53-
self.OutlineColor = PulsarUI.LerpColor(FrameTime() * 8, self.OutlineColor, col)
53+
local col2 = PulsarUI.LerpColor(FrameTime() * 8, self.OutlineColor, col)
5454

5555
PulsarUI.DrawRoundedBox(6, 0, 0, w, h, self.InnerColor)
5656

57-
local screenX, screenY = self:LocalToScreen(0, 0)
58-
PulsarUI.paint.outlines.drawOutline(6, screenX, screenY, w, h, self.OutlineColor, nil, 2 )
57+
local flags = PulsarUI.RNDX.SHAPE_CIRCLE
58+
PulsarUI.RNDX.DrawOutlined(6, 0, 0, w, h, col, 2, flags)
5959

6060
if self:GetValue() == "" then
6161
PulsarUI.DrawSimpleText(self:GetPlaceholderText() or "", "UI.TextEntry", PulsarUI.Scale(10), h / 2, self.PlaceholderTextCol, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)

lua/pulsarui/elements/color_mixer/cl_rgb_picker.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function PANEL:Paint(w, h)
7979
local barH = h - PulsarUI.Scale(4)
8080

8181
PulsarUI.Mask(function()
82+
local flags = PulsarUI.RNDX.SHAPE_CIRCLE
8283
PulsarUI.DrawFullRoundedBox(barH / 2, 0, PulsarUI.Scale(2), w, barH, color_white)
8384
end,
8485
function()
@@ -96,9 +97,10 @@ function PANEL:Paint(w, h)
9697
newX = w - (h / 2)
9798
end
9899

99-
local screenX, screenY = self:LocalToScreen(newX - (h / 2), 1)
100-
PulsarUI.paint.roundedBoxes.roundedBox(h / 2, screenX, screenY, h, h, self:GetColor())
101-
PulsarUI.paint.outlines.drawOutline( h / 2, screenX, screenY, h, h, color_white, nil, 5 )
100+
local posX, posY = newX, h / 2 - 1
101+
local flags = PulsarUI.RNDX.SHAPE_CIRCLE
102+
PulsarUI.RNDX.DrawCircle(posX, posY, 24, self:GetColor(), flags)
103+
PulsarUI.RNDX.DrawCircleOutlined(posX, posY, 24, color_white, 4, flags)
102104
end
103105

104106
vgui.Register("PulsarUI.RGBPicker", PANEL, "EditablePanel")

lua/pulsarui/elements/color_mixer/cl_slider.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function PANEL:Init()
3737
self.KnobColor = color_white
3838

3939
self.Knob.Paint = function(panel, w, h)
40-
PulsarUI.DrawOutlinedRoundedBox(h / 2, 0, 0, h, h, self.KnobColor, 8)
40+
PulsarUI.DrawOutlinedRoundedBox(h / 2, 0, 0, h, h, self.KnobColor, 4)
4141
end
4242

4343
self.Knob.OnCursorMoved = function(panel, x, y)

0 commit comments

Comments
 (0)