Module: Mouse
- Defined in:
- scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb
Overview
Module responsive of giving global state of mouse Inputs
The buttons of the mouse are : :LEFT, :MIDDLE, :RIGHT, :X1, :X2
Constant Summary collapse
- BUTTON_MAPPING =
Mapping between button & symbols
{ Sf::Mouse::LEFT => :LEFT, Sf::Mouse::RIGHT => :RIGHT, Sf::Mouse::Middle => :MIDDLE, Sf::Mouse::XButton1 => :X1, Sf::Mouse::XButton2 => :X2 }
- BUTTON_ALIAS =
List of alias button
{ left: :LEFT, right: :RIGHT, middle: :MIDDLE }
Class Attribute Summary collapse
-
.moved ⇒ Boolean
readonly
Get if the mouse moved since last frame.
-
.wheel ⇒ Integer
Mouse wheel position.
-
.wheel_delta ⇒ Integer
readonly
Mouse wheel delta.
-
.x ⇒ Integer
readonly
Get the mouse x position.
-
.y ⇒ Integer
readonly
Get the mouse y position.
Class Method Summary collapse
-
.in? ⇒ Boolean
Tell if the mouse is in the screen.
-
.press?(button) ⇒ Boolean
Tell if a button is pressed on the mouse.
-
.register_events(window)
Register event related to the mouse.
-
.released?(button) ⇒ Boolean
Tell if a button was released on the mouse.
-
.swap_states
Swap the state of the mouse.
-
.trigger?(button) ⇒ Boolean
Tell if a button was triggered on the mouse.
Class Attribute Details
.moved ⇒ Boolean (readonly)
Get if the mouse moved since last frame
59 60 61 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 59 def moved @moved end |
.wheel ⇒ Integer
Mouse wheel position
47 48 49 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 47 def wheel @wheel end |
.wheel_delta ⇒ Integer (readonly)
Mouse wheel delta
50 51 52 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 50 def wheel_delta @wheel_delta end |
.x ⇒ Integer (readonly)
Get the mouse x position
53 54 55 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 53 def x @x end |
.y ⇒ Integer (readonly)
Get the mouse y position
56 57 58 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 56 def y @y end |
Class Method Details
.in? ⇒ Boolean
Tell if the mouse is in the screen
87 88 89 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 87 def in? return @in_screen end |
.press?(button) ⇒ Boolean
Tell if a button is pressed on the mouse
64 65 66 67 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 64 def press?() = BUTTON_ALIAS[] || return @current_state[] end |
.register_events(window)
Register event related to the mouse
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 100 def register_events(window) return if Configs.devices.is_mouse_disabled window.on_touch_began = proc { |finger_id, x, y| on_mouse_entered on_mouse_moved(x, y) (Sf::Mouse::LEFT) } window.on_touch_moved = proc { |finger, x, y| on_mouse_moved(x, y) } window.on_touch_ended = proc { |finger_id, x, y| (Sf::Mouse::LEFT) on_mouse_moved(x, y) on_mouse_left } window.on_mouse_wheel_scrolled = proc { |wheel, delta| on_wheel_scrolled(wheel, delta) } window. = proc { || () } window. = proc { || () } window.on_mouse_moved = proc { |x, y| on_mouse_moved(x, y) } window.on_mouse_entered = proc { on_mouse_entered } window.on_mouse_left = proc { on_mouse_left } end |
.released?(button) ⇒ Boolean
Tell if a button was released on the mouse
80 81 82 83 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 80 def released?() = BUTTON_ALIAS[] || return @last_state[] && !@current_state[] end |
.swap_states
Swap the state of the mouse
92 93 94 95 96 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 92 def swap_states @last_state.merge!(@current_state) @moved = false @wheel_delta = 0 end |
.trigger?(button) ⇒ Boolean
Tell if a button was triggered on the mouse
72 73 74 75 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 72 def trigger?() = BUTTON_ALIAS[] || return @current_state[] && !@last_state[] end |