Circular Knob that Snaps to Positions

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
theotherbassist
Posts: 115
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Circular Knob that Snaps to Positions

Post by theotherbassist » Sat Apr 23, 2016 2:48 pm

Here I've got a basic circular knob that changes angle based on vertical mouse drag. I found the basis for this in the forums. In the stack, the upper field reports an integer value which is basically the angle as a fraction of a defined range. The lower field reports the angle value (just easier to visualize for me that way).

How can I make the knob so that it doesn't "freely" rotate (i.e. with a resolution of 360 possible positions per complete rotation) and have it snap instead only to the closest of a limited number of angles? I want the number of angles to be defined by the range of possible decimals defined in the script by the constant "cmaxdecimal."

In the example, cmaxdecimal is "5", so there should only be 6 possible positions of the knob (0-5, equally spaced). For my purposes, it doesn't matter if the snap happens while mouse tracking is still happening or once after mouseUp.

I know it should just basically be a reversal of the math that goes from angle to decimal, but my brain isn't working well enough today to reach something workable. Any ideas?

It would also be really nice to be able to define the lower limit of the decimal range, mostly because I want it to begin with 1, but that's sort of a separate thing.
Attachments
la knob.zip
(2.96 KiB) Downloaded 170 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Circular Knob that Snaps to Positions

Post by dunbarx » Sat Apr 23, 2016 6:50 pm

I could not open your stack. I was told it was corrupted. Usually, if made in 7 or 8, I am only told about a "later version". I am still in v.6.

Anyway, do you use the "mouseMove" message to set rotation? If so, you can track the x and y components, and only trigger a change in the knob with a modulo value, whatever suits you. If you are using some other method, you can do the same thing.

Craig Newman

theotherbassist
Posts: 115
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Re: Circular Knob that Snaps to Positions

Post by theotherbassist » Sat Apr 23, 2016 9:32 pm

Would you want mod or div? If you used div, you'd get the "whole" increments (some arbitrary px difference) for the change in x/y. Isn't that what you'd want? Am I thinking of it wrong?

...and yeah I'm using 7. I should just take 6 off altogether because of the way it corrupts the stacks permanently if you try to open 7+ in 6 or lower.

RogGuay
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 114
Joined: Fri Apr 28, 2006 12:10 am
Location: Seattle

Re: Circular Knob that Snaps to Positions

Post by RogGuay » Sun Apr 24, 2016 6:53 am

Forgive me if I'm jumping the gun here or if I misunderstand your needs, But have you looked at my RadialDialOmatic stack available here:

https://www.dropbox.com/s/w2rek4rphrqzw ... ecode?dl=0

I think you will find at least some useful ideas here for your requirements.


Regards,

Roger

theotherbassist
Posts: 115
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Re: Circular Knob that Snaps to Positions

Post by theotherbassist » Mon Apr 25, 2016 4:10 pm

Really cool stack, Roger. Thanks for the suggestions guys. I decided to give up on deciphering "stolen" code line by line and just developed my own solution.

In this version, the background is an image and the pointer is a graphic. The two are grouped and the knob's behavior is defined by a few custom properties of the group. I think I made it adaptable enough that others might find it useful. Feel free to DL and use.

Cheers,
theotherbassist
Attachments
Rotating Snap Knob - theotherbassist.zip
Circular Control that Snaps to States
(3.58 KiB) Downloaded 184 times

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”