|parrotcode: base class for application-specific SDL event handlers|
|Contents | Libraries|
SDL::EventHandler - base class for application-specific SDL event handlers
# load the event class and this library load_bytecode 'library/SDL/Event.pir' load_bytecode 'library/SDL/EventHandler.pir' # subclass this class .local pmc parent_class .local pmc class_type getclass parent_class, 'SDL::EventHandler' subclass class_type, parent_class, 'My::Event::Handler' # define your overridden methods .sub key_down_down method .param pmc event .param pmc event_args # ... .end # create an event handler object .local pmc event_handler .local int handler_type find_type handler_type, 'My::Event::Handler' event_handler = new handler_type # create and populate some event_arguments .local pmc event_args new event_args, .PerlHash event_args[ 'main_surface' ] = main_surface event_args[ 'sprite_list' ] = sprites # create a new event object .local pmc event .local int event_type find_type event_type, 'SDL::Event' event = new event_type # ... and wait for events event.wait_event( event_handler, handler_args )
SDL::EventHandler is a parent class for all event handlers in SDL Parrot programs. Subclass this class and override the methods that correspond to the events you want to handle.
SDL::EventHandler provides the following methods:
key_down_keynamemethod, if one exists. Otherwise, does nothing.
key_upkeynamemethod, if one exists. Otherwise, does nothing.
Key event methods have names of the form
key_eventtype_keyname. That is, to handle a key down event for the Escape key, override the method
key_down_escape. Key names follow the SDL naming convention, except that key names are in all lowercase.
Unless you override
key_up and do something different, all of these methods will receive one argument, the
event_args hash passed to
SDL::Event::wait_event(). Use this hash to store and to retrieve data between events, particularly your main surface and any sprites or other surfaces.
In addition, you can override the following methods to handle their event types.
By default, these methods do nothing. They all take two arguments, the SDL::Event object representing the incoming event and the
event_args hash storing data between events.
At the very least, you should override
Written and maintained by chromatic, <chromatic at wgz dot org>. Designed by Allison Randal. Please send patches, feedback, and suggestions to the Perl 6 Internals mailing list.
Copyright (c) 2004, The Perl Foundation.