Class: Core::GUI::ImageButton

Inherits:
Button show all
Defined in:
lib/gui/button.rb

Overview

Same as Button, but draws an image instead of text

Instance Attribute Summary collapse

Attributes inherited from Button

#background, #proc

Attributes inherited from Element

#h, #w, #x, #xoff, #y, #yoff, #zoff

Instance Method Summary collapse

Methods inherited from Button

#disable, #enable, #hovered?, #toggle, #update

Methods inherited from Element

#remove?, #update

Constructor Details

#initialize(x, y, file, proc, w = -1,, h = -1)) ⇒ ImageButton

Returns a new instance of ImageButton.



72
73
74
75
76
77
78
79
80
81
# File 'lib/gui/button.rb', line 72

def initialize(x, y, file, proc, w=-1, h=-1)
  @bg = Core.sprite(file.to_s)
  if w < 0
    @w = w = @bg.width
  end
  if h < 0
    @h = h = @bg.height
  end
  super(x, y, w, h, "", proc, false)
end

Instance Attribute Details

#bgObject (readonly)

Returns the value of attribute bg.



71
72
73
# File 'lib/gui/button.rb', line 71

def bg
  @bg
end

Instance Method Details

#drawObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/gui/button.rb', line 82

def draw
  color = Gosu::Color.new(255, 255, 255, 255)
  if !@enabled
    color.saturation = 125
  end
  @bg.draw(@x+@xoff, @y+@yoff, Core::GUI_Z + 10 + @zoff, @w/@bg.width.to_f, @h/@bg.height.to_f, color)
  if @selected and @enabled
    @hi.draw(@x+@xoff, @y+@yoff, Core::GUI_Z + 11 + @zoff, @w/@hi.width.to_f, @h/@hi.height.to_f, 0xff999999, :additive)
  end
end