Class: Button
- Inherits:
-
Object
- Object
- Button
- Defined in:
- lib/sgl/sgl-button.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #draw(s) ⇒ Object
- #draw_rect(w, h) ⇒ Object
-
#initialize(x, y) ⇒ Button
constructor
A new instance of Button.
- #inside?(x, y) ⇒ Boolean
- #move_to(x, y) ⇒ Object
- #pos ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Button
Returns a new instance of Button.
9 10 11 12 13 |
# File 'lib/sgl/sgl-button.rb', line 9 def initialize(x, y) @dx, @dy = x, y @x, @y = x, y @w, @h = 8, 8 end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
15 16 17 |
# File 'lib/sgl/sgl-button.rb', line 15 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
15 16 17 |
# File 'lib/sgl/sgl-button.rb', line 15 def y @y end |
Instance Method Details
#draw(s) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/sgl/sgl-button.rb', line 25 def draw(s) colorHSV(0, s, 100, 60) draw_rect(@w, @h) colorHSV(0, s, 0, 30) draw_rect(@w-1, @h-1) end |
#draw_rect(w, h) ⇒ Object
32 33 34 |
# File 'lib/sgl/sgl-button.rb', line 32 def draw_rect(w, h) rect(@x-w, @y-h, @x+w, @y+h) end |
#inside?(x, y) ⇒ Boolean
36 37 38 |
# File 'lib/sgl/sgl-button.rb', line 36 def inside?(x, y) (@x-@w) < x && x < (@x+@w) && (@y-@h) < y && y < (@y+@h) end |
#move_to(x, y) ⇒ Object
21 22 23 |
# File 'lib/sgl/sgl-button.rb', line 21 def move_to(x, y) @x, @y = x, y end |
#pos ⇒ Object
17 18 19 |
# File 'lib/sgl/sgl-button.rb', line 17 def pos return [x, y] end |