Class: Moon::Input

Inherits:
Object show all
Defined in:
lib/moon/packages/std/input.rb,
lib/moon/packages/std/input/observer.rb

Overview

Input extension for using Moon::Events

Defined Under Namespace

Classes: Mouse, Observer

Instance Method Summary collapse

Instance Method Details

#on_button(button, action, mods) ⇒ Object


27
28
29
# File 'lib/moon/packages/std/input.rb', line 27

def on_button(button, action, mods)
  trigger MouseInputEvent.new(button, action, mods, @mouse.position)
end

#on_key(key, _, action, mods) ⇒ Object


23
24
25
# File 'lib/moon/packages/std/input.rb', line 23

def on_key(key, _, action, mods)
  trigger KeyboardInputEvent.new(key, action, mods)
end

#on_mousemove(x, y) ⇒ Object


35
36
37
# File 'lib/moon/packages/std/input.rb', line 35

def on_mousemove(x, y)
  trigger MouseMoveEvent.new(x, y, @engine.screen.rect)
end

#on_type(char) ⇒ Object


31
32
33
# File 'lib/moon/packages/std/input.rb', line 31

def on_type(char)
  trigger KeyboardTypingEvent.new(char)
end

#register(channel) ⇒ Object


9
10
11
# File 'lib/moon/packages/std/input.rb', line 9

def register(channel)
  channels.push channel
end

#trigger(event) ⇒ Object


17
18
19
20
21
# File 'lib/moon/packages/std/input.rb', line 17

def trigger(event)
  channels.each do |channel|
    channel.call event
  end
end

#unregister(channel) ⇒ Object


13
14
15
# File 'lib/moon/packages/std/input.rb', line 13

def unregister(channel)
  channels.delete channel
end