Jump to content

[HELP] Rounded border


Sakingod

Recommended Posts

Hello, there's a way to transform this: 8jwayY9.png to this -> GdwhZ7A.png?

first image code -> 

function dxDrawRoundedBorder(x, y, w, h, borderColor, postGUI)
	if (x) and (y) and (w) and (h) then
		borderColor = borderColor or tocolor(255, 255, 255, 230)

		dxDrawRectangle(x - 1, y + 1, 1, h - 2, borderColor, postGUI) -- left
		dxDrawRectangle(x + w, y + 1, 1, h - 2, borderColor, postGUI)-- right
		dxDrawRectangle(x + 1, y - 1, w - 2, 1, borderColor, postGUI) -- top
		dxDrawRectangle(x + 1, y + h, w - 2, 1, borderColor, postGUI) -- bottom

		dxDrawRectangle(x, y, 1, 1, borderColor, postGUI)
		dxDrawRectangle(x + w - 1, y, 1, 1, borderColor, postGUI)
		dxDrawRectangle(x, y + h - 1, 1, 1, borderColor, postGUI)
		dxDrawRectangle(x + w - 1, y + h - 1, 1, 1, borderColor, postGUI)
	end
end

 

Link to comment

the useful function from wiki 

function dxDrawRoundedRectangle(x, y, rx, ry, color, radius)
    rx = rx - radius * 2
    ry = ry - radius * 2
    x = x + radius
    y = y + radius

    if (rx >= 0) and (ry >= 0) then
        dxDrawRectangle(x, y, rx, ry, color)
        dxDrawRectangle(x, y - radius, rx, radius, color)
        dxDrawRectangle(x, y + ry, rx, radius, color)
        dxDrawRectangle(x - radius, y, radius, ry, color)
        dxDrawRectangle(x + rx, y, radius, ry, color)

        dxDrawCircle(x, y, radius, 180, 270, color, color, 7)
        dxDrawCircle(x + rx, y, radius, 270, 360, color, color, 7)
        dxDrawCircle(x + rx, y + ry, radius, 0, 90, color, color, 7)
        dxDrawCircle(x, y + ry, radius, 90, 180, color, color, 7)
    end
end

example 

function isMouseInPosition ( x, y, width, height )
	if ( not isCursorShowing( ) ) then
		return false
	end
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
        return true
    else
        return false
    end
end

function dxDrawRoundedRectangle(x, y, rx, ry, color, radius)
    rx = rx - radius * 2
    ry = ry - radius * 2
    x = x + radius
    y = y + radius

    if (rx >= 0) and (ry >= 0) then
        dxDrawRectangle(x, y, rx, ry, color)
        dxDrawRectangle(x, y - radius, rx, radius, color)
        dxDrawRectangle(x, y + ry, rx, radius, color)
        dxDrawRectangle(x - radius, y, radius, ry, color)
        dxDrawRectangle(x + rx, y, radius, ry, color)

        dxDrawCircle(x, y, radius, 180, 270, color, color, 7)
        dxDrawCircle(x + rx, y, radius, 270, 360, color, color, 7)
        dxDrawCircle(x + rx, y + ry, radius, 0, 90, color, color, 7)
        dxDrawCircle(x, y + ry, radius, 90, 180, color, color, 7)
    end
end

-- # example 

addEventHandler ( "onClientRender" , root , function ( ) 
local hover = isMouseInPosition ( 300 , 300 , 170 , 30 ) ; 
dxDrawRoundedRectangle(300,300,170,30, hover and tocolor(200,200,200,200) or tocolor(0,0,0,200), 10)
dxDrawText("Button",300,300,470,330,hover and tocolor(0,0,0,200) or tocolor(255,255,255,200),1,'default-bold','center','center')
end ) 

good luck

Link to comment
7 hours ago, Default#^ said:

the useful function from wiki 


function dxDrawRoundedRectangle(x, y, rx, ry, color, radius)
    rx = rx - radius * 2
    ry = ry - radius * 2
    x = x + radius
    y = y + radius

    if (rx >= 0) and (ry >= 0) then
        dxDrawRectangle(x, y, rx, ry, color)
        dxDrawRectangle(x, y - radius, rx, radius, color)
        dxDrawRectangle(x, y + ry, rx, radius, color)
        dxDrawRectangle(x - radius, y, radius, ry, color)
        dxDrawRectangle(x + rx, y, radius, ry, color)

        dxDrawCircle(x, y, radius, 180, 270, color, color, 7)
        dxDrawCircle(x + rx, y, radius, 270, 360, color, color, 7)
        dxDrawCircle(x + rx, y + ry, radius, 0, 90, color, color, 7)
        dxDrawCircle(x, y + ry, radius, 90, 180, color, color, 7)
    end
end

example 


function isMouseInPosition ( x, y, width, height )
	if ( not isCursorShowing( ) ) then
		return false
	end
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
        return true
    else
        return false
    end
end

function dxDrawRoundedRectangle(x, y, rx, ry, color, radius)
    rx = rx - radius * 2
    ry = ry - radius * 2
    x = x + radius
    y = y + radius

    if (rx >= 0) and (ry >= 0) then
        dxDrawRectangle(x, y, rx, ry, color)
        dxDrawRectangle(x, y - radius, rx, radius, color)
        dxDrawRectangle(x, y + ry, rx, radius, color)
        dxDrawRectangle(x - radius, y, radius, ry, color)
        dxDrawRectangle(x + rx, y, radius, ry, color)

        dxDrawCircle(x, y, radius, 180, 270, color, color, 7)
        dxDrawCircle(x + rx, y, radius, 270, 360, color, color, 7)
        dxDrawCircle(x + rx, y + ry, radius, 0, 90, color, color, 7)
        dxDrawCircle(x, y + ry, radius, 90, 180, color, color, 7)
    end
end

-- # example 

addEventHandler ( "onClientRender" , root , function ( ) 
local hover = isMouseInPosition ( 300 , 300 , 170 , 30 ) ; 
dxDrawRoundedRectangle(300,300,170,30, hover and tocolor(200,200,200,200) or tocolor(0,0,0,200), 10)
dxDrawText("Button",300,300,470,330,hover and tocolor(0,0,0,200) or tocolor(255,255,255,200),1,'default-bold','center','center')
end ) 

good luck

Where "dxDrawCircle" 's function?

Link to comment
On 02/10/2018 at 05:05, Default#^ said:

luck

it's not work good with postgui =true the color of corner doesn't appear

so u can use



function dxDrawRoundedRectangle(x,y,width,height,raduis,color,postgui)

dxDrawRectangle(x,y+raduis,width+1,height-(raduis*2),color,postgui)--horezantal rectangle
dxDrawRectangle(x+raduis,y,width-(raduis*2),height+1,color,postgui)--vertical rectangle

for k=180,270 do--left top
	local co=math.cos(math.rad(k))* raduis
	local si=math.sin(math.rad(k))* raduis
	dxDrawLine((x+raduis)+co,(y+raduis)+si,x+raduis,y+raduis,color,1,postgui)
end
for k=270,360 do--right top
	local co=math.cos(math.rad(k))* raduis
	local si=math.sin(math.rad(k))* raduis
	dxDrawLine((x+width-raduis)+co,(y+raduis)+si,x+width-raduis,y+raduis,color,1,postgui)
end

for k=90,180 do--left bottom
	local co=math.cos(math.rad(k))* raduis
	local si=math.sin(math.rad(k))* raduis
	dxDrawLine((x+raduis)+co,(y+height-raduis)+si,x+raduis,y+height-raduis,color,1,postgui)
end
local k=360
while(k<=(360+90))do
if k~= 360 then
	local co=math.cos(math.rad(k))* raduis
	local si=math.sin(math.rad(k))* raduis
	dxDrawLine((x-raduis+width)+co,(y+height-raduis)+si,x+width-raduis,y+height-raduis,color,1,postgui)
	
end
	k=k+1;
end

end

 

Link to comment
  • Discord Moderators
On 04/10/2018 at 00:47, sanyisasha said:

Interesting. When i last used this it was usefull. It's in my "old" (2018 jun's) core :D
I have to test it's performance better than the usefull one, or it's the same just implemented.

The circle shader is by far the fastest one(nearly 5x times faster than the in-built dxDrawCricle one, since it depends on CPU rather than GPU, which, as you know, isn't used too often in MTA, so, take use of it.)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...