class Gosuplus::GUI::Button
Attributes
timer[RW]
Public Class Methods
new(position, image, input_handler, key_id, text = nil, font = nil)
click to toggle source
# File lib/Gosuplus/gui/button.rb, line 6 def initialize(position, image, input_handler, key_id, text = nil, font = nil) @icon = Icon.new(image, position) @input_handler, @key_id = input_handler, key_id if text && font @text = Text.new(text, font) @text.center(@icon) end @visible = true end
Public Instance Methods
active?()
click to toggle source
# File lib/Gosuplus/gui/button.rb, line 35 def active?; @active; end
draw()
click to toggle source
# File lib/Gosuplus/gui/button.rb, line 16 def draw ButtonRenderer.draw(@icon, @text) if @visible end
expose()
click to toggle source
# File lib/Gosuplus/gui/button.rb, line 38 def expose; @visible = true; end
hide()
click to toggle source
# File lib/Gosuplus/gui/button.rb, line 37 def hide; @visible = false; end
update(x, y)
click to toggle source
# File lib/Gosuplus/gui/button.rb, line 20 def update(x, y) @active = false if @active unless @timer.nil? if activated?(x, y) @timer.reset @active = true end else @active = false end @timer.update end
visible?()
click to toggle source
# File lib/Gosuplus/gui/button.rb, line 36 def visible?; @visible; end
Private Instance Methods
activated?(x, y)
click to toggle source
# File lib/Gosuplus/gui/button.rb, line 41 def activated?(x, y) Collision.rectangular_collision?(@icon.body, Body.new(Vec2.new(x, y), 1, 1)) && @timer.ready? && @input_handler.get_state(256) end