Jump to content

[Help]Rounded rectangle


3B00DG4MER

Recommended Posts

Posted
I don't think so.

Thanks

There is a way, 'chatbubbles' ( the resource ) used this way. It's an insane way. They created a rectangle that kept growing 1px bigger in the width and moving 1px down to finally create the rounded rectangle. I wouldn't recommend it, but it's a way.

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

Posted

you actually can create multiple rectangles with "for" vertically by 1 pixel and change the size as it goes. Like this

local x,y = guiGetScreenSize() 
local sx,sy = 400,200 
local size = 45 -- pixel size to cut 
  
function performRendering() 
  for i=1,sy do 
    local dg = math.min(i,size) -- limit it to the size 
    if i > sy-size then 
      dg = sy-math.max(sy-size,i) -- limit it to the size for bottom parts 
    end 
    local csx = sx-1/dg*size -- use our lovely y = k/x function 
    dxDrawRectangle(x/2-csx/2,y/2-sy/2+i,csx,1,tocolor(0,0,0,200)) -- draw the magic at the middle 
  end 
end 
addEventHandler("onClientRender",getRootElement(),performRendering) 

But it WILL loose the quallity and it WILL look a bit weird.

Screenshot_at_2014_04_26__18_15_00.png

You also can draw that more frequently than 1 pixel, but keep in mind that slow computers will degrade on performance.

Posted

I don't see what's the point of that, what's wrong with using a image?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
I don't see what's the point of that, what's wrong with using a image?

it's take download :lol:

An image like this wont take more than 100kb, maybe even less if it's small. If you don't want to take the download part. Don't make these rounding corners. :P

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

Posted
you actually can create multiple rectangles with "for" vertically by 1 pixel and change the size as it goes. Like this
local x,y = guiGetScreenSize() 
local sx,sy = 400,200 
local size = 45 -- pixel size to cut 
  
function performRendering() 
  for i=1,sy do 
    local dg = math.min(i,size) -- limit it to the size 
    if i > sy-size then 
      dg = sy-math.max(sy-size,i) -- limit it to the size for bottom parts 
    end 
    local csx = sx-1/dg*size -- use our lovely y = k/x function 
    dxDrawRectangle(x/2-csx/2,y/2-sy/2+i,csx,1,tocolor(0,0,0,200)) -- draw the magic at the middle 
  end 
end 
addEventHandler("onClientRender",getRootElement(),performRendering) 

But it WILL loose the quallity and it WILL look a bit weird.

Screenshot_at_2014_04_26__18_15_00.png

You also can draw that more frequently than 1 pixel, but keep in mind that slow computers will degrade on performance.

Thanks

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted
I don't see what's the point of that, what's wrong with using a image?

it's take download :lol:

An image like this wont take more than 100kb, maybe even less if it's small. If you don't want to take the download part. Don't make these rounding corners. :P

Okay okay i'll make a image

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted

If you want to make the rounded rectangle scalable, then it's better if you just make an image of the corner and draw everything else with dxDrawRectangle, then the download should be less than 1kb (more in photoshop, because of useless photoshop info in the image)

Posted

They would have to download the image once, and then that's all it renders.

It is way more efficient than doing those calculations with every frame. And easier. And looks better. :P

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

  • Moderators
Posted

Well all you need is white 4 corners.... (white because then you can set up your own colour)

Perfect rounded corners, it only cost a lot loop power to generate it. (one time of course)

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
3B00DG4MER: thank you .

Solved.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • 3 years later...
Posted
function roundedRectangle(x, y, w, h, borderColor, bgColor, postGUI)
	if (x and y and w and h) then
		if (not borderColor) then
			borderColor = tocolor(0, 0, 0, 200);
		end
		
		if (not bgColor) then
			bgColor = borderColor;
		end
		
		--> Background
		dxDrawRectangle(x, y, w, h, bgColor, postGUI);
		
		--> Border
		dxDrawRectangle(x + 2, y - 1, w - 4, 1, borderColor, postGUI); -- top
		dxDrawRectangle(x + 2, y + h, w - 4, 1, borderColor, postGUI); -- bottom
		dxDrawRectangle(x - 1, y + 2, 1, h - 4, borderColor, postGUI); -- left
		dxDrawRectangle(x + w, y + 2, 1, h - 4, borderColor, postGUI); -- right
	end
end

Just add it inside your rendering function next to the rectangle you want it to become round..

don´t is necessari

Posted

Just as a simple solution, having a circle image and drawing sections for corners its better, simple and has a better performance than using maths everyframe.

"El conocimiento jamás debe detenerse, por que es lo único que nos salvará cuando no nos quede más".

Att: -|TG|-Mister[Q]<.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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