Module: Rubydraw::Events

Defined in:
lib/rubydraw/events.rb

Overview

A module containing Rubydraw events and their SDL event “bindings”.

Defined Under Namespace

Classes: Event, FocusEvent, FocusGain, FocusLoss, KeyPressed, KeyReleased, KeyboardEvent, MouseButtonEvent, MouseMove, MousePressed, MouseReleased, QuitRequest, UnknownEvent, WindowResize

Class Method Summary collapse

Class Method Details

.match(sdl_event) ⇒ Object

Translate the given SDL event to its corresponding Rubydraw event, by asking each event class if it matches the SDL event. No case statements here.



22
23
24
25
26
27
28
29
# File 'lib/rubydraw/events.rb', line 22

def self.match(sdl_event)
  event_classes = Event.all_subclasses.compact
  rubydraw_event = UnknownEvent.new(sdl_event)
  # Remove all the classes that don't want to be included in the search
  event_classes.delete_if {|event_class| not event_class.wants_to_match?}
  event_classes.each {|event_class| rubydraw_event = event_class.from_sdl_event(sdl_event) if event_class.matches?(sdl_event)}
  rubydraw_event
end