Class: LUIT::LUITElement

Inherits:
Object
  • Object
show all
Defined in:
lib/luit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(holder, id, x, y, w, h) ⇒ LUITElement



48
49
50
51
52
53
54
55
56
57
# File 'lib/luit.rb', line 48

def initialize(holder, id, x, y, w, h)
	@holder = holder
	@id = id
	@x = x
	@y = y
	@w = w
	@h = h
	@msDown = false
	@hover = true
end

Instance Attribute Details

#hObject (readonly)

Returns the value of attribute h.



47
48
49
# File 'lib/luit.rb', line 47

def h
  @h
end

#hoverObject (readonly)

Returns the value of attribute hover.



47
48
49
# File 'lib/luit.rb', line 47

def hover
  @hover
end

#idObject (readonly)

Returns the value of attribute id.



47
48
49
# File 'lib/luit.rb', line 47

def id
  @id
end

#wObject (readonly)

Returns the value of attribute w.



47
48
49
# File 'lib/luit.rb', line 47

def w
  @w
end

#xObject (readonly)

Returns the value of attribute x.



47
48
49
# File 'lib/luit.rb', line 47

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



47
48
49
# File 'lib/luit.rb', line 47

def y
  @y
end

Instance Method Details

#button_down(id) ⇒ Object



85
86
87
88
89
# File 'lib/luit.rb', line 85

def button_down(id)
	if id == Gosu::MsLeft && @hover
		@holder.onClick(@id)
	end
end

#draw(x = 0, y = 0) ⇒ Object



59
60
# File 'lib/luit.rb', line 59

def draw(x = 0, y = 0)
end

#draw_rel(x = 0, y = 0) ⇒ Object



62
63
64
# File 'lib/luit.rb', line 62

def draw_rel(x = 0, y = 0)
	draw(x - (@w/2), y - (@h/2))
end

#update(x = 0, y = 0) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/luit.rb', line 70

def update(x = 0, y = 0)
	if Gosu::button_down?(Gosu::MsLeft) or LUIT.touchDown
		if !@msDown
			button_down(Gosu::MsLeft)
		end
		@msDown = true
	else
		@msDown = false
	end
end

#update_rel(x = 0, y = 0) ⇒ Object



81
82
83
# File 'lib/luit.rb', line 81

def update_rel(x = 0, y = 0)
	update(x - (@w/2), y - (@h/2))
end

#updateHover(x, y) ⇒ Object



66
67
68
# File 'lib/luit.rb', line 66

def updateHover(x, y)
	@hover = LUIT.mX.between?(x, x + @w) && LUIT.mY.between?(y, y + @h)
end