Module: OrangeZest::Input
- Defined in:
- lib/orange_zest/input.rb
Overview
Holds some input state so that it can be globally accessed.
In Gosu, the mouse cursor position is only available to the Gosu::Window, which makes it tricky to break the UI into components. This module stores and shares the cursor position for global access.
Class Method Summary collapse
-
.button_down(id) ⇒ Object
Should be called from your ‘Gosu::Window#button_down` implementation.
-
.clear_click ⇒ Object
Clears the click registered this frame, if any.
-
.click? ⇒ Boolean
Whether the left mouse button was clicked this frame.
-
.cursor ⇒ Object
The mouse cursor position within the window.
-
.update(window) ⇒ Object
Should be called from your ‘Gosu::Window’#update` implementation.
Class Method Details
.button_down(id) ⇒ Object
Should be called from your ‘Gosu::Window#button_down` implementation. Updates .click?.
10 11 12 |
# File 'lib/orange_zest/input.rb', line 10 def self.(id) @click = (id == Gosu::MS_LEFT) end |
.clear_click ⇒ Object
Clears the click registered this frame, if any. This can be used to ensure that a click is only seen by one UI element.
33 34 35 |
# File 'lib/orange_zest/input.rb', line 33 def self.clear_click @click = false end |
.click? ⇒ Boolean
Whether the left mouse button was clicked this frame. Even if the mouse is held down, this will only be true for the first frame of the click.
27 28 29 |
# File 'lib/orange_zest/input.rb', line 27 def self.click? @click end |
.cursor ⇒ Object
The mouse cursor position within the window.
21 22 23 |
# File 'lib/orange_zest/input.rb', line 21 def self.cursor @cursor end |
.update(window) ⇒ Object
Should be called from your ‘Gosu::Window’#update` implementation. Updates .cursor.
16 17 18 |
# File 'lib/orange_zest/input.rb', line 16 def self.update(window) @cursor = Point.new(window.mouse_x, window.mouse_y) end |