Page 1 of 2

[Ruby] Circular Mouse Checks

Posted: Mon Nov 23, 2015 3:05 pm
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.

Re: [Ruby] Circular Mouse Checks

Posted: Mon Nov 23, 2015 7:55 pm
by RJHollins
Hi T,

Man , that works really well. Cool.
8-)

Re: [Ruby] Circular Mouse Checks

Posted: Mon Nov 23, 2015 7:58 pm
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

Re: [Ruby] Circular Mouse Checks

Posted: Mon Nov 23, 2015 10:26 pm
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 :)

Re: [Ruby] Circular Mouse Checks

Posted: Mon Nov 23, 2015 11:31 pm
by RJHollins
Good stuff Guys.

Always appreciate the 'education' too !
8-)

Re: [Ruby] Circular Mouse Checks

Posted: Tue Nov 24, 2015 9:32 am
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!

Re: [Ruby] Circular Mouse Checks

Posted: Tue Nov 24, 2015 2:26 pm
by Walter Sommerfeld
Perfect 4 my Endless knob with it's center button...


Keep on doing!

cheers,
Walter

Re: [Ruby] Circular Mouse Checks

Posted: Tue Nov 24, 2015 2:54 pm
by Tronic
8-)

Re: [Ruby] Circular Mouse Checks

Posted: Tue Nov 24, 2015 6:21 pm
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-)

Re: [Ruby] Circular Mouse Checks

Posted: Tue Nov 24, 2015 9:33 pm
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..