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.



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

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.



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

def value
  @value
end

Instance Method Details

#button_down(id) ⇒ Object



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

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

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



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

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



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

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