Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Array problem in Ruby - am I missing something??

For general discussion related FlowStone

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

Postby MyCo » Fri Jan 25, 2013 1:13 pm

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
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

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

Postby trogluddite » Fri Jan 25, 2013 9:01 pm

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

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

Postby MyCo » Fri Jan 25, 2013 9:33 pm

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.
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

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

Postby tor » Sat Jan 26, 2013 4:04 am

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

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

Postby trogluddite » Sun Jan 27, 2013 1:43 pm

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??

Postby trogluddite » Mon Jan 28, 2013 10:00 am

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 1033 times
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??

Postby tor » Tue Jan 29, 2013 12:18 pm

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

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

Postby TimC-uk » Sun Feb 03, 2013 6:58 pm

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 1019 times
bitmap radio buttons.fsm
Based on some rough graphics throw together in Corel
(46.19 KiB) Downloaded 992 times
TimC-uk
 
Posts: 8
Joined: Sun Dec 02, 2012 7:11 pm

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 5 guests