Circular Knob that Snaps to Positions
Posted: 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.
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.