A GUI view that mimics a rotary-style encoder, similar to Knob, but fully customizable, including optionally a full 360-degree continuous range.
The view works in much the same was at other SC widgets, but has additional capabilities to notify dependents of changes, and the appearance is extensively customizable via numerous drawing layers with settable properties.
Create a new RotaryView.
parent |
A Window or View, in which to embed this view. If |
bounds |
A Rect describing the bounds of this view within its parent. If parent is |
spec |
A ControlSpec that will control the range and warping of your value. -input is the unmapped -value. If NOTE: : The step of the provided ControlSpec will determine the step resolution of the rotary when changing the value with a mouse or arrow key (default is 0 , i.e. highest step resolution possible). See RotaryView: Example: radio dial. |
initVal |
The initial -value within range of the spec when the view is first drawn. |
startAngle |
The angular position of the start of the rotary's range, in radians. Default is |
sweepLength |
The range of motion of the rotary, in radians. Default is |
innerRadiusRatio |
A value from |
outerRadiusRatio |
A value from |
direction |
A Symbol, |
A RotaryView.
Get/set the value held by the view, which is the mapped counterpart of the -input (via the -spec).
The new value and corresponding -input will be broadcast to dependents, via \value
and \iinput
messages, respectively, every time either is set, unless -broadcastNewOnly is true
, in which case the values are only broadcast if they differ from their previous state.
val |
A Number. The number will either be constrained or wrapped within the view's -spec, depending on the state of -wrap (default is |
Get/set the input held by the view, which is the unmapped counterpart of the -value (via the -spec), i.e. a value from (0..1). This is useful for updating other UI elements which are often set through normalized values, like Sliders.
The new input and corresponding -value will be broadcast to dependents, via \input
and \value
messages, respectively, every time either is set, unless -broadcastNewOnly is true
, in which case the values are only broadcast if they differ from their previous state.
normValue |
A Number in the range |
Set the value of the view and perform the -action. This also updates the -input by unmapping from the -spec.
val |
A Number in the range of the -spec. Out-of-range values will be clipped to the range of the -spec, unless -wrap is |
Set the input value of the view and perform the -action. This also updates the -value by mapping through the -spec.
normValue |
A Number in the range of (0..1). Out-of-range inputs will be clipped to the range, unless -wrap is |
Perform the -action. Usually called through -valueAction or -inputAction.
newValue |
A Boolean determining whether the actions is performed. Default is |
Get/set the Boolean which determines if the -action is performed only when a newly set value differs from its previous state. This applies when calling -valueAction, -inputAction, or -doAction. Default is true
(repeated actions are suppressed). See RotaryView: Example: radio dial.
Get/set the ControlSpec used to both map the -input and constrain the -value. Note: the step of the provided controlSpec will determine the step resolution of the rotary.
controlSpec |
A ControlSpec. |
updateValue |
A Boolean specifying whether the -value(and -input) should be updated when the new controlSpec is set. Default is |
A Boolean which determines if the rotary behaves like a continuous encoder, wrapping values around its -spec range when crossing min/max values. Useful for full 2pi
range rotary controls. Synonym for -wrap. Default is false
(values are clipped to range).
\circular
the rotary behavior is always continuous, even if -continuous is false
.Set how mouse clicking changes the rotary position:
(value) |
|
Set how mouse dragging changes moves the rotary position.
\circular
the rotary behavior is always continuous, even if -continuous is false
.vertHorizOrCirc |
|
Get/set the sensitivity of mouse interaction (and output resolution) by specifying the number of pixels over which the whole view's value range can be covered. Default is 200
, i.e. the entire range of possible values will be covered in 200 pixels of movement. This can also be set by -valuePerPixel.
Get/set the sensitivity of mouse interaction (and output resolution) by specifying the value change per pixel when interacting with the view through mouse movement. Default is spec.range / 200
, i.e. the entire range of possible values will be covered in 200 pixels of movement. This can also be set by -rangeInPixels.
Get/set the Boolean indicating whether the value changes with mouse scrolling. Default is true
.
Get/set the step amount when scrolling. Default is 100.reciprocal
.
Get/set the x scroll direction. 1
is left to right scrolling (default), -1
is the reverse.
Get/set the y scroll direction. -1
is "natural" scrolling (default), 1
is the reverse.
Get/set the step amount of each arrow key press, as a percentage of the range of the spec. E.g. keyStep of 30.reciprocal
(the default) means it takes 30 key strokes to cover the full value range (warped according to the -spec).
Get/set the step direction of Left/Right arrow keys. 1
= right increments, left decrements (default). -1
= left increments, right decrements.
Get/set the step direction of Up/Down arrow keys. 1
= up increments, down decrements (default). -1
= down increments, up decrements.
Get/set how the rotary fills the color up to the current value. If false
, the color is always filled from the minumum value in the range up to the current value. If true
, the color is filled from the -centerValue to the current value. See RotaryView: Example: bipolar mode and Example: continuous encoder.
bool |
A Boolean. |
Get/set the Number that is the "center" of the bipolar axis. See RotaryView: Example: bipolar mode and Example: continuous encoder.
value |
Set the number of ticks to be displayed evenly across the full range of the rotary. See Examples: radio dial and Example: continuous encoder.
num |
An Integer. The total number of ticks (major and minor). |
majorEvery |
An Integer. Frequency of major ticks. E.g. majorEvery = |
startAndEnd |
A Boolean, whether the first and last tick fall at the start and end of the range. E.g. If the -sweepLength is |
Set the position of major and minor ticks, in radians.
majorRadPositions |
An Array of radian values, relative to -startAngle and -direction, for the major ticks. |
minorRadPositions |
An Array of radian values, relative to -startAngle and -direction, for the minor ticks. |
Set the position of major and minor ticks, in the units of your -spec. See Examples: bipolar mode.
majorVals |
An Array of values for the major ticks, within the range of your -spec. |
minorVals |
An Array of values for the minor ticks, within the range of your -spec. |
Set the ticks at an even interval, in the units of your -spec, specifying the steps between each major tick. See Example: continuous encoder.
valueHop |
A Number specifying the interval, or "hop", between each tick. |
majorEvery |
An Integer specifying the steps of major ticks. |
Get/set the direction of positive movement, for both value changes as well as affecting how -startAngle is determined.
dir |
A Symbol, |
Get the value corresponding to the rotary's direction: clockwise = 1
, counterclockwise = -1
.
Set/get the radius of the the inner edge of the rotary.
ratio |
A value from |
Set/get the radius of the the outer edge of the rotary, where 1
is the maximum radius given the size of the view.
ratio |
A value from |
Get/set the angular position of the start of the rotary's range, in radians. Reference 0
position is up, 12 o'clock, and advances according to -direction.
radians |
A Number in radians, can be negative. |
Get/set the range of motion of the rotary, in radians. Default is 2pi
.
radians |
A A Number in radians. |
The rotary is comprised of multiple layers, each with their own settable properties: range, level, text, ticks, handle, and outline. Each drawing layer has a *properties
list (an Event), the keys of which can be accessed as pseudo-methods for getting and setting their values. Setting a property automatically refreshes the view. For example:
The layer showing the range of the rotary. Some parameters apply only for a certain style
. If style == \wedge
, an annularWedge is drawn for the range. If style == \arc
a stroked arc is used.
property | default | description |
show | true | show the range layer or not |
style | \wedge | \arc or \wedge (an annularWedge); if \arc , the width
follows width, not strokeWidth |
radius | 1 | (0..1) , radius of outer edge of the wedge or arc |
width | 1 | (0..1) width of range display, relative to wedgeWidth
( |
fill | true | fill the range or not |
fillColor | Color(0.9,0.9,0.9) | color to fill the range |
stroke | false | stroke the range or not |
strokeType | \around | if style == \wedge ; \inside , \outside , \around , or \insideOutside |
strokeColor | Color | stroke color of the range |
strokeWidth | 1 | if style == \wedge ; if < 1 , assumed to be a normalized value
and changes with view size, else treated as a pixel value |
joinStyle | 0 | if style == \wedge ; \miter ; \round , \bevel , or
an Integer of the Pen: *joinStyle |
capStyle | \round | if style == \arc ; \butt , \flat , \round , \square , or
an Integer of the Pen: *capStyle |
The layer showing the level of the rotary. If style == \wedge
, an annularWedge is drawn for the range. If style == \arc
a stroked arc is used.
property | default | description |
show | true | show the level layer or not |
style | \wedge | \arc or \wedge (an annularWedge); if \arc , the width
follows width, not strokeWidth |
radius | 1 | (0..1) , radius of outer edge of the wedge or arc |
width | 1 | (0..1) width of range display, relative to wedgeWidth |
fill | true | fill the level or not |
fillColor | Color.white | color to fill the level; |
stroke | true | stroke the level or not |
strokeType | \around | if style == \wedge ; \inside , \outside , \around , or \insideOutside |
strokeColor | Color.gray | stroke color of the level |
strokeWidth | 0.025 | if style == \wedge ; if < 1 , assumed to be a normalized value |
joinStyle | 0 | if style == \wedge ; \miter ; \round , \bevel , or
an Integer of the Pen: *joinStyle and changes with view size, else treated as a pixel value |
capStyle | 0 | if style == \arc ; \butt , \flat , \round , \square , or
an Integer of the Pen: *capStyle |
The layer showing the text of the rotary's current value.
property | default | description |
show | true | show the text layer or not |
align | \center | \top , \bottom , \center , \left , \right , or a Point on which
to center the text, in a range of where top-left is |
round | 0.1 | a Number to round the value display to |
fontSize | 0.1 | font size in pixels, unless < 1 , then relative to radius |
fontName | "Helvetica" | a String, the font name |
color | Color.gray | Color of the text |
The layer showing the ticks of the rotary. The number and position of ticks are set through -numTicks, -ticksAt, -ticksAtValues, or -ticksEveryVal.
property | default | description |
show | false | show the tick layer or not |
anchor | 0.97 | (0..1) position/radius where the ticks are "anchored",
relative to outer edge of rotary |
align | \inside | the position of the ticks relative to anchor;
|
majorLength | 0.25 | length of major ticks, (0..1) realtive to maxRadius |
minorLength | 0.1 | length of major ticks, (0..1) realtive to maxRadius |
majorWidth | 0.05 | width of major tick, in pixels unless < 1 ,
in which case relative to radius |
minorWidth | 0.025 | width of major tick, in pixels unless < 1 ,
in which case relative to radius |
majorColor | Color.gray | Color of the major ticks |
minorColor | Color.gray | Color of the minor ticks |
capStyle | \round | \butt , \flat , \round , \square ,
or an Integer of the Pen: *capStyle |
The layer showing the "handle" of the rotary. Some properties are only valid for certain styles.
property | default | description |
show | true | show the handle layer or not |
style | 'line' | \line , \circle , or \arrow |
anchor | 0.9 | reference radius of for drawing the anchor align, (0..1) |
align | 'inside' | \inside , \outside , or \center on the anchor |
length | 0.3 | if style == \line or == \arrow , (0..1) relative to radius |
width | 0.6 | if style == \arrow , (0..1) relative to length |
stroke | true | if style == \circle or == \arrow , stroke the handle or not |
strokeColor | Color.black | stroke Color of the handle |
fill | true | if style == \circle or == \arrow , fill the handle or not |
fillColor | Color.red | fill Color of the handle |
joinStyle | 'round' | if style == \arrow , \miter , \round , \bevel ,
or an Integer of the Pen: *joinStyle |
radius | 0.1 | if style == \circle , in pixels unless < 1 ,
in which case relative to radius |
capStyle | 'round' | if style == \line , \butt , \flat , \round , \square ,
or an Integer of the Pen: *capStyle |
strokeWidth | 0.05 | width of stroke, in pixels, unless < 1 , then relative to radius
in which case relative to radius |
The layer showing the outline of the rotary. It's called "outline", but need not be on the perimeter—it's essentially a circle of variable size/fill that can serve as an outline or visual accent. It's the topmost layer.
property | default | description |
show | false | show the outline layer or not |
radius | 1 | (0..1) , relative to radius |
stroke | true | stroke or not |
strokeColor | Color.black | stroke Color of the outline |
strokeWidth | 2 | in pixels unless < 1 ,
in which case relative to radius |
rangeOnly | false | a Boolean whether outline is constrained
to the rotary's range, or is a full circle |
capStyle | flat | if rangeOnly == \true , \butt , \flat , \round , \square ,
or an Integer of the Pen: *capStyle |
fill | false | fill or not |
fillColor | Color.white | fill Color of the outline layer |
Multiple rotaries in a layout.