Page 3 of 3
Re: Array problem in Ruby - am I missing something??
Posted: Fri Jan 25, 2013 1:13 pm
by MyCo
The GraphicsPath object has no method for generating a round rect. I've built my own some time ago:
Code: Select all
def roundRectPathMyCo x,y,w,h,tlc,trc,brc,blc
path = GraphicsPath.new
# top left edge
path.addBeziers [ [x+w-trc,y], [x+w,y], [x+w,y+trc], [x+w,y+trc] ]
# top right edge
path.addBeziers [ [x+w,y+h-brc], [x+w,y+h], [x+w-brc,y+h], [x+w-brc,y+h] ]
# bottom right edge
path.addBeziers [ [x+blc,y+h], [x,y+h], [x,y+h-blc], [x,y+h-blc] ]
# bottom left edge
path.addBeziers [ [x,y+tlc], [x,y], [x+tlc,y], [x+tlc,y] ]
# left edge
path.closeFigure
return path
end
Parameters are:
x,y,w,h = outer rectangle
tlc,trc,brc,blc = corner sizes (eg. tlc = top left corner)
return value is a path containing the round rect shape
Re: Array problem in Ruby - am I missing something??
Posted: Fri Jan 25, 2013 9:01 pm
by trogluddite
Nice one, MyCo - that will "round out" (sorry, couldn't resist!) the selection of GraphicsPath shapes nicely.
Had a look at the GDI+ spec's and it appears there isn't a native command for adding rounded rectangles, so it would seem that this is the only way to draw it.
Re: Array problem in Ruby - am I missing something??
Posted: Fri Jan 25, 2013 9:33 pm
by MyCo
there is actually another way to draw the path using AddArc... but the code would be a lot longer, and my guess is, that it'll use more CPU because it has to calc sine and cosine instead of simple cubic interpolation.
Re: Array problem in Ruby - am I missing something??
Posted: Sat Jan 26, 2013 4:04 am
by tor
Is it impossible to use the already established draw round rectangle area as a reference for mouse inside/outside? Sounds weird to me, with a so diverse language...
Re: Array problem in Ruby - am I missing something??
Posted: Sun Jan 27, 2013 1:43 pm
by trogluddite
tor wrote:Is it impossible to use the already established draw round rectangle area as a reference for mouse inside/outside? Sounds weird to me, with a so diverse language...
It's not Ruby that's the problem - all of the graphics drawing commands are just calls to sub-routines built into the Windows GDI+ graphics engine, so it is GDI+ that defines which shapes are counted as paths that can use the 'isVisible' method.
In principle you could define a Ruby method to provide 'isVisible' for rounded rectangles - but using MyCo's method to define a path, and then using the GDI+ 'isVisible' is most likely already the most efficient way to do it.
Re: Array problem in Ruby - am I missing something??
Posted: Mon Jan 28, 2013 10:00 am
by trogluddite
MyCo wrote:it has to calc sine and cosine instead of simple cubic interpolation
Or maybe not?

Re: Array problem in Ruby - am I missing something??
Posted: Tue Jan 29, 2013 12:18 pm
by tor
ok, thanks both of you

I have to read more about Ruby and get more comfortable with things and repeat the tutorial some times to get it stored in my mental HDD, RAM and make the CPU understand all the info stored.
rubymonk.com is a great site for learning.
Re: Array problem in Ruby - am I missing something??
Posted: Sun Feb 03, 2013 6:58 pm
by TimC-uk
I dont' know if this is of any interest, but I wanted to make some radio buttons, and found the method of making a bitmap (either with your favourite graphics package, or even in Flowstone)) of sequential graphics operated by simple code to point to the offset, a very compact way of doing it. While I'm learining Ruby (and exploring Flowstone in general), I'm a K.I.S.S. sort of person! The example just has graphics of all four buttons in their up or down positions. I should think if you make a graphic of one button in off/on, up/down or whatever, it should be easy to extend to an array of as many as you need. If you need the results in an array, this could come afterwards.