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.
E.g.
For a control with a projection range of [100,200] + when value is 0, projectionValue() is 100 + when value is 0.5, projectionValue() is 150 + when value is 1, projectionValue() is 200 For a control with a projection range of [50,30] + when value is 0, projectionValue() is 50 + when value is 0.5, projectionValue() is 40 + when value is 1, projectionValue() is 30
setLimitsWithInsets(startInset, endInset)
Sets both startLimit and endLimit with the given insets from 0
and 1, correspondingly.
E.g.
control.setLimitsWithInsets(0.1, 0.2) // sets startLimit as 0.1 // sets endLimit as 0.8
Parameters:
| Name | Type | Description |
|---|---|---|
startInset |
number
|
The inset from |
endInset |
number
|
The inset from |
(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 |