Class: SDL::Event

Inherits:
FFI::Union
  • Object
show all
Defined in:
lib/ruby-sdl-ffi/sdl/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap(event) ⇒ Object

Creates a generic Event containing a specific event. You usually don’t need to do this, because you can pass specific events directly to SDL::SDL_PushEvent.



213
214
215
# File 'lib/ruby-sdl-ffi/sdl/event.rb', line 213

def self.wrap( event )
  self.new( event.pointer )
end

Instance Method Details

#inspectObject



245
246
247
# File 'lib/ruby-sdl-ffi/sdl/event.rb', line 245

def inspect
  super.gsub(">", " :type=#{self[:type]}>")
end

#unwrapObject

Extracts a specific event class from a generic Event.



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/ruby-sdl-ffi/sdl/event.rb', line 219

def unwrap
  case self[:type]
  when ACTIVEEVENT;       ActiveEvent.new(self.pointer)
  when KEYDOWN, KEYUP;    KeyboardEvent.new(self.pointer)
  when MOUSEMOTION;       MouseMotionEvent.new(self.pointer)

  when MOUSEBUTTONDOWN, MOUSEBUTTONUP;
                          MouseButtonEvent.new(self.pointer)

  when JOYAXISMOTION;     JoyAxisEvent.new(self.pointer)
  when JOYBALLMOTION;     JoyBallEvent.new(self.pointer)
  when JOYHATMOTION;      JoyHatEvent.new(self.pointer)

  when JOYBUTTONDOWN, JOYBUTTONUP;
                          JoyButtonEvent.new(self.pointer)

  when QUIT;              QuitEvent.new( self.pointer )
  when SYSWMEVENT;        SysWMEvent.new( self.pointer )
  when VIDEORESIZE;       ResizeEvent.new( self.pointer )
  when VIDEOEXPOSE;       ExposeEvent.new( self.pointer )
  when USEREVENT;         UserEvent.new( self.pointer )

  else; raise TypeError, "Invalid event #{self.inspect}"
  end
end