Class: SDC::Button

Inherits:
Object
  • Object
show all
Defined in:
lib/core/Button.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shape: nil, texture_id: nil, text: nil, &function) ⇒ Button

Returns a new instance of Button.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/core/Button.rb', line 8

def initialize(shape: nil, texture_id: nil, text: nil, &function)
	@shape = shape

	# TODO: Texture and text processing
	# TODO: Determine shape from texture if not given directly? Maybe not?
	
	# Call function if given, as long as the button is actually touched by the mouse.
	# Put this in an event handler for right and left clicks to trigger this only if clicked.
	# Preferably, this should only be used for prototyping.
	# For a more sophisticated event handling, use on_mouse_touch.
	function&.call if touched_by_mouse?
end

Instance Attribute Details

#shapeObject

Returns the value of attribute shape.



6
7
8
# File 'lib/core/Button.rb', line 6

def shape
  @shape
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/core/Button.rb', line 6

def text
  @text
end

#texture_idObject

Returns the value of attribute texture_id.



6
7
8
# File 'lib/core/Button.rb', line 6

def texture_id
  @texture_id
end

Instance Method Details

#drawObject



31
32
33
# File 'lib/core/Button.rb', line 31

def draw
	# TODO
end

#on_mouse_touch(&function) ⇒ Object



21
22
23
# File 'lib/core/Button.rb', line 21

def on_mouse_touch(&function)
	function&.call if touched_by_mouse?
end

#touched_by_mouse?Boolean

TODO: Clicking is wonky, maybe this can be handled better

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/core/Button.rb', line 26

def touched_by_mouse?
	return false if !@shape
	return SDC.mouse_touching?(@shape)
end