Class: LUIT::Button
- Inherits:
-
LUITElement
- Object
- LUITElement
- LUIT::Button
- Defined in:
- lib/luit.rb
Instance Attribute Summary
Attributes inherited from LUITElement
Instance Method Summary collapse
- #draw(x = 0, y = 0) ⇒ Object
-
#initialize(holder, id, x, y, text, w = 0, h = 0) ⇒ Button
constructor
w and h will auto adjust to the text size + 10px padding if its not set (or set lower than acceptable).
- #update(x = 0, y = 0) ⇒ Object
Methods inherited from LUITElement
#button_down, #draw_rel, #updateHover, #update_rel
Constructor Details
#initialize(holder, id, x, y, text, w = 0, h = 0) ⇒ Button
w and h will auto adjust to the text size + 10px padding if its not set (or set lower than acceptable)
211 212 213 214 215 216 217 218 219 |
# File 'lib/luit.rb', line 211 def initialize(holder, id, x, y, text, w = 0, h = 0) h = [50, h].max @text = text @buttonColor = LUIT.uiColor @font = Gosu::Font.new(h - 20) @textW = @font.text_width(@text) w = @textW + 20 if w < @textW + 20 super(holder, id, x, y, w, h) end |
Instance Method Details
#draw(x = 0, y = 0) ⇒ Object
221 222 223 224 |
# File 'lib/luit.rb', line 221 def draw(x = 0, y = 0) Gosu::draw_rect(x + @x, y + @y, @w, @h, @hover ? LUIT.uiColorLight : LUIT.uiColor, LUIT.z) @font.draw_rel(@text, @x + x + @w / 2, @y + y + @h / 2, LUIT.z + 1, 0.5, 0.5) end |
#update(x = 0, y = 0) ⇒ Object
226 227 228 229 230 231 |
# File 'lib/luit.rb', line 226 def update(x = 0, y = 0) x += @x y += @y updateHover(x, y) super(x, y) end |