Module: Ruby2D::Window::MouseEvents
- Included in:
- Ruby2D::Window
- Defined in:
- lib/ruby2d/window/mouse_events.rb
Overview
Mouse input event handling
Instance Method Summary collapse
-
#mouse_callback(type, button, direction, x, y, delta_x, delta_y) ⇒ Object
Mouse callback method, called by the native and web extentions.
-
#mouse_held?(btn) ⇒ Boolean
Mouse held event method for class pattern.
-
#mouse_inside? ⇒ Boolean
True while the cursor is over the window.
-
#mouse_move_delta_x ⇒ Object
Get the mouse move delta x.
-
#mouse_move_delta_y ⇒ Object
Get the mouse move delta y.
-
#mouse_moved? ⇒ Boolean
Mouse move event method for class pattern.
-
#mouse_position ⇒ Object
Current mouse position as a [x, y] pair, for the common case where both coordinates are needed together.
-
#mouse_pressed?(btn) ⇒ Boolean
Mouse down event method for class pattern.
-
#mouse_released?(btn) ⇒ Boolean
Mouse up event method for class pattern.
-
#mouse_scroll_delta_x ⇒ Object
Get the scroll delta x.
-
#mouse_scroll_delta_y ⇒ Object
Get the scroll delta y.
-
#mouse_scroll_direction ⇒ Object
Get the scroll direction.
-
#mouse_scrolled? ⇒ Boolean
Mouse scroll event method for class pattern.
Instance Method Details
#mouse_callback(type, button, direction, x, y, delta_x, delta_y) ⇒ Object
Mouse callback method, called by the native and web extentions
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ruby2d/window/mouse_events.rb', line 70 def mouse_callback(type, , direction, x, y, delta_x, delta_y) # All mouse events fire_event_handlers(:mouse) { MouseEvent.new(type, , direction, x, y, delta_x, delta_y) } case type # When mouse button pressed when :down handle_mouse_down type, , x, y # When mouse button released when :up handle_mouse_up type, , x, y # When mouse button is being held down, fired every frame when :held handle_mouse_held type, , x, y # When mouse scrolling, wheel or trackpad when :scroll handle_mouse_scroll type, direction, delta_x, delta_y # When mouse motion / movement when :move handle_mouse_move type, x, y, delta_x, delta_y # When cursor enters the window when :enter handle_mouse_enter type # When cursor leaves the window when :leave handle_mouse_leave type end end |
#mouse_held?(btn) ⇒ Boolean
Mouse held event method for class pattern
18 19 20 |
# File 'lib/ruby2d/window/mouse_events.rb', line 18 def mouse_held?(btn) @mouse_buttons_held.include? btn end |
#mouse_inside? ⇒ Boolean
True while the cursor is over the window. Toggles on :mouse_enter / :mouse_leave; starts false until SDL reports the first enter event.
30 31 32 |
# File 'lib/ruby2d/window/mouse_events.rb', line 30 def mouse_inside? @mouse_inside end |
#mouse_move_delta_x ⇒ Object
Get the mouse move delta x
60 61 62 |
# File 'lib/ruby2d/window/mouse_events.rb', line 60 def mouse_move_delta_x @mouse_move_delta_x end |
#mouse_move_delta_y ⇒ Object
Get the mouse move delta y
65 66 67 |
# File 'lib/ruby2d/window/mouse_events.rb', line 65 def mouse_move_delta_y @mouse_move_delta_y end |
#mouse_moved? ⇒ Boolean
Mouse move event method for class pattern
55 56 57 |
# File 'lib/ruby2d/window/mouse_events.rb', line 55 def mouse_moved? @mouse_move_event end |
#mouse_position ⇒ Object
Current mouse position as a [x, y] pair, for the common case where both coordinates are needed together.
24 25 26 |
# File 'lib/ruby2d/window/mouse_events.rb', line 24 def mouse_position [@mouse_x, @mouse_y] end |
#mouse_pressed?(btn) ⇒ Boolean
Mouse down event method for class pattern
8 9 10 |
# File 'lib/ruby2d/window/mouse_events.rb', line 8 def mouse_pressed?(btn) @mouse_buttons_down.include? btn end |
#mouse_released?(btn) ⇒ Boolean
Mouse up event method for class pattern
13 14 15 |
# File 'lib/ruby2d/window/mouse_events.rb', line 13 def mouse_released?(btn) @mouse_buttons_up.include? btn end |
#mouse_scroll_delta_x ⇒ Object
Get the scroll delta x
45 46 47 |
# File 'lib/ruby2d/window/mouse_events.rb', line 45 def mouse_scroll_delta_x @mouse_scroll_delta_x end |
#mouse_scroll_delta_y ⇒ Object
Get the scroll delta y
50 51 52 |
# File 'lib/ruby2d/window/mouse_events.rb', line 50 def mouse_scroll_delta_y @mouse_scroll_delta_y end |
#mouse_scroll_direction ⇒ Object
Get the scroll direction
40 41 42 |
# File 'lib/ruby2d/window/mouse_events.rb', line 40 def mouse_scroll_direction @mouse_scroll_direction end |
#mouse_scrolled? ⇒ Boolean
Mouse scroll event method for class pattern
35 36 37 |
# File 'lib/ruby2d/window/mouse_events.rb', line 35 def mouse_scrolled? @mouse_scroll_event end |