Module: Rubygame::Events

Defined in:
lib/rubygame/events.rb,
lib/rubygame/events/misc_events.rb,
lib/rubygame/events/clock_events.rb,
lib/rubygame/events/mouse_events.rb,
lib/rubygame/events/joystick_events.rb,
lib/rubygame/events/keyboard_events.rb,
ext/rubygame/rubygame_event2.c

Overview

The Events module contains classes representing various hardware events (e.g. keyboard presses, mouse clicks) and software events (e.g. clock tick, window becomes active)

This event classes are meant as a full replacement for the older event classes defined in the Rubygame module (e.g. KeyDownEvent, QuitEvent). The old classes are deprecated and should not be used anymore.

Defined Under Namespace

Modules: JoystickButtonEvent, KeyboardEvent, MouseButtonEvent Classes: ClockTicked, InputFocusGained, InputFocusLost, JoystickAxisMoved, JoystickBallMoved, JoystickButtonPressed, JoystickButtonReleased, JoystickHatMoved, KeyPressed, KeyReleased, MouseFocusGained, MouseFocusLost, MouseMoved, MousePressed, MouseReleased, QuitRequested, WindowExposed, WindowMinimized, WindowResized, WindowUnminimized

Class Method Summary collapse

Class Method Details

.fetch_sdl_eventsArray

NOTE: This method converts the SDL events into the new-style event classes, located in the Rubygame::Events module. For converting to the older (deprecated) events, see Rubygame.fetch_sdl_events.

Retrieves all pending events from SDL’s event stack and converts them into Rubygame event objects. Returns an Array of all the events, in the order they were read.

This method is used by the EventQueue class (among others), so don’t call it if you are using any of Rubygame’s event management classes (e.g. EventQueue)! If you do, they will not receive all the events, because some events will have been removed from SDL’s event stack by this method.

However, if you aren’t using EventQueue, you can safely use this method to make your own event management system.

Returns:

  • (Array)


623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'ext/rubygame/rubygame_event2.c', line 623

VALUE rg_fetch_sdl_events2( VALUE module )
{
  SDL_Event event;
  VALUE events = rb_ary_new();
  VALUE thing;

  while(SDL_PollEvent(&event)==1) 
  {
    /* Either an event or array of zero or more events. */
    thing = rg_convert_sdlevent2( event );

    if( TYPE(thing) == T_ARRAY )
    {
      rb_ary_concat( events, thing );
    }
    else
    {
      rb_ary_push( events, thing );
    }
  }

  return events;
}