roundrect: a fully functioning implementation

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

roundrect: a fully functioning implementation

Post by Robin »

I wrote this post before, but it got lost (together with everything else done on the backup server, if I'm right).

But anyhow:

Introducting love.graphics.roundrect, version 1.1.
roundrect.lua
Wowie! Rounded rectangles!
(958 Bytes) Downloaded 355 times
roundbox.love
Examples
(631 Bytes) Downloaded 335 times
Usage: love.graphics.roundrect(mode, x, y, width, height, xround, yround)

The first four arguments are the same as love.graphics.rectangle. xround and yround determine the size of the rounding.

And it works completely fine with alpha. I made it to use for Space.

License: let's say WTFPL. Whatever you want to do with it, it is fine.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: roundrect: a fully functioning implementation

Post by bartbes »

Again? :P
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: roundrect: a fully functioning implementation

Post by Robin »

It is a different version though: supplying too large values for xround and/or yround doesn't do any harm anymore. ;)
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: roundrect: a fully functioning implementation

Post by kikito »

mmm...

a polygon. Very smart!

If I could just minimize the number of calls to sin and cos...

I might give it a try during this week.
When I write def I mean function.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: roundrect: a fully functioning implementation

Post by coffee »

Hello Robin! Sorry (or not) to revive this. I was doing a small function for doing rounded corners buttons (in 7.2). It works well and it's enough for me. But since my function is limited to a solid object, I got curious when I saw this thread and what alternative (something more mathematical I guess) could be done. However your examples in thread are gone. Please, just for educative motifs can you respost? Thanks.

As you see my solution spite working nicely, was quite rudimentary and crude. Draw four circles at corners and drop 2 rectangles over (ashamed)

Code: Select all

function UI.bt:new(args)
   local v = {}
   if args == nil then return end
   --
   if args.key then v.key = args.key else return end
   if args.label then v.label = args.label else return end
   v.bg_color = args.bg_color or color.grey
   v.txt_color = args.txt_color or color.white
   v.hover_color = args.hover_color or color.orange
   v.x = args.x or 100
   v.y = args.y or 100
   v.w = args.w or tile_w or 32
   v.h = args.h or tile_h or 32
   v.r = args.radius or 5
   v.v = args.vertices or 3 
   v.hover = false
   v.hidden = false
   table.insert (UI.bt,v)
end -- end of function

function UI.bt:draw()

   if #UI.bt == 0 or UI.bt == nil then return end

   for i,v in ipairs(UI.bt) do
   setColor( v.bg_color )
   love.graphics.rectangle("fill",v.x+v.r,v.y,v.w-v.r*2,v.h)
   love.graphics.rectangle("fill",v.x,v.y+v.r,v.w,v.h-v.r*2)
   love.graphics.circle("fill", v.x+v.r, v.y+v.r, v.r, v.v*v.r) -- NW
   love.graphics.circle("fill", v.x+v.w-v.r, v.y+v.r, v.r, v.v*v.r) -- NE
   love.graphics.circle("fill", v.x+v.w-v.r, v.y+v.h-v.r, v.r, v.v*v.r) -- SE
   love.graphics.circle("fill", v.r+v.x, v.h+v.y-v.r, v.r, v.v*v.r) -- SW
   -- text stuff
end
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: roundrect: a fully functioning implementation

Post by Kingdaro »

perhaps with the release of 0.8 you would be able to use arcs to produce lined rounded rectangles?
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: roundrect: a fully functioning implementation

Post by coffee »

Kingdaro wrote:perhaps with the release of 0.8 you would be able to use arcs to produce lined rounded rectangles?
Yes, I already saw that some time ago in changelog. And that was very good news. But as for now it's better make it compatible with current stable version at least until 0.8 is available for all 3 OS's. But since this thread is from 2010 and Robin's function have "mode" I only can guess he found a way of simulate arcs or something close. So I got curious on this. :)
User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: roundrect: a fully functioning implementation

Post by trubblegum »

Looks neato .. I guess if 0.8 is adding to line-drawing functionality, a curve-drawing lib would be a bit pointless right now.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: roundrect: a fully functioning implementation

Post by Jasoco »

I wish we could draw ovals by way of extra parameters to the circle function. (X squish, Y squish and rotation)
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: roundrect: a fully functioning implementation

Post by coffee »

trubblegum wrote:Looks neato .. I guess if 0.8 is adding to line-drawing functionality, a curve-drawing lib would be a bit pointless right now.
Would be? Remember (if I'm right) that Linux users haven't yet a 0.8 version. Between use 0.8 because just only one command or use a outdated library (but that function in all Love versions) I would choose later one! :D
I wish we could draw ovals by way of extra parameters to the circle function. (X squish, Y squish and rotation)
Hmmm... Maybe use l.g.scale to distort circles to make them ovals?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest