Class: LUIT::Toggle

Inherits:
LUITElement show all
Defined in:
lib/luit.rb

Instance Attribute Summary collapse

Attributes inherited from LUITElement

#h, #hover, #id, #w, #x, #y

Instance Method Summary collapse

Methods inherited from LUITElement

#draw_rel, #updateHover, #update_rel

Constructor Details

#initialize(holder, id, x, y, size = 30) ⇒ Toggle

Returns a new instance of Toggle.



305
306
307
308
309
310
311
# File 'lib/luit.rb', line 305

def initialize(holder, id, x, y, size = 30)
  h = [30, size].max
  w = h * 2
  super(holder, id, x, y, w, h)
  @buttonColor = LUIT.uiColor
  @value = false
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



304
305
306
# File 'lib/luit.rb', line 304

def value
  @value
end

Instance Method Details

#button_down(id) ⇒ Object



329
330
331
332
333
334
# File 'lib/luit.rb', line 329

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

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



313
314
315
316
317
318
319
# File 'lib/luit.rb', line 313

def draw(x = 0, y = 0)
  x += @x
  y += @y
  Gosu::draw_rect(x, y, @w, @h, @buttonColor, LUIT.z)
  @value ? v = 1 : v = 0
  Gosu::draw_rect(x + 4 + (@h * v), y + 4, @h - 8, @h - 8, @value ? 0xff_ffffff : 0xff_000000, LUIT.z + 1)
end

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



321
322
323
324
325
326
327
# File 'lib/luit.rb', line 321

def update(x = 0, y = 0)
  x += @x
  y += @y
  updateHover(x, y)
  @buttonColor = @hover ? LUIT.uiColorLight : LUIT.uiColor
  super
end