Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

SDLmm::Event Class Reference

The general Event class. More...

#include <sdlmm_event.h>

List of all members.

Public Methods

bool Poll (bool fetch=true)
 Polls for currently pending events. More...

bool Wait (bool fetch=true)
 Waits indefinitely for the next available event. More...

bool Push ()
 Push this event onto the event queue. More...


Static Public Methods

Event Methods
void PumpEvents ()
 Pumps the event loop, gathering events from the input devices. More...

void SetEventFilter (SDL_EventFilter filter)
 Sets up a filter to process all events before they are posted to the event queue. More...

SDL_EventFilter GetEventFilter ()
 Retrieves a pointer to the event filter. More...

Uint8 EventState (Uint8 type, int state)
 Set the state of processing for certain events. More...

void HandleEvents (EventHandler &handler)
 Handle all queued events using the specified EventHandler. More...

void HandleEvent (EventHandler &handler, const SDL_Event &event)
 Handle a single event using the specified EventHandler. More...

Keyboard Methods
Uint8* GetKeyState (int &numkeys)
 Get a snapshot of the current keyboard state. More...

Uint8* GetKeyState ()
 Get a snapshot of the current keyboard state. More...

SDLMod GetModState ()
 Get the state of modifier keys. More...

void SetModState (SDLMod modstate)
 Set the current key modifier state. More...

char* GetKeyName (SDLKey key)
 Get the name of an SDL virtual key symbol. More...

bool EnableUNICODE (bool enable=true)
 Enable UNICODE keyboard translation. More...

bool DisableUNICODE ()
 Disable UNICODE translation. More...

bool QueryUNICODE ()
 Query the current UNICODE translation mode. More...

bool EnableKeyRepeat (int delay=SDL_DEFAULT_REPEAT_DELAY, int interval=SDL_DEFAULT_REPEAT_DELAY)
 Set keyboard repeat rate. More...

Mouse Methods
Uint8 GetMouseState (int *x=0, int *y=0)
 Retrieve the current state of the mouse. More...

Uint8 GetRelativeMouseState (int *x, int *y)
 Retrieve the current state of the mouse. More...

Other Methods
Uint8 GetAppState ()
 Get the state of the application. More...

int JoystickEventState (int state)
 Enable / disable joystick event polling. More...


Public Attributes

SDL_Event me
 The event structure. More...


Detailed Description

The general Event class.

The Event class is the core to all event handling is SDLmm. It's probably the most important class after Surface. The Event class can be used to store any type of event.

Definition at line 32 of file sdlmm_event.h.


Member Function Documentation

bool SDLmm::Event::DisableUNICODE ( ) [inline, static]
 

Disable UNICODE translation.

Returns:
true if UNICODE translation was previously enabled, false otherwise.
See also:
EnableUNICODE, QueryUNICODE

Definition at line 298 of file sdlmm_event.h.

bool SDLmm::Event::EnableKeyRepeat ( int delay = SDL_DEFAULT_REPEAT_DELAY,
int interval = SDL_DEFAULT_REPEAT_DELAY ) [static]
 

Set keyboard repeat rate.

Enables or disables the keyboard repeat rate. delay specifies how long the key must be pressed before it begins repeating. It then repeats at the speed specified by interval. Both delay and interval are expressed in milliseconds.

Setting delay to 0 disables key repeating completely. If called without parameters, the default values uses are SDL_DEFAULT_REPEAT_DELAY and SDL_DEFAULT_REPEAT_INTERVAL.

Returns:
true on success, false on failure.
Parameters:
delay   delay before key repeating starts in ms.
interval   delay between repeats in ms.

Definition at line 86 of file sdlmm_event.cpp.

bool SDLmm::Event::EnableUNICODE ( bool enable = true ) [inline, static]
 

Enable UNICODE keyboard translation.

If you wish to translate a keysym to it's printable representation, you need to enable UNICODE translation using this function and then look in the unicode member of the SDL_keysym structure. This value will be zero for keysyms that do not have a printable representation. UNICODE translation is disabled by default as the conversion can cause a slight overhead.

Parameters:
enable   if false, disable UNICODE translation (SDL compatibility)

Returns:
true if UNICODE translation was previously enabled, false otherwise.
See also:
DisableUNICODE, QueryUNICODE

Definition at line 290 of file sdlmm_event.h.

Uint8 SDLmm::Event::EventState ( Uint8 type,
int state ) [static]
 

Set the state of processing for certain events.

This function allows you to set the state of processing certain event types.

If state is set to SDL_IGNORE, that event type will be automatically dropped from the event queue and will not be filtered.

If state is set to SDL_ENABLE, that event type will be processed normally.

If state is set to SDL_QUERY, EventState() will return the current processing state of the specified event type.

A list of event types can be found in the SDL_Event section in the SDL documentation.

Parameters:
type   the event type
state   the state as documented above.
Returns:
the current processing state for the specified event type

Definition at line 62 of file sdlmm_event.cpp.

Uint8 SDLmm::Event::GetAppState ( ) [static]
 

Get the state of the application.

This function returns the current state of the application. The value returned is a bitwise combination of:

  • SDL_APPMOUSEFOCUS - the application has mouse focus.
  • SDL_APPINPUTFOCUS - the application has keyboard focus
  • SDL_APPACTIVE - the application is visible
Returns:
The current state of the application.

Definition at line 97 of file sdlmm_event.cpp.

SDL_EventFilter SDLmm::Event::GetEventFilter ( ) [static]
 

Retrieves a pointer to the event filter.

This function retrieves a pointer to the event filter that was previously set using SetEventFilter(). An SDL_EventFilter function is defined as:

      typedef int (*SDL_EventFilter)(const SDL_Event *event);
Returns:
Returns a pointer to the event filter or 0 if no filter has been set.
See also:
SetEventFilter()

Definition at line 58 of file sdlmm_event.cpp.

char * SDLmm::Event::GetKeyName ( SDLKey key ) [static]
 

Get the name of an SDL virtual key symbol.

Returns:
the SDL defined name of the key.
Parameters:
key   the SDLkey key symbol

Definition at line 78 of file sdlmm_event.cpp.

Uint8 * SDLmm::Event::GetKeyState ( ) [static]
 

Get a snapshot of the current keyboard state.

Same as the GetKeyState(int &numkeys) method, used when you don't care how many keys were returned (i.e you want to check the state of a key that is known to exist).

Example:
      Uint8 *keystate;
      keystate = Event::GetKeyState();
      if (keystate[SDLK_RETURN])
        cout << "Return Key Pressed.\n";
See also:
GetModState()

Definition at line 70 of file sdlmm_event.cpp.

Uint8 * SDLmm::Event::GetKeyState ( int & numkeys ) [static]
 

Get a snapshot of the current keyboard state.

Gets a snapshot of the current keyboard state. The current state is returned as a pointer to an array. The size of this array is stored in numkeys. The array is indexed by the SDLK_* symbols. A value of 1 means the key is pressed and a value of 0 means its not.

Note:
Use PumpEvents() to update the state array.
See also:
PumpEvents()
Parameters:
numkeys   a reference to an integer used to store the size of the returned array.

Definition at line 66 of file sdlmm_event.cpp.

SDLMod SDLmm::Event::GetModState ( ) [static]
 

Get the state of modifier keys.

Returns the current of the modifier keys (CTRL, ALT, etc.).

Returns:
The return value can be an OR'd combination of the SDLMod enum or one of the convenience defines:
  • KMOD_NONE
  • KMOD_LSHIFT
  • KMOD_RSHIFT
  • KMOD_LCTRL
  • KMOD_RCTRL
  • KMOD_LALT
  • KMOD_RALT
  • KMOD_LMETA
  • KMOD_RMETA
  • KMOD_NUM
  • KMOD_CAPS
  • KMOD_MODE
  • KMOD_CTRL (KMOD_LCTRL | KMOD_RCTRL)
  • KMOD_SHIFT (KMOD_LSHIFT | KMOD_RSHIFT)
  • KMOD_ALT (KMOD_LALT | KMOD_RALT)
  • KMOD_META (KMOD_LMETA | KMOD_RMETA)
See also:
SetModState(), GetModState()

Definition at line 74 of file sdlmm_event.cpp.

Uint8 SDLmm::Event::GetMouseState ( int * x = 0,
int * y = 0 ) [static]
 

Retrieve the current state of the mouse.

The current button state is returned as a button bitmask, which can be tested using the SDL_BUTTON(X) macros, and x and y are set to the current mouse cursor position. You can pass zero for either x or y.

Returns:
the button bitmask.
Parameters:
x, y   pointers to integers where the current mouse coordinates will be stored.

Definition at line 90 of file sdlmm_event.cpp.

Uint8 SDLmm::Event::GetRelativeMouseState ( int * x,
int * y ) [static]
 

Retrieve the current state of the mouse.

The current button state is returned as a button bitmask, which can be tested using the SDL_BUTTON(X) macros, and x and y are set to the change in the mouse position since the last call to SDL_GetRelativeMouseState or since event initialization. You can pass zero for either x or y.

Returns:
the button bitmask.
Parameters:
x, y   pointers to integers for mouse coordinates or relative change.

Definition at line 94 of file sdlmm_event.cpp.

void SDLmm::Event::HandleEvent ( EventHandler & handler,
const SDL_Event & event ) [static]
 

Handle a single event using the specified EventHandler.

This function calls the event callback methods. To actually handle any events, you need to create a derivate of the EventHandler class reimplementing the callbacks for the events you're interested in. See the EventHandler documentation for more details.

Parameters:
handler   the EventHandler which should handle the events.
event   the event to handle.
See also:
EventHandler

Definition at line 111 of file sdlmm_event.cpp.

Referenced by HandleEvents().

void SDLmm::Event::HandleEvents ( EventHandler & handler ) [static]
 

Handle all queued events using the specified EventHandler.

This function polls for active events and calls the event callback methods. To actually handle any events, you need to create a derivate of the EventHandler class reimplementing the callbacks for the events you're interested in. See the EventHandler documentation for more details.

Parameters:
handler   the EventHandler which should handle the events.
See also:
EventHandler, HandleEvent

Definition at line 104 of file sdlmm_event.cpp.

int SDLmm::Event::JoystickEventState ( int state ) [static]
 

Enable / disable joystick event polling.

Definition at line 100 of file sdlmm_event.cpp.

bool SDLmm::Event::Poll ( bool fetch = true )
 

Polls for currently pending events.

If there are any pending events, it will by default be removed from the queue and stored in this class instance.

Parameters:
fetch   if false, only poll for pending events but don't fetch it.
Returns:
true if any events were pending.
See also:
EventHandler, HandleEvents(), Wait()

Definition at line 30 of file sdlmm_event.cpp.

void SDLmm::Event::PumpEvents ( ) [static]
 

Pumps the event loop, gathering events from the input devices.

PumpEvents() gathers all the pending input information from devices and places it on the event queue. Without calls to PumpEvents() no events would ever be placed on the queue. Often the calls to PumpEvents() is hidden from the user since Poll and Wait implicitly call Pump. However, if you are not polling or waiting for events (e.g. your filtering them), then you must call Pump to force an event queue update.

Note:
You can only call this function in the thread that set the video mode.

Definition at line 50 of file sdlmm_event.cpp.

bool SDLmm::Event::Push ( )
 

Push this event onto the event queue.

The event queue can actually be used as a two way communication channel. Not only can events be read from the queue, but the user can also push their own events onto it.

Note:
Pushing device input events onto the queue doesn't modify the state of the device within SDL.
Warning:
Make sure to initialize the Event before pushing it!
Returns:
true on success, falese if the Event couldn't be pushed.

Definition at line 46 of file sdlmm_event.cpp.

bool SDLmm::Event::QueryUNICODE ( ) [inline, static]
 

Query the current UNICODE translation mode.

This function checks whether UNICODE translation is enabled or disabled.

Returns:
true if UNICODE translation is enabled, false otherwise.
See also:
EnableUNICODE, DisableUNICODE

Definition at line 307 of file sdlmm_event.h.

void SDLmm::Event::SetEventFilter ( SDL_EventFilter filter ) [static]
 

Sets up a filter to process all events before they are posted to the event queue.

This function sets up a filter to process all events before they are posted to the event queue. This is a very powerful and flexible feature. The filter is prototyped as:

      typedef int (*SDL_EventFilter)(const SDL_Event *event);

If the filter returns 1, then the event will be added to the internal queue. If it returns 0, then the event will be dropped from the queue. This allows selective filtering of dynamically.

There is one caveat when dealing with the SDL_QUITEVENT event type. The event filter is only called when the window manager desires to close the application window. If the event filter returns 1, then the window will be closed, otherwise the window will remain open if possible. If the quit event is generated by an interrupt signal, it will bypass the internal queue and be delivered to the application at the next event poll.

Note:
Events pushed onto the queue with Push() or Peep() do not get passed through the event filter.

Warning:
Be careful! The event filter function may run in a different thread so be careful what you do within it.
See also:
GetEventFilter()

Definition at line 54 of file sdlmm_event.cpp.

void SDLmm::Event::SetModState ( SDLMod modstate ) [static]
 

Set the current key modifier state.

The inverse of GetModState(), SetModState() allows you to impose modifier key states on your application.

Simply pass your desired modifier states into modstate. This value my be a logical OR'd combination of the symbols documented in GetModState().

Parameters:
modstate   the new key modifier state.
See also:
GetModState()

Definition at line 82 of file sdlmm_event.cpp.

bool SDLmm::Event::Wait ( bool fetch = true )
 

Waits indefinitely for the next available event.

This function will wait for an event to become available. It will not return until an event is queued.

Parameters:
fetch   if false, don't fetch and dequeue the event once it becomes available.
Returns:
true when an event became available and false if something went wrong.
See also:
EventHandler, HandleEvents(), Poll()

Definition at line 38 of file sdlmm_event.cpp.


Member Data Documentation

SDL_Event SDLmm::Event::me
 

The event structure.

If you use the event polling method, this is where the result is stored. You should consider using the more elegant EventHandler method instead however.

See also:
EventHandler, HandleEvents(), Poll(), Wait()

Definition at line 41 of file sdlmm_event.h.


The documentation for this class was generated from the following files:
Documentation automatically generated by doxygen written by Dimitri van Heesch. Project hosted at
Hosted by SourceForge