Class: Button

Inherits:
Object
  • Object
show all
Defined in:
lib/sgl/sgl-button.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



15
16
17
# File 'lib/sgl/sgl-button.rb', line 15

def x
  @x
end

#yObject

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

Returns:

  • (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

#posObject



17
18
19
# File 'lib/sgl/sgl-button.rb', line 17

def pos
  return [x, y]
end