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??
28 posts
• Page 3 of 3 • 1, 2, 3
Re: Array problem in Ruby - am I missing something??
The GraphicsPath object has no method for generating a round rect. I've built my own some time ago:
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
- 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
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Array problem in Ruby - am I missing something??
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.
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!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Array problem in Ruby - am I missing something??
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.
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Array problem in Ruby - am I missing something??
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??
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!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Array problem in Ruby - am I missing something??
MyCo wrote:it has to calc sine and cosine instead of simple cubic interpolation
Or maybe not?
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Array problem in Ruby - am I missing something??
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.
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??
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 1052 times
-
- bitmap radio buttons.fsm
- Based on some rough graphics throw together in Corel
- (46.19 KiB) Downloaded 1022 times
- TimC-uk
- Posts: 8
- Joined: Sun Dec 02, 2012 7:11 pm
28 posts
• Page 3 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 99 guests