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.
Raised events
-
quit
-
focus_gain(focus_type)
-
mouse_motion(rect), where [rect.x, rect.y] is where the user clicked.
-
mouse_press(button, rect)
-
mouse_release(button, rect)
-
key_press(key, mod_keys)
-
key_release(key, mod_keys)
-
window_resize(rect), where [rect.w, rect.h] is the size of the window.
-
joy_motion(joystick_id, axis_id, axis_value)
-
joy_press(joystick_id, button_id)
-
joy_release(joystick_id, button_id)
Constant Summary collapse
- FOCUS_TYPES =
{ Ray::Event::APPMOUSEFOCUS => :mouse_focus, Ray::Event::APPINPUTFOCUS => :input_focus, Ray::Event::APPACTIVE => :app_activity }
- MOUSE_BUTTONS =
{ Ray::Event::BUTTON_LEFT => :left, Ray::Event::BUTTON_MIDDLE => :middle, Ray::Event::BUTTON_RIGHT => :right, Ray::Event::BUTTON_WHEELUP => :wheel_up, Ray::Event::BUTTON_WHEELDOWN => :wheel_down }
Class Method Summary collapse
- .active_event(ev) ⇒ Object
- .joy_motion(ev) ⇒ Object
- .joy_press(ev) ⇒ Object
- .joy_release(ev) ⇒ Object
- .key_press(ev) ⇒ Object
- .key_release(ev) ⇒ Object
- .mouse_motion(ev) ⇒ Object
- .mouse_press(ev) ⇒ Object
- .mouse_release(ev) ⇒ Object
- .quit(ev) ⇒ Object
- .resize(ev) ⇒ Object
-
.translate_event(ev) ⇒ Array
The arguments you should pass to raise_event.
Class Method Details
.active_event(ev) ⇒ Object
57 58 59 60 |
# File 'lib/ray/dsl/event_translator.rb', line 57 def active_event(ev) [[ev.is_gain? ? :focus_gain : :focus_loss, FOCUS_TYPES[ev.focus_state]]] end |
.joy_motion(ev) ⇒ Object
90 91 92 |
# File 'lib/ray/dsl/event_translator.rb', line 90 def joy_motion(ev) [[:joy_motion, ev.joystick_id, ev.axis_id, ev.axis_value]] end |
.joy_press(ev) ⇒ Object
94 95 96 |
# File 'lib/ray/dsl/event_translator.rb', line 94 def joy_press(ev) [[:joy_press, ev.joystick_id, ev.]] end |
.joy_release(ev) ⇒ Object
98 99 100 |
# File 'lib/ray/dsl/event_translator.rb', line 98 def joy_release(ev) [[:joy_release, ev.joystick_id, ev.]] end |
.key_press(ev) ⇒ Object
78 79 80 |
# File 'lib/ray/dsl/event_translator.rb', line 78 def key_press(ev) [[:key_press, ev.key, ev.mod_keys]] end |
.key_release(ev) ⇒ Object
82 83 84 |
# File 'lib/ray/dsl/event_translator.rb', line 82 def key_release(ev) [[:key_release, ev.key, ev.mod_keys]] end |
.mouse_motion(ev) ⇒ Object
62 63 64 |
# File 'lib/ray/dsl/event_translator.rb', line 62 def mouse_motion(ev) [[:mouse_motion, Ray::Rect.new(ev.mouse_x, ev.mouse_y)]] end |
.mouse_press(ev) ⇒ Object
66 67 68 69 70 |
# File 'lib/ray/dsl/event_translator.rb', line 66 def mouse_press(ev) [[:mouse_press, MOUSE_BUTTONS[ev.], Ray::Rect.new(ev.mouse_x, ev.mouse_y)]] end |
.mouse_release(ev) ⇒ Object
72 73 74 75 76 |
# File 'lib/ray/dsl/event_translator.rb', line 72 def mouse_release(ev) [[:mouse_release, MOUSE_BUTTONS[ev.], Ray::Rect.new(ev.mouse_x, ev.mouse_y)]] end |
.quit(ev) ⇒ Object
53 54 55 |
# File 'lib/ray/dsl/event_translator.rb', line 53 def quit(ev) [[:quit]] end |
.resize(ev) ⇒ Object
86 87 88 |
# File 'lib/ray/dsl/event_translator.rb', line 86 def resize(ev) [[:window_resize, Ray::Rect.new(0, 0, ev.window_w, ev.window_h)]] end |
.translate_event(ev) ⇒ Array
Returns The arguments you should pass to raise_event.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ray/dsl/event_translator.rb', line 35 def translate_event(ev) case ev.type when Ray::Event::TYPE_NOEVENT then [] when Ray::Event::TYPE_QUIT then quit(ev) when Ray::Event::TYPE_ACTIVEEVENT then active_event(ev) when Ray::Event::TYPE_MOUSEMOTION then mouse_motion(ev) when Ray::Event::TYPE_MOUSEBUTTONDOWN then mouse_press(ev) when Ray::Event::TYPE_MOUSEBUTTONUP then mouse_release(ev) when Ray::Event::TYPE_KEYDOWN then key_press(ev) when Ray::Event::TYPE_KEYUP then key_release(ev) when Ray::Event::TYPE_VIDEORESIZE then resize(ev) when Ray::Event::TYPE_JOYAXISMOTION then joy_motion(ev) when Ray::Event::TYPE_JOYBUTTONDOWN then joy_press(ev) when Ray::Event::TYPE_JOYBUTTONUP then joy_release(ev) else [] end end |