Array problem in Ruby - am I missing something??

For general discussion related FlowStone
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Array problem in Ruby - am I missing something??

Post 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
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Array problem in Ruby - am I missing something??

Post 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.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Array problem in Ruby - am I missing something??

Post 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.
tor
Posts: 114
Joined: Fri Sep 24, 2010 5:54 pm

Re: Array problem in Ruby - am I missing something??

Post 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...
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Array problem in Ruby - am I missing something??

Post 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.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Array problem in Ruby - am I missing something??

Post by trogluddite »

MyCo wrote:it has to calc sine and cosine instead of simple cubic interpolation

Or maybe not? ;)
Theyre all beziers.fsm
(125.79 KiB) Downloaded 1132 times
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
tor
Posts: 114
Joined: Fri Sep 24, 2010 5:54 pm

Re: Array problem in Ruby - am I missing something??

Post 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.
TimC-uk
Posts: 8
Joined: Sun Dec 02, 2012 7:11 pm

Re: Array problem in Ruby - am I missing something??

Post 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.
Attachments
radio buttons - antique!.fsm
The same but using edited images from a website
(322.71 KiB) Downloaded 1127 times
bitmap radio buttons.fsm
Based on some rough graphics throw together in Corel
(46.19 KiB) Downloaded 1094 times
Post Reply