Jump to content

[Help]Rounded rectangle


3B00DG4MER

Recommended Posts

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.

Link to comment

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.

Link to comment
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

Link to comment
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

Link to comment

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)

Link to comment
  • 3 years later...
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..

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

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