RoundedRectangle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:
<lowercasetitle></lowercasetitle>
<lowercasetitle></lowercasetitle>
__NOTOC__
__NOTOC__
This function is make a rounded rectangle.
This function draws a rounded corner rectangle.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool roundedRectangle ( float startX, float startY, float width, float height [, int tocolor ( int red, int green, int blue [, int alpha = 255 ] ) , bool postGUI = false ] )</syntaxhighlight>
<syntaxhighlight lang="lua">nil dxDrawRoundedRectangle(x, y, width, height, radius, color, postGUI, subPixelPositioning)</syntaxhighlight>


==Example==
==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 data = {}
roundedRectangle(sx/2, sy/2, 100, 100, tocolor(0,0,0,200))
data.resolution = {}
data.resolution.x, data.resolution.y = guiGetScreenSize()
data.mainRect = {}
data.mainRect.width = 300
data.mainRect.height = 500


function roundedRectangle(x, y, w, h, borderColor, bgColor, postGUI)
dxDrawRoundedRectangle(
if (x and y and w and h) then
    data.resolution.x-data.mainRect.width,
if (not borderColor) then
    data.resolution.y-data.mainRect.height,
borderColor = tocolor(0, 0, 0, 200);
    data.mainRect.width,
end
    data.mainRect.height,
if (not bgColor) then
    10,
bgColor = borderColor;
    0xffffffff,
end
    false,
dxDrawRectangle(x, y, w, h, bgColor, postGUI);
    false
dxDrawRectangle(x + 2, y - 1, w - 4, 1, borderColor, postGUI);
)
dxDrawRectangle(x + 2, y + h, w - 4, 1, borderColor, postGUI);
dxDrawRectangle(x - 1, y + 2, 1, h - 4, borderColor, postGUI);
dxDrawRectangle(x + w, y + 2, 1, h - 4, borderColor, postGUI);
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
Line 34: Line 33:
<section name="Client side" class="client" show="true">
<section name="Client side" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function roundedRectangle(x, y, w, h, borderColor, bgColor, postGUI)
function dxDrawRoundedRectangle(x, y, width, height, radius, color, postGUI, subPixelPositioning)
if (x and y and w and h) then
    dxDrawRectangle(x+radius, y+radius, width-(radius*2), height-(radius*2), color, postGUI, subPixelPositioning)
if (not borderColor) then
    dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI)
borderColor = tocolor(0, 0, 0, 200);
    dxDrawCircle(x+radius, (y+height)-radius, radius, 90, 180, color, color, 16, 1, postGUI)
end
    dxDrawCircle((x+width)-radius, (y+height)-radius, radius, 0, 90, color, color, 16, 1, postGUI)
if (not bgColor) then
    dxDrawCircle((x+width)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI)
bgColor = borderColor;
    dxDrawRectangle(x, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning)
end
    dxDrawRectangle(x+radius, y+height-radius, width-(radius*2), radius, color, postGUI, subPixelPositioning)
dxDrawRectangle(x, y, w, h, bgColor, postGUI);
    dxDrawRectangle(x+width-radius, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning)
dxDrawRectangle(x + 2, y - 1, w - 4, 1, borderColor, postGUI);
    dxDrawRectangle(x+radius, y, width-(radius*2), radius, color, postGUI, subPixelPositioning)
dxDrawRectangle(x + 2, y + h, w - 4, 1, borderColor, postGUI);
dxDrawRectangle(x - 1, y + 2, 1, h - 4, borderColor, postGUI);
dxDrawRectangle(x + w, y + 2, 1, h - 4, borderColor, postGUI);
end
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


Written by: ExTasY[https://wiki.multitheftauto.com/wiki/User:Extasy]
Original by [[User:Extasy]]
 
Rewritten by [[User:Woovie]]

Revision as of 06:08, 8 October 2020

This function draws a rounded corner rectangle.

Syntax

nil dxDrawRoundedRectangle(x, y, width, height, radius, color, postGUI, subPixelPositioning)

Example

Click to collapse [-]
Client side
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,
    false,
    false
)

Code

Click to collapse [-]
Client side
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

Original by User:Extasy

Rewritten by User:Woovie