## 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: Klaus, FourthWorld, heatherlaine, kevinmiller

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

### Circular Knob that Snaps to Positions

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

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

### Re: Circular Knob that Snaps to Positions

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: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

### Re: Circular Knob that Snaps to Positions

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
Posts: 74
Joined: Fri Apr 28, 2006 12:10 am

### Re: Circular Knob that Snaps to Positions

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: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

### Re: Circular Knob that Snaps to Positions

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