Abstract class for controls that select a value within a range.
Controls may use an anchor
object to determine the visual position of
the control's interactive elements. Each implementation determines the
class used for this anchor
, for example
ArcControl
uses an Arc
as
anchor, which defines where the control is drawn, what orientation it
uses, and the position of the control knob through the range of possible
values.
A control keeps a value
property in the range [0,1] for the currently
selected value.
The projectionStart
and projectionEnd
properties can be used to
project value
into the range [projectionStart,projectionEnd]
by using
the projectedValue()
method. By default set to [0,1].
The startLimit
and endLimit
can be used to restrain the allowable
values that can be selected through user interaction. By default set to
[0,1].
Constructor
new Control(rac, value)
Creates a new Control
instance.
Parameters:
Name | Type | Description |
---|---|---|
rac |
Rac
|
Instance to use for drawing and creating other objects |
value |
Number
|
The initial value of the control, in the [0,1] range |
Members
endLimit :Number
Maximum value
that can be selected through user interaction.
- Default Value:
-
1
-
markers :Array.<number>
Collection of values at which visual markers are drawn.
- Default Value:
-
[]
-
projectionEnd :Number
Projected value to use when
value
is 1
.
- Default Value:
-
1
-
projectionStart :Number
Projected value to use when
value
is 0
.
- Default Value:
-
0
-
rac :Rac
Instance of Rac
used for drawing and passed along to any created
object.
startLimit :Number
Minimum value
that can be selected through user interaction.
- Default Value:
-
0
-
style :Rac.Stroke|Rac.Fill|Rac.StyleContainer
Style to apply when drawing. This style gets applied after
rac.controller.controlStyle
.
- Default Value:
-
null
-
value :Number
Current selected value, in the range [0,1].
May be further constrained to [startLimit,endLimit]
.
Methods
addMarkerAtCurrentValue()
Adds a marker at the current value
.
(abstract) affixAnchor() → {Object}
Returns a copy of the anchor to be persited during user interaction.
Each implementation determines the type used for anchor
and
affixAnchor()
.
This fixed anchor is passed back to the control through
updateWithPointer
and
drawSelection
during user
interaction.
⚠️ This method must be overriden by an extending class. Calling this implementation throws an error.
(abstract) draw()
Draws the current state.
⚠️ This method must be overriden by an extending class. Calling this implementation throws an error.
(abstract) drawSelection(pointerCenter, fixedAnchor, pointerToKnobOffset)
Draws the selection state along with pointer interaction visuals.
Called by rac.controller.drawControls
only for the selected control.
⚠️ This method must be overriden by an extending class. Calling this implementation throws an error.
Parameters:
Name | Type | Description |
---|---|---|
pointerCenter |
Rac.Point
|
The position of the user pointer |
fixedAnchor |
Object
|
Anchor of the control produced when user interaction started |
pointerToKnobOffset |
Rac.Segment
|
A |
isSelected() → {Boolean}
Returns true
when this control is the currently selected control.
(abstract) knob() → {Rac.Point}
Returns a Point
at the center of the control knob.
⚠️ This method must be overriden by an extending class. Calling this implementation throws an error.
projectedValue() → {Number}
Returns value
projected into the range
[projectionStart,projectionEnd]
.
By default the projection range is [0,1], in which case value
and
projectedValue()
are equal.
Projection ranges with a negative direction (E.g. [50,30], when
projectionStart
is greater that projectionEnd
) are supported. As
value
increases, the projection returned decreases from
projectionStart
until reaching projectionEnd
.
Examples
control.setProjectionRange(100, 200)
control.value = 0; control.projectionValue() // returns 100
control.value = 0.5; control.projectionValue() // returns 150
control.value = 1; control.projectionValue() // returns 200
control.setProjectionRange(30, 50)
control.value = 0; control.projectionValue() // returns 50
control.value = 0.5; control.projectionValue() // returns 40
control.value = 1; control.projectionValue() // returns 30
setLimitsWithInsets(startInset, endInset)
Sets both startLimit
and endLimit
with the given insets from 0
and 1
, correspondingly.
Parameters:
Name | Type | Description |
---|---|---|
startInset |
Number
|
The inset from |
endInset |
Number
|
The inset from |
Example
control.setLimitsWithInsets(0.1, 0.2)
// returns 0.1, since 0 + 0.1 = 0.1
control.startLimit
// returns 0.8, since 1 - 0.2 = 0.8
control.endLimit
(abstract) updateWithPointer(pointerKnobCenter, fixedAnchor)
Updates value
using pointerKnobCenter
in relation to fixedAnchor
.
Called by rac.controller.pointerDragged
as the user interacts with the control.
Each implementation interprets pointerKnobCenter
against fixedAnchor
to update its own value. The current anchor
is not used for this
update since anchor
could change during redraw in response to updates
in value
.
Each implementation is also responsible of keeping the updated value
within the range [startLimit,endLimit]
. This method is the only path
for updating the control through user interaction, and thus the only
place where each implementation must enforce a valid value
within
[0,1] and [startLimit,endLimit]
.
⚠️ This method must be overriden by an extending class. Calling this implementation throws an error.
Parameters:
Name | Type | Description |
---|---|---|
pointerKnobCenter |
Rac.Point
|
The position of the knob center as interacted by the user pointer |
fixedAnchor |
Object
|
Anchor produced when user interaction started |