Class: SparkleMotion::LaunchPad::Widget
- Inherits:
-
Object
- Object
- SparkleMotion::LaunchPad::Widget
- Defined in:
- lib/sparkle_motion/launch_pad/widget.rb
Overview
Base class for Launchpad UI widgets.
Direct Known Subclasses
SparkleMotion::LaunchPad::Widgets::HorizontalSlider, SparkleMotion::LaunchPad::Widgets::RadioGroup, SparkleMotion::LaunchPad::Widgets::Toggle, SparkleMotion::LaunchPad::Widgets::VerticalSlider
Instance Attribute Summary collapse
-
#down ⇒ Object
Returns the value of attribute down.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#off ⇒ Object
Returns the value of attribute off.
-
#on ⇒ Object
Returns the value of attribute on.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #blank ⇒ Object
-
#initialize(launchpad:, x: nil, y: nil, position: nil, width:, height:, on:, off:, down:, value:) ⇒ Widget
constructor
TODO: Use ‘Vector2` for position/size…
- #max_v ⇒ Object
- #render ⇒ Object
- #update(value, render_now = true) ⇒ Object
Constructor Details
#initialize(launchpad:, x: nil, y: nil, position: nil, width:, height:, on:, off:, down:, value:) ⇒ Widget
TODO: Use ‘Vector2` for position/size…
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 9 def initialize(launchpad:, x: nil, y: nil, position: nil, width:, height:, on:, off:, down:, value:) @x = x @y = y @position = position @width = width @height = height @launchpad = launchpad @value = value @pressed = {} set_colors!(on, off, down) attach_handler! end |
Instance Attribute Details
#down ⇒ Object
Returns the value of attribute down.
6 7 8 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 6 def down @down end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 5 def height @height end |
#off ⇒ Object
Returns the value of attribute off.
6 7 8 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 6 def off @off end |
#on ⇒ Object
Returns the value of attribute on.
6 7 8 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 6 def on @on end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 5 def value @value end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 5 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
5 6 7 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 5 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
5 6 7 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 5 def y @y end |
Instance Method Details
#blank ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 41 def blank black = SparkleMotion::LaunchPad::Color::BLACK.to_h if @x (0..max_x).each do |xx| (0..max_y).each do |yy| change_grid(x: xx, y: yy, color: black) end end else change_command(position: @position, color: black) end end |
#max_v ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 54 def max_v if @x @max_v ||= (height * width) - 1 else 1 end end |
#render ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 29 def render @pressed.map do |idx, state| next unless state if @x xx, yy = coords_for(idx: idx) change_grid(x: xx, y: yy, color: down) else change_command(position: @position, color: down) end end end |
#update(value, render_now = true) ⇒ Object
23 24 25 26 27 |
# File 'lib/sparkle_motion/launch_pad/widget.rb', line 23 def update(value, render_now = true) @value = value @value = max_v if max_v && @value && @value > max_v render if render_now end |