|
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 | | - |
38 | 1 | 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) |
69 | 3 |
|
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 |
87 | 4 | end |
88 | 5 |
|
89 | | -local drawRoundedBoxEx = PulsarUI.DrawRoundedBoxEx |
90 | 6 | 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) |
92 | 8 | end |
93 | 9 |
|
94 | 10 | 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 |
133 | 12 |
|
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 |
139 | 17 |
|
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) |
145 | 19 | end |
146 | 20 |
|
147 | 21 | function PulsarUI.DrawFullRoundedBox(borderSize, x, y, w, h, col) |
|
0 commit comments