Class: ButtonColumn
- Inherits:
-
Object
- Object
- ButtonColumn
- Defined in:
- lib/sgl/sgl-button.rb
Instance Attribute Summary collapse
-
#cur ⇒ Object
Returns the value of attribute cur.
-
#y_spring ⇒ Object
readonly
Returns the value of attribute y_spring.
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(length, dy, hy) ⇒ ButtonColumn
constructor
A new instance of ButtonColumn.
- #make_buttons ⇒ Object
- #move(x, y) ⇒ Object
- #onMouseDown(x, y) ⇒ Object
Constructor Details
#initialize(length, dy, hy) ⇒ ButtonColumn
Returns a new instance of ButtonColumn.
42 43 44 45 46 47 48 |
# File 'lib/sgl/sgl-button.rb', line 42 def initialize(length, dy, hy) @length, @dy, @hy = length, dy, hy #destination y and hide y @cur = 0 @buttons = [] @y_spring = NumSpring.new(@dy, @dy, 5, 0.6) end |
Instance Attribute Details
#cur ⇒ Object
Returns the value of attribute cur.
51 52 53 |
# File 'lib/sgl/sgl-button.rb', line 51 def cur @cur end |
#y_spring ⇒ Object (readonly)
Returns the value of attribute y_spring.
50 51 52 |
# File 'lib/sgl/sgl-button.rb', line 50 def y_spring @y_spring end |
Instance Method Details
#draw ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/sgl/sgl-button.rb', line 84 def draw @buttons.each_index {|i| b = @buttons[i] s = (@cur == i) ? 100 : 0 b.draw(s) } end |
#make_buttons ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sgl/sgl-button.rb', line 53 def y = @y_spring.x sw = 46 w = 0 @length.times { @buttons << Button.new(0, y) w += sw } x = -w/2 @buttons.each {|b| b.x = x x += sw } end |
#move(x, y) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sgl/sgl-button.rb', line 68 def move(x, y) # @y_spring.target = y.abs < (768/2 - 120) ? @hy : @dy #if y.abs < (768/2 - 120) if (@dy - y).abs < 50 @y_spring.target = @dy else @y_spring.target = @hy end @y_spring.moving = true @y_spring.move y = @y_spring.x @buttons.each {|b| b.y = y } end |
#onMouseDown(x, y) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/sgl/sgl-button.rb', line 92 def onMouseDown(x, y) @buttons.each_index {|i| b = @buttons[i] if b.inside?(x, y) @cur = i return i end } nil end |