1515 along with this program. If not, see <https://www.gnu.org/licenses/>.
1616--]]
1717
18- local cornerTex8 = surface .GetTextureID (" gui/corner8" )
19- local cornerTex16 = surface .GetTextureID (" gui/corner16" )
20- local cornerTex32 = surface .GetTextureID (" gui/corner32" )
21- local cornerTex64 = surface .GetTextureID (" gui/corner64" )
22- local cornerTex512 = surface .GetTextureID (" gui/corner512" )
18+ local RNDX_DRAW , RNDX_FLAG_TL , RNDX_FLAG_TR , RNDX_FLAG_BL , RNDX_FLAG_BR , RNDX_SHAPE_CIRCLE
2319
24- local round = math .Round
25- local min = math.min
26- local floor = math.floor
20+ local function DrawFullRoundedBoxEx (borderSize , x , y , w , h , col , tl , tr , bl , br )
21+ if not RNDX_DRAW then
22+ -- just in case this frame we still dont have it
23+ if not PIXEL .RNDX then return end
2724
28- local setDrawColor = surface .SetDrawColor
29- local drawRect = surface .DrawRect
30- local drawTexturedRectUV = surface .DrawTexturedRectUV
31- local setTexture = surface .SetTexture
25+ RNDX_DRAW = PIXEL .RNDX .Draw
26+ RNDX_FLAG_TL = PIXEL .RNDX .NO_TL
27+ RNDX_FLAG_TR = PIXEL .RNDX .NO_TR
28+ RNDX_FLAG_BL = PIXEL .RNDX .NO_BL
29+ RNDX_FLAG_BR = PIXEL .RNDX .NO_BR
30+ RNDX_SHAPE_CIRCLE = PIXEL .RNDX .SHAPE_CIRCLE
31+ end
3232
33- function PIXEL .DrawRoundedBoxEx (borderSize , x , y , w , h , col , topLeft , topRight , bottomLeft , bottomRight )
34- setDrawColor (col .r , col .g , col .b , col .a )
35-
36- if borderSize <= 0 then
37- drawRect (x , y , w , h )
38- return
39- end
40-
41- x = round (x )
42- y = round (y )
43- w = round (w )
44- h = round (h )
45- borderSize = min (round (borderSize ), floor (w / 2 ))
33+ local flags = RNDX_SHAPE_CIRCLE
4634
47- drawRect (x + borderSize , y , w - borderSize * 2 , h )
48- drawRect (x , y + borderSize , borderSize , h - borderSize * 2 )
49- drawRect (x + w - borderSize , y + borderSize , borderSize , h - borderSize * 2 )
35+ if tl == false then flags = flags + RNDX_FLAG_TL end
36+ if tr == false then flags = flags + RNDX_FLAG_TR end
37+ if bl == false then flags = flags + RNDX_FLAG_BL end
38+ if br == false then flags = flags + RNDX_FLAG_BR end
5039
51- local tex = cornerTex8
52- if borderSize > 8 then tex = cornerTex16 end
53- if borderSize > 16 then tex = cornerTex32 end
54- if borderSize > 32 then tex = cornerTex64 end
55- if borderSize > 64 then tex = cornerTex512 end
56-
57- setTexture (tex )
58-
59- if topLeft then
60- drawTexturedRectUV (x , y , borderSize , borderSize , 0 , 0 , 1 , 1 )
61- else
62- drawRect (x , y , borderSize , borderSize )
63- end
40+ RNDX_DRAW (borderSize , x , y , w , h , col , flags )
41+ end
6442
65- if topRight then
66- drawTexturedRectUV (x + w - borderSize , y , borderSize , borderSize , 1 , 0 , 0 , 1 )
67- else
68- drawRect (x + w - borderSize , y , borderSize , borderSize )
69- end
43+ PIXEL .DrawFullRoundedBoxEx = DrawFullRoundedBoxEx
7044
71- if bottomLeft then
72- drawTexturedRectUV (x , y + h - borderSize , borderSize , borderSize , 0 , 1 , 1 , 0 )
73- else
74- drawRect (x , y + h - borderSize , borderSize , borderSize )
75- end
7645
77- if bottomRight then
78- drawTexturedRectUV (x + w - borderSize , y + h - borderSize , borderSize , borderSize , 1 , 1 , 0 , 0 )
79- else
80- drawRect (x + w - borderSize , y + h - borderSize , borderSize , borderSize )
81- end
46+ function PIXEL .DrawRoundedBoxEx (borderSize , x , y , w , h , col , topLeft , topRight , bottomLeft , bottomRight )
47+ return DrawFullRoundedBoxEx (borderSize , x , y , w , h , col , topLeft , topRight , bottomLeft , bottomRight )
8248end
8349
84- local drawRoundedBoxEx = PIXEL .DrawRoundedBoxEx
8550function PIXEL .DrawRoundedBox (borderSize , x , y , w , h , col )
86- return drawRoundedBoxEx (borderSize , x , y , w , h , col , true , true , true , true )
87- end
88-
89- local roundedBoxCache = {}
90- local whiteTexture = surface .GetTextureID (" vgui/white" )
91-
92- local drawPoly = surface .DrawPoly
93-
94- function PIXEL .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- return
100- end
101-
102- local fullRight = x + w
103- local fullBottom = y + h
104-
105- local left , right = x + borderSize , fullRight - borderSize
106- local top , bottom = y + borderSize , fullBottom - borderSize
107-
108- local halfBorder = borderSize * .7
109-
110- local cacheName = borderSize .. x .. y .. w .. h
111- local cache = roundedBoxCache [cacheName ]
112- if not cache then
113- cache = {
114- {x = right , y = y }, -- Top Right
115- {x = right + halfBorder , y = top - halfBorder },
116- {x = fullRight , y = top },
117-
118- {x = fullRight , y = bottom }, -- Bottom Right
119- {x = right + halfBorder , y = bottom + halfBorder },
120- {x = right , y = fullBottom },
121-
122- {x = left , y = fullBottom }, -- Bottom Left
123- {x = left - halfBorder , y = bottom + halfBorder },
124- {x = x , y = bottom },
125-
126- {x = x , y = top }, -- Top Left
127- {x = left - halfBorder , y = top - halfBorder },
128- {x = left , y = y }
129- }
130-
131- roundedBoxCache [cacheName ] = cache
132- end
133-
134- setTexture (whiteTexture )
135- drawPoly (cache )
136-
137- if not tl then drawRect (x , y , borderSize , borderSize ) end
138- if not tr then drawRect (x + w - borderSize , y , borderSize , borderSize ) end
139- if not bl then drawRect (x , y + h - borderSize , borderSize , borderSize ) end
140- if not br then drawRect (x + w - borderSize , y + h - borderSize , borderSize , borderSize ) end
51+ return DrawFullRoundedBoxEx (borderSize , x , y , w , h , col , true , true , true , true )
14152end
14253
14354function PIXEL .DrawFullRoundedBox (borderSize , x , y , w , h , col )
144- return PIXEL . DrawFullRoundedBoxEx (borderSize , x , y , w , h , col , true , true , true , true )
55+ return DrawFullRoundedBoxEx (borderSize , x , y , w , h , col , true , true , true , true )
14556end
0 commit comments