Module: Ray::DSL::EventTranslator
- Defined in:
- lib/ray/dsl/event_translator.rb
Overview
Module charged to translate an instance of Ray::Event into the arguments you pass to raise_event. It is for instance used in Ray::Scene.
Unless otherwise mentionned, points and sizes are Ray::Vector2 and rects Ray::Rect.
Raised events
-
quit
-
focus_gain
-
focus_loss
-
mouse_entered
-
mouse_left
-
mouse_motion(pos)
-
wheel_motion(pos, delta)
-
mouse_press(button, pos)
-
mouse_release(button, pos)
-
key_press(key, mod_keys, native_key)
-
key_release(key, mod_keys, native_key)
-
window_resize(size)
Constant Summary collapse
- MOUSE_BUTTONS =
{ Ray::Event::ButtonLeft => :left, Ray::Event::ButtonMiddle => :middle, Ray::Event::ButtonRight => :right, Ray::Event::ButtonUnknown => :unknown }
Class Method Summary collapse
- .focus_gain(ev) ⇒ Object
- .focus_loss(ev) ⇒ Object
- .key_press(ev) ⇒ Object
- .key_release(ev) ⇒ Object
- .mouse_entered(ev) ⇒ Object
- .mouse_left(ev) ⇒ Object
- .mouse_motion(ev) ⇒ Object
- .mouse_press(ev) ⇒ Object
- .mouse_release(ev) ⇒ Object
- .quit(ev) ⇒ Object
- .resize(ev) ⇒ Object
- .text_entered(ev) ⇒ Object
-
.translate_event(ev) ⇒ Array
The arguments you should pass to raise_event.
- .wheel_motion(ev) ⇒ Object
Class Method Details
.focus_gain(ev) ⇒ Object
55 56 57 |
# File 'lib/ray/dsl/event_translator.rb', line 55 def focus_gain(ev) [:focus_gain] end |
.focus_loss(ev) ⇒ Object
59 60 61 |
# File 'lib/ray/dsl/event_translator.rb', line 59 def focus_loss(ev) [:focus_loss] end |
.key_press(ev) ⇒ Object
91 92 93 |
# File 'lib/ray/dsl/event_translator.rb', line 91 def key_press(ev) [:key_press, ev.key, ev.key_mod, ev.native_key] end |
.key_release(ev) ⇒ Object
95 96 97 |
# File 'lib/ray/dsl/event_translator.rb', line 95 def key_release(ev) [:key_release, ev.key, ev.key_mod, ev.native_key] end |
.mouse_entered(ev) ⇒ Object
63 64 65 |
# File 'lib/ray/dsl/event_translator.rb', line 63 def mouse_entered(ev) [:mouse_entered] end |
.mouse_left(ev) ⇒ Object
67 68 69 |
# File 'lib/ray/dsl/event_translator.rb', line 67 def mouse_left(ev) [:mouse_left] end |
.mouse_motion(ev) ⇒ Object
71 72 73 |
# File 'lib/ray/dsl/event_translator.rb', line 71 def mouse_motion(ev) [:mouse_motion, ev.mouse_pos] end |
.mouse_press(ev) ⇒ Object
79 80 81 82 83 |
# File 'lib/ray/dsl/event_translator.rb', line 79 def mouse_press(ev) [:mouse_press, MOUSE_BUTTONS[ev.], ev.mouse_pos] end |
.mouse_release(ev) ⇒ Object
85 86 87 88 89 |
# File 'lib/ray/dsl/event_translator.rb', line 85 def mouse_release(ev) [:mouse_release, MOUSE_BUTTONS[ev.], ev.mouse_pos] end |
.quit(ev) ⇒ Object
51 52 53 |
# File 'lib/ray/dsl/event_translator.rb', line 51 def quit(ev) [:quit] end |
.resize(ev) ⇒ Object
99 100 101 |
# File 'lib/ray/dsl/event_translator.rb', line 99 def resize(ev) [:window_resize, ev.window_size] end |
.text_entered(ev) ⇒ Object
103 104 105 |
# File 'lib/ray/dsl/event_translator.rb', line 103 def text_entered(ev) [:text_entered, ev.text] end |
.translate_event(ev) ⇒ Array
Returns The arguments you should pass to raise_event.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ray/dsl/event_translator.rb', line 33 def translate_event(ev) case ev.type when Ray::Event::TypeQuit then quit(ev) when Ray::Event::TypeFocusGain then focus_gain(ev) when Ray::Event::TypeFocusLoss then focus_loss(ev) when Ray::Event::TypeMouseEntered then mouse_entered(ev) when Ray::Event::TypeMouseLeft then mouse_left(ev) when Ray::Event::TypeMouseMotion then mouse_motion(ev) when Ray::Event::TypeWheelMotion then wheel_motion(ev) when Ray::Event::TypeButtonPress then mouse_press(ev) when Ray::Event::TypeButtonRelease then mouse_release(ev) when Ray::Event::TypeKeyRelease then key_release(ev) when Ray::Event::TypeKeyPress then key_press(ev) when Ray::Event::TypeResize then resize(ev) when Ray::Event::TypeTextEntered then text_entered(ev) end end |
.wheel_motion(ev) ⇒ Object
75 76 77 |
# File 'lib/ray/dsl/event_translator.rb', line 75 def wheel_motion(ev) [:wheel_motion, ev.mouse_pos, ev.wheel_delta] end |