Index


NAME

Top

SDL::Event - General event structure

SYNOPSIS

Top

 use SDL::Event;                             # for the event object itself
 use SDL::Events qw(pump_events poll_event); # functions for event queue handling

 SDL::init(SDL_INIT_VIDEO);
 my $event = SDL::Event->new();

 while(1)
 {
     pump_events();

     if(poll_event($event))
     {
        if($event->type == SDL_MOUSEBUTTONDOWN)
        {
            # now you can handle the details
            $event->button_which;
            $event->button_button;
            $event->button_x;
            $event->button_y;
        }

        last if $event->type == SDL_QUIT;
     }

     # your screen drawing code will be here
 }

DESCRIPTION

Top

Event handling allows your application to receive input from the user. Event handling is initalised (along with video) with a call to:

SDL::init(SDL_INIT_VIDEO);

Internally, SDL stores all the events waiting to be handled in an event queue. Using functions like SDL::Events::poll_event(), SDL::Events::peep_events and SDL::Events::wait_event() you can observe and handle waiting input events.

The key to event handling in SDL is the SDL::Event union. The event queue itself is composed of a series of SDL::Event unions, one for each waiting event. SDL::Event unions are read from the queue with the SDL::Events::poll_event() function and it is then up to the application to process the information stored with them.

METHODS

Top

new

new creates an empty event-object, which can be used store information. Either by calling poll_event($event) that transferes one event from the queue into our object or by setting all the needed data manually in order to push the event to the queue.

 use SDL::Event;

 my $event = SDL::Event->new();

type

SDL::Event is a union of all event structures used in SDL, using it is a simple matter of knowing which union member relates to which event type.

 print 'heureka' if $event->type = SDL_MOUSEBUTTONDOWN;

Available type constants:

TODO: SDL_EVENTMASK()

active

active is a member of the SDL::Event union and is used when an event of type SDL_ACTIVEEVENT is reported.

When the mouse leaves or enters the window area a SDL_APPMOUSEFOCUS type activation event occurs, if the mouse entered the window then gain will be 1, otherwise gain will be 0.

A SDL_APPINPUTFOCUS type activation event occurs when the application loses or gains keyboard focus. This usually occurs when another application is made active.

Finally, a SDL_APPACTIVE type event occurs when the application is either minimised/iconified (gain=0) or restored.

A single event can have multiple values set in state.

Note: This event does not occur when an application window is first created.

A new ActiveEvent (to fake focus loss) will be created like this:

 my $event = SDL::Event->new();
    $event->type(SDL_ACTIVEEVENT);
    $event->active_gain(0);
    $event->active_state(SDL_APPMOUSEFOCUS);

 # I think this is wrong, ->active_type() should get SDL_APPMOUSEFOCUS, but what state gets?

active_type

active_gain

active_state

key

key_type

key_state

key_keysym

key_scancode

key_sym

key_mod

key_unicode

motion

motion_type

motion_state

motion_x, motion_y

motion_xrel, motion_yrel

button

button_type

button_which

button_button

button_state

button_x, button_y

jaxis

jaxis_type

jaxis_which

jaxis_axis

jaxis_value

jbutton

jbutton_type

jbutton_which

jbutton_button

jbutton_state

jhat

jhat_type

jhat_which

jhat_hat

jhat_value

jball

jball_type

jball_which

jball_ball

jball_xrel, jball_yrel

resize

resize_type

resize_x, resize_y

expose

expose_type

syswm

syswm_type

syswm_msg

user

user_type

user_code

user_data1, user_data2

quit

quit_type

Create a new SDL::Event object.

AUTHOR

Top

SEE ALSO

Top

perl