Class: SDC::Button
- Inherits:
-
Object
- Object
- SDC::Button
- Defined in:
- lib/core/Button.rb
Instance Attribute Summary collapse
-
#shape ⇒ Object
Returns the value of attribute shape.
-
#text ⇒ Object
Returns the value of attribute text.
-
#texture_id ⇒ Object
Returns the value of attribute texture_id.
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(shape: nil, texture_id: nil, text: nil, &function) ⇒ Button
constructor
A new instance of Button.
- #on_mouse_touch(&function) ⇒ Object
-
#touched_by_mouse? ⇒ Boolean
TODO: Clicking is wonky, maybe this can be handled better.
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
#shape ⇒ Object
Returns the value of attribute shape.
6 7 8 |
# File 'lib/core/Button.rb', line 6 def shape @shape end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/core/Button.rb', line 6 def text @text end |
#texture_id ⇒ Object
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
#draw ⇒ Object
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
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 |