RoundedRectangle: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Useful Function}} <lowercasetitle></lowercasetitle> __NOTOC__ This function is make a rounded rectangle. ==Syntax== <syntaxhighlight lang="lua">bool roundedRectangle ( floa...") |
|||
(7 intermediate revisions by 5 users not shown) | |||
Line 2: | Line 2: | ||
<lowercasetitle></lowercasetitle> | <lowercasetitle></lowercasetitle> | ||
__NOTOC__ | __NOTOC__ | ||
This function | This function draws a rounded corner rectangle. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua">nil dxDrawRoundedRectangle(x, y, width, height, radius, color, align, postGUI, subPixelPositioning)</syntaxhighlight> | ||
== | ==Example== | ||
<section name="Client side" class="client" show="true"> | <section name="Client side" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local sx, sy = guiGetScreenSize() | local sx, sy = guiGetScreenSize() | ||
local x, y, w, h = sx/2-200, sy/2-200, 400, 400 | |||
local rounded = 10 | |||
local color = tocolor(0, 0, 0, 200) | |||
function | addEventHandler('onClientRender', root, function () | ||
dxDrawRoundedRectangle(x, y, w, h, rounded, color) | |||
end) | |||
</syntaxhighlight> | |||
Example by @IQ65 | |||
</section> | |||
==Code 1== | |||
<section name="Client side" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
function dxDrawRoundedRectangle(x, y, width, height, radius, color, postGUI, subPixelPositioning) | |||
dxDrawRectangle(x+radius, y+radius, width-(radius*2), height-(radius*2), color, postGUI, subPixelPositioning) | |||
dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI) | |||
dxDrawCircle(x+radius, (y+height)-radius, radius, 90, 180, color, color, 16, 1, postGUI) | |||
dxDrawCircle((x+width)-radius, (y+height)-radius, radius, 0, 90, color, color, 16, 1, postGUI) | |||
dxDrawCircle((x+width)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI) | |||
dxDrawRectangle(x, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning) | |||
dxDrawRectangle(x+radius, y+height-radius, width-(radius*2), radius, color, postGUI, subPixelPositioning) | |||
dxDrawRectangle(x+width-radius, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning) | |||
dxDrawRectangle(x+radius, y, width-(radius*2), radius, color, postGUI, subPixelPositioning) | |||
end | end | ||
</syntaxhighlight> | |||
</section> | |||
==Code 2== | |||
==Syntax== | |||
<syntaxhighlight lang="lua">nil dxDrawRoundedRectangle(x, y, w, h, radius = 10, color = tocolor(255, 255, 255, 255), align = 'full', postGUI = false, subPixelPositioning = false)</syntaxhighlight> | |||
==Example== | |||
<section name="Client side" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
local data = {} | |||
data.resolution = {} | |||
data.resolution.x, data.resolution.y = guiGetScreenSize() | |||
data.mainRect = {} | |||
data.mainRect.width = 300 | |||
data.mainRect.height = 500 | |||
dxDrawRoundedRectangle( | |||
data.resolution.x-data.mainRect.width, | |||
data.resolution.y-data.mainRect.height, | |||
data.mainRect.width, | |||
data.mainRect.height, | |||
10, | |||
0xffffffff, | |||
'top', | |||
false, | |||
false | |||
) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
==Code== | ==Code== | ||
<section name=" | <section name="Client side" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | function dxDrawRoundedRectangle(x, y, w, h, radius, color, align, postGUI) | ||
if | if not x or not y or not w or not h then return end | ||
if ( | |||
local radius = radius or 10 | |||
local color = color or tocolor(255, 255, 255, 255) | |||
local align = align or 'full' | |||
if w < radius then | |||
w = 0 | |||
radius = 0 | |||
elseif h < radius then | |||
h = 0 | |||
radius = 0 | |||
end | |||
if align == 'full' or align == 'top' or align == 'right' or align == 'left' then | |||
if align == 'right' then | |||
dxDrawRectangle(x, y, w - radius, radius, color, postGUI) | |||
dxDrawCircle((x+w)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI) | |||
elseif align == 'left' then | |||
dxDrawRectangle(x + radius, y, w - radius, radius, color, postGUI) | |||
dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI) | |||
else | |||
dxDrawRectangle(x + radius, y, w - (radius * 2), radius, color, postGUI) | |||
dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI) | |||
dxDrawCircle((x+w)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI) | |||
end | end | ||
if | |||
if align == 'top' or align == 'right' or align == 'left' then | |||
dxDrawRectangle(x, y + radius, w, h - (radius * 2), color, postGUI) | |||
end | end | ||
dxDrawRectangle(x, y, w, h, | end | ||
dxDrawRectangle(x + | |||
dxDrawRectangle(x + 2, y + h, w - | if align == 'full' or align == 'bottom' or align == 'right' or align == 'left' then | ||
dxDrawRectangle(x | if align == 'right' then | ||
dxDrawRectangle(x | dxDrawRectangle(x, y + h - radius, w - radius, radius, color, postGUI) | ||
dxDrawCircle((x+w)-radius, (y+h)-radius, radius, 0, 90, color, color, 16, 1, postGUI) | |||
elseif align == 'left' then | |||
dxDrawRectangle(x + radius, y + h - radius, w - radius, radius, color, postGUI) | |||
dxDrawCircle(x+radius, (y+h)-radius, radius, 90, 180, color, color, 16, 1, postGUI) | |||
else | |||
dxDrawRectangle(x + radius, y + h - radius, w - (radius * 2), radius, color, postGUI) | |||
dxDrawCircle(x+radius, (y+h)-radius, radius, 90, 180, color, color, 16, 1, postGUI) | |||
dxDrawCircle((x+w)-radius, (y+h)-radius, radius, 0, 90, color, color, 16, 1, postGUI) | |||
end | |||
if align == 'bottom' or align == 'right' or align == 'left' then | |||
dxDrawRectangle(x, y + radius, w, h - (radius * 2), color, postGUI) | |||
end | |||
end | |||
if align == 'full' then | |||
dxDrawRectangle(x, y + radius, w, h - (radius * 2), color, postGUI) | |||
end | end | ||
end | end | ||
Line 52: | Line 132: | ||
</section> | </section> | ||
Original by [[User:Extasy]] | |||
Rewritten by [[User:Woovie]] | |||
Code 2 by [[User:.WhiteBlue]] |
Latest revision as of 14:13, 15 November 2023
This function draws a rounded corner rectangle.
Syntax
nil dxDrawRoundedRectangle(x, y, width, height, radius, color, align, postGUI, subPixelPositioning)
Example
Click to collapse [-]
Client sidelocal sx, sy = guiGetScreenSize() local x, y, w, h = sx/2-200, sy/2-200, 400, 400 local rounded = 10 local color = tocolor(0, 0, 0, 200) addEventHandler('onClientRender', root, function () dxDrawRoundedRectangle(x, y, w, h, rounded, color) end)
Example by @IQ65
Code 1
Click to collapse [-]
Client sidefunction dxDrawRoundedRectangle(x, y, width, height, radius, color, postGUI, subPixelPositioning) dxDrawRectangle(x+radius, y+radius, width-(radius*2), height-(radius*2), color, postGUI, subPixelPositioning) dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI) dxDrawCircle(x+radius, (y+height)-radius, radius, 90, 180, color, color, 16, 1, postGUI) dxDrawCircle((x+width)-radius, (y+height)-radius, radius, 0, 90, color, color, 16, 1, postGUI) dxDrawCircle((x+width)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI) dxDrawRectangle(x, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning) dxDrawRectangle(x+radius, y+height-radius, width-(radius*2), radius, color, postGUI, subPixelPositioning) dxDrawRectangle(x+width-radius, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning) dxDrawRectangle(x+radius, y, width-(radius*2), radius, color, postGUI, subPixelPositioning) end
Code 2
Syntax
nil dxDrawRoundedRectangle(x, y, w, h, radius = 10, color = tocolor(255, 255, 255, 255), align = 'full', postGUI = false, subPixelPositioning = false)
Example
Click to collapse [-]
Client sidelocal data = {} data.resolution = {} data.resolution.x, data.resolution.y = guiGetScreenSize() data.mainRect = {} data.mainRect.width = 300 data.mainRect.height = 500 dxDrawRoundedRectangle( data.resolution.x-data.mainRect.width, data.resolution.y-data.mainRect.height, data.mainRect.width, data.mainRect.height, 10, 0xffffffff, 'top', false, false )
Code
Click to collapse [-]
Client sidefunction dxDrawRoundedRectangle(x, y, w, h, radius, color, align, postGUI) if not x or not y or not w or not h then return end local radius = radius or 10 local color = color or tocolor(255, 255, 255, 255) local align = align or 'full' if w < radius then w = 0 radius = 0 elseif h < radius then h = 0 radius = 0 end if align == 'full' or align == 'top' or align == 'right' or align == 'left' then if align == 'right' then dxDrawRectangle(x, y, w - radius, radius, color, postGUI) dxDrawCircle((x+w)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI) elseif align == 'left' then dxDrawRectangle(x + radius, y, w - radius, radius, color, postGUI) dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI) else dxDrawRectangle(x + radius, y, w - (radius * 2), radius, color, postGUI) dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI) dxDrawCircle((x+w)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI) end if align == 'top' or align == 'right' or align == 'left' then dxDrawRectangle(x, y + radius, w, h - (radius * 2), color, postGUI) end end if align == 'full' or align == 'bottom' or align == 'right' or align == 'left' then if align == 'right' then dxDrawRectangle(x, y + h - radius, w - radius, radius, color, postGUI) dxDrawCircle((x+w)-radius, (y+h)-radius, radius, 0, 90, color, color, 16, 1, postGUI) elseif align == 'left' then dxDrawRectangle(x + radius, y + h - radius, w - radius, radius, color, postGUI) dxDrawCircle(x+radius, (y+h)-radius, radius, 90, 180, color, color, 16, 1, postGUI) else dxDrawRectangle(x + radius, y + h - radius, w - (radius * 2), radius, color, postGUI) dxDrawCircle(x+radius, (y+h)-radius, radius, 90, 180, color, color, 16, 1, postGUI) dxDrawCircle((x+w)-radius, (y+h)-radius, radius, 0, 90, color, color, 16, 1, postGUI) end if align == 'bottom' or align == 'right' or align == 'left' then dxDrawRectangle(x, y + radius, w, h - (radius * 2), color, postGUI) end end if align == 'full' then dxDrawRectangle(x, y + radius, w, h - (radius * 2), color, postGUI) end end
Original by User:Extasy
Rewritten by User:Woovie
Code 2 by User:.WhiteBlue