[Ruby] Circular Mouse Checks

Post any examples or modules that you want to share here
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

[Ruby] Circular Mouse Checks

Post by tulamide »

Nowadays GUIs have more and more circular objects, be it knobs or buttons. If you have more than one object in your view and want to detect mouse clicks on them, you have to create a method for it.

You can get away with a rectangular check, which is setting up the boundaries of a virtual rectangle around the object and then testing if the mouse position is inside that virtual rectangle.

But you can also check circular. If you draw a circle it has a center point and a radius. The trick is to test if the mouse position is inside the radius.

The schematic will show you how to do a circular check and why it is an advantage when dealing with circular objects.
Attachments
check_circular.fsm
(1.04 KiB) Downloaded 1424 times
"There lies the dog buried" (German saying translated literally)
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: [Ruby] Circular Mouse Checks

Post by RJHollins »

Hi T,

Man , that works really well. Cool.
8-)
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: [Ruby] Circular Mouse Checks

Post by Nubeat7 »

thats very useful, if you would like to play this with any shape you like, there exists a comfortable methode,
the isVisible methode for graphicpaths (userguide p.162)

with this methode you can check if a point is inside a graphicpath, here is a small example based on the one you posted

greez
Attachments
check_shape.fsm
(707 Bytes) Downloaded 1471 times
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: [Ruby] Circular Mouse Checks

Post by tulamide »

Yes, I know about this method, and it is nice to have. The thing is, polygon checks are much more cpu-intensive. If this is not a concern, then, this goes to everyone reading here, make use of it. If it is a concern, rectangular and circular checks are cheaper on cpu.

@RJHollins, thank you :)
"There lies the dog buried" (German saying translated literally)
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: [Ruby] Circular Mouse Checks

Post by RJHollins »

Good stuff Guys.

Always appreciate the 'education' too !
8-)
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: [Ruby] Circular Mouse Checks

Post by Nubeat7 »

tulamide wrote:Yes, I know about this method, and it is nice to have. The thing is, polygon checks are much more cpu-intensive. If this is not a concern, then, this goes to everyone reading here, make use of it. If it is a concern, rectangular and circular checks are cheaper on cpu.

@RJHollins, thank you :)


thanks for this info, good to know!
User avatar
Walter Sommerfeld
Posts: 250
Joined: Wed Jul 14, 2010 6:00 pm
Location: HH - Made in Germany
Contact:

Re: [Ruby] Circular Mouse Checks

Post by Walter Sommerfeld »

Perfect 4 my Endless knob with it's center button...


Keep on doing!

cheers,
Walter
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: [Ruby] Circular Mouse Checks

Post by Tronic »

8-)
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: [Ruby] Circular Mouse Checks

Post by RJHollins »

Walter Sommerfeld wrote:Perfect 4 my Endless knob with it's center button...


Keep on doing!

cheers,
Walter

Hmmm :) Are you saying a way to control dual concentric rings ?? :o Like an API 5500 eq.

that would be so useful.
8-)
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: [Ruby] Circular Mouse Checks

Post by Nubeat7 »

RJHollins wrote:..control dual concentric rings ??..


for this you can use the widen methode on an arc path when you are using a pen to draw a path and you will need only the area from the pen line...
here is a very basic schematic to do this, but also tulamides methode would work, its without any eventhandling or presetmanagement, but this shouldn't be to hard..
Attachments
double_knob.fsm
(1.04 KiB) Downloaded 1412 times
Post Reply