sdljava.event
Class SDLEvent

java.lang.Object
  extended by sdljava.event.SDLEvent
Direct Known Subclasses:
DummyEvent, SDLActiveEvent, SDLExposeEvent, SDLJoyAxisEvent, SDLJoyBallEvent, SDLJoyButtonEvent, SDLJoyHatEvent, SDLKeyboardEvent, SDLMouseButtonEvent, SDLMouseMotionEvent, SDLQuitEvent, SDLResizeEvent, SDLSysWMEvent, SDLUserEvent

public abstract class SDLEvent
extends java.lang.Object

The SDL_Event is the core to all event handling in SDL, its probably the most important structure after SDL_Surface. 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.

In the case of sdljava you can simply deal with the returned SDLEvent instance. For example if you have the code SDLEvent event = SDLEvent.waitEvent() you can now do an instanceof on the returned event to determine its type, cast it to the appropriate class, then deal with the data in any way you wish. NOTE: The following is not yet implemented:

Version:
$Id: SDLEvent.java,v 1.21 2005/01/30 05:15:16 ivan_ganza Exp $
Author:
Ivan Z. Ganza

Field Summary
(package private) static SDLActiveEvent activeEvent
           
(package private) static DummyEvent dummyEvent
           
(package private) static SDLExposeEvent exposeEvent
           
(package private) static SDLJoyAxisEvent joyAxisEvent
           
(package private) static SDLJoyBallEvent joyBallEvent
           
(package private) static SDLJoyButtonEvent joyButtonEvent
           
(package private) static SDLJoyHatEvent joyHatEvent
           
(package private) static SDLMouseButtonEvent mouseButtonEvent
           
(package private) static SDLMouseMotionEvent mouseMotionEvent
           
(package private) static SDLQuitEvent quitEvent
           
(package private) static SDLResizeEvent resizeEvent
           
static int SDL_ACTIVEEVENT
           
static int SDL_ACTIVEEVENTMASK
           
static int SDL_ADDEVENT
           
static int SDL_APPACTIVE
           
static int SDL_APPINPUTFOCUS
           
static int SDL_APPMOUSEFOCUS
           
static int SDL_BUTTON_LEFT
           
static int SDL_BUTTON_MIDDLE
           
static int SDL_BUTTON_RIGHT
           
static int SDL_BUTTON_WHEELDOWN
           
static int SDL_BUTTON_WHEELUP
           
static int SDL_DEFAULT_REPEAT_DELAY
           
static int SDL_DEFAULT_REPEAT_INTERVAL
           
static int SDL_DISABLE
           
static int SDL_ENABLE
           
static int SDL_GETEVENT
           
static int SDL_IGNORE
           
static int SDL_JOYAXISMOTION
           
static int SDL_JOYAXISMOTIONMASK
           
static int SDL_JOYBALLMOTION
           
static int SDL_JOYBALLMOTIONMASK
           
static int SDL_JOYBUTTONDOWN
           
static int SDL_JOYBUTTONDOWNMASK
           
static int SDL_JOYBUTTONUP
           
static int SDL_JOYBUTTONUPMASK
           
static int SDL_JOYEVENTMASK
           
static int SDL_JOYHATMOTION
           
static int SDL_JOYHATMOTIONMASK
           
static int SDL_KEYDOWN
           
static int SDL_KEYDOWNMASK
           
static int SDL_KEYUP
           
static int SDL_KEYUPMASK
           
static int SDL_MOUSEBUTTONDOWN
           
static int SDL_MOUSEBUTTONDOWNMASK
           
static int SDL_MOUSEBUTTONUP
           
static int SDL_MOUSEBUTTONUPMASK
           
static int SDL_MOUSEEVENTMASK
           
static int SDL_MOUSEMOTION
           
static int SDL_MOUSEMOTIONMASK
           
static int SDL_NOEVENT
           
static int SDL_PEEKEVENT
           
static int SDL_PRESSED
           
static int SDL_QUERY
           
static int SDL_QUIT
           
static int SDL_QUITMASK
           
static int SDL_RELEASED
           
static int SDL_SYSWMEVENT
           
static int SDL_SYSWMEVENTMASK
           
static int SDL_USEREVENT
           
static int SDL_VIDEOEXPOSE
           
static int SDL_VIDEOEXPOSEMASK
           
static int SDL_VIDEORESIZE
           
static int SDL_VIDEORESIZEMASK
           
(package private) static SDLKeyboardEvent sdlKeyboardEvent
           
(package private) static SDL_Event swigEvent
           
(package private) static SDLSysWMEvent sysWMEvent
           
(package private) static SDLUserEvent userEvent
           
 
Constructor Summary
SDLEvent()
           
 
Method Summary
static void enableKeyRepeat(int delay, int interval)
          Enables or disables the keyboard repeat rate.
static int enableUNICODE(int mode)
          Enables/Disables Unicode keyboard translation.
static SDLEventState eventState(int type, SDLEventState state)
          This function allows you to set the state of processing certain event types.
static SDLAppState getAppState()
          This function returns the current state of the application.
static java.lang.String getKeyName(int key)
          Get the name of an SDL virtual keysym
static SDLMod getModState()
          Get the state of modifier keys.
static MouseState getMouseState()
          Retrieve the current state of the mouse
static MouseState getRelativeMouseState()
          Retrieve the relative current state of the mouse since the last call to getRelativeMouseState()
abstract  int getType()
          The type of the this event
static int joystickEventState(SDLEventState state)
          This function is used to enable or disable joystick event processing.
static SDLEvent pollEvent()
          Polls for currently pending events.
static SDLEvent pollEvent(boolean returnEvent)
          Polls for currently pending events.
(package private) static SDLEvent processEvent(SDL_Event swigEvent)
           
static void pumpEvents()
          Pumps the event loop, gathering events from the input devices.
static void setModState(SDLMod mod)
          Describe setModState method here.
static SDLEvent waitEvent()
          Waits indefinitely for the next available event
static SDLEvent waitEvent(boolean returnEvent)
          Waits indefinitely for the next available event
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SDL_ADDEVENT

public static final int SDL_ADDEVENT
See Also:
Constant Field Values

SDL_PEEKEVENT

public static final int SDL_PEEKEVENT
See Also:
Constant Field Values

SDL_GETEVENT

public static final int SDL_GETEVENT
See Also:
Constant Field Values

SDL_QUERY

public static final int SDL_QUERY
See Also:
Constant Field Values

SDL_IGNORE

public static final int SDL_IGNORE
See Also:
Constant Field Values

SDL_DISABLE

public static final int SDL_DISABLE
See Also:
Constant Field Values

SDL_ENABLE

public static final int SDL_ENABLE
See Also:
Constant Field Values

SDL_DEFAULT_REPEAT_DELAY

public static final int SDL_DEFAULT_REPEAT_DELAY
See Also:
Constant Field Values

SDL_DEFAULT_REPEAT_INTERVAL

public static final int SDL_DEFAULT_REPEAT_INTERVAL
See Also:
Constant Field Values

SDL_PRESSED

public static final int SDL_PRESSED
See Also:
Constant Field Values

SDL_RELEASED

public static final int SDL_RELEASED
See Also:
Constant Field Values

SDL_NOEVENT

public static final int SDL_NOEVENT
See Also:
Constant Field Values

SDL_ACTIVEEVENT

public static final int SDL_ACTIVEEVENT
See Also:
Constant Field Values

SDL_KEYDOWN

public static final int SDL_KEYDOWN
See Also:
Constant Field Values

SDL_KEYUP

public static final int SDL_KEYUP
See Also:
Constant Field Values

SDL_MOUSEMOTION

public static final int SDL_MOUSEMOTION
See Also:
Constant Field Values

SDL_MOUSEBUTTONDOWN

public static final int SDL_MOUSEBUTTONDOWN
See Also:
Constant Field Values

SDL_MOUSEBUTTONUP

public static final int SDL_MOUSEBUTTONUP
See Also:
Constant Field Values

SDL_JOYAXISMOTION

public static final int SDL_JOYAXISMOTION
See Also:
Constant Field Values

SDL_JOYBALLMOTION

public static final int SDL_JOYBALLMOTION
See Also:
Constant Field Values

SDL_JOYHATMOTION

public static final int SDL_JOYHATMOTION
See Also:
Constant Field Values

SDL_JOYBUTTONDOWN

public static final int SDL_JOYBUTTONDOWN
See Also:
Constant Field Values

SDL_JOYBUTTONUP

public static final int SDL_JOYBUTTONUP
See Also:
Constant Field Values

SDL_QUIT

public static final int SDL_QUIT
See Also:
Constant Field Values

SDL_SYSWMEVENT

public static final int SDL_SYSWMEVENT
See Also:
Constant Field Values

SDL_VIDEORESIZE

public static final int SDL_VIDEORESIZE
See Also:
Constant Field Values

SDL_VIDEOEXPOSE

public static final int SDL_VIDEOEXPOSE
See Also:
Constant Field Values

SDL_USEREVENT

public static final int SDL_USEREVENT
See Also:
Constant Field Values

SDL_ACTIVEEVENTMASK

public static final int SDL_ACTIVEEVENTMASK
See Also:
Constant Field Values

SDL_KEYDOWNMASK

public static final int SDL_KEYDOWNMASK
See Also:
Constant Field Values

SDL_KEYUPMASK

public static final int SDL_KEYUPMASK
See Also:
Constant Field Values

SDL_MOUSEMOTIONMASK

public static final int SDL_MOUSEMOTIONMASK
See Also:
Constant Field Values

SDL_MOUSEBUTTONDOWNMASK

public static final int SDL_MOUSEBUTTONDOWNMASK
See Also:
Constant Field Values

SDL_MOUSEBUTTONUPMASK

public static final int SDL_MOUSEBUTTONUPMASK
See Also:
Constant Field Values

SDL_MOUSEEVENTMASK

public static final int SDL_MOUSEEVENTMASK
See Also:
Constant Field Values

SDL_JOYAXISMOTIONMASK

public static final int SDL_JOYAXISMOTIONMASK
See Also:
Constant Field Values

SDL_JOYBALLMOTIONMASK

public static final int SDL_JOYBALLMOTIONMASK
See Also:
Constant Field Values

SDL_JOYHATMOTIONMASK

public static final int SDL_JOYHATMOTIONMASK
See Also:
Constant Field Values

SDL_JOYBUTTONDOWNMASK

public static final int SDL_JOYBUTTONDOWNMASK
See Also:
Constant Field Values

SDL_JOYBUTTONUPMASK

public static final int SDL_JOYBUTTONUPMASK
See Also:
Constant Field Values

SDL_JOYEVENTMASK

public static final int SDL_JOYEVENTMASK
See Also:
Constant Field Values

SDL_VIDEORESIZEMASK

public static final int SDL_VIDEORESIZEMASK
See Also:
Constant Field Values

SDL_VIDEOEXPOSEMASK

public static final int SDL_VIDEOEXPOSEMASK
See Also:
Constant Field Values

SDL_QUITMASK

public static final int SDL_QUITMASK
See Also:
Constant Field Values

SDL_SYSWMEVENTMASK

public static final int SDL_SYSWMEVENTMASK
See Also:
Constant Field Values

SDL_APPMOUSEFOCUS

public static final int SDL_APPMOUSEFOCUS
See Also:
Constant Field Values

SDL_APPINPUTFOCUS

public static final int SDL_APPINPUTFOCUS
See Also:
Constant Field Values

SDL_APPACTIVE

public static final int SDL_APPACTIVE
See Also:
Constant Field Values

SDL_BUTTON_LEFT

public static final int SDL_BUTTON_LEFT
See Also:
Constant Field Values

SDL_BUTTON_MIDDLE

public static final int SDL_BUTTON_MIDDLE
See Also:
Constant Field Values

SDL_BUTTON_RIGHT

public static final int SDL_BUTTON_RIGHT
See Also:
Constant Field Values

SDL_BUTTON_WHEELUP

public static final int SDL_BUTTON_WHEELUP
See Also:
Constant Field Values

SDL_BUTTON_WHEELDOWN

public static final int SDL_BUTTON_WHEELDOWN
See Also:
Constant Field Values

swigEvent

static SDL_Event swigEvent

activeEvent

static SDLActiveEvent activeEvent

sdlKeyboardEvent

static SDLKeyboardEvent sdlKeyboardEvent

mouseMotionEvent

static SDLMouseMotionEvent mouseMotionEvent

mouseButtonEvent

static SDLMouseButtonEvent mouseButtonEvent

joyAxisEvent

static SDLJoyAxisEvent joyAxisEvent

joyBallEvent

static SDLJoyBallEvent joyBallEvent

joyHatEvent

static SDLJoyHatEvent joyHatEvent

joyButtonEvent

static SDLJoyButtonEvent joyButtonEvent

resizeEvent

static SDLResizeEvent resizeEvent

exposeEvent

static SDLExposeEvent exposeEvent

quitEvent

static SDLQuitEvent quitEvent

userEvent

static SDLUserEvent userEvent

sysWMEvent

static SDLSysWMEvent sysWMEvent

dummyEvent

static DummyEvent dummyEvent
Constructor Detail

SDLEvent

public SDLEvent()
Method Detail

pumpEvents

public static void pumpEvents()
                       throws SDLException
Pumps the event loop, gathering events from the input devices.

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

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

Throws:
SDLException - if an error occurs

pollEvent

public static SDLEvent pollEvent(boolean returnEvent)
                          throws SDLException
Polls for currently pending events.

If returnEvent is true the next event is removed from the queue and returned (if one exists)

Parameters:
returnEvent - specifies if the event should be returned
Returns:
If returnEvent is true: The next event if one is waiting, otherwise null

If returnEvent is false: non-null SDLEvent instance if an event is available, otherwise null

Throws:
SDLException - if an error occurs

pollEvent

public static SDLEvent pollEvent()
                          throws SDLException
Polls for currently pending events.

Returns:
The next event if one is waiting, otherwise null
Throws:
SDLException - if an error occurs

waitEvent

public static SDLEvent waitEvent(boolean returnEvent)
                          throws SDLException
Waits indefinitely for the next available event

If returnEvent is true the next event is removed from the queue and returned (if one exists)

Otherwise the method simply returns once the next event is available

Parameters:
returnEvent - specifies if the event should be returned
Returns:
The next event if one is waiting and returnEvent is true, otherwise null
Throws:
SDLException - if an error occurs

waitEvent

public static SDLEvent waitEvent()
                          throws SDLException
Waits indefinitely for the next available event

Returns:
The next event if one is waiting, otherwise null
Throws:
SDLException - if an error occurs

eventState

public static SDLEventState eventState(int type,
                                       SDLEventState state)
                                throws SDLException
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, SDL_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.

Parameters:
type - a SDLEventType value
state - a SDLEventState value
Returns:
a SDLEventState value
Throws:
SDLException - if an error occurs

getModState

public static SDLMod getModState()
Get the state of modifier keys.

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

setModState

public static void setModState(SDLMod mod)
Describe setModState method here.


getKeyName

public static java.lang.String getKeyName(int key)
Get the name of an SDL virtual keysym

Parameters:
key - a SDLKey value
Returns:
the SDL-defined name of the SDLKey key.

enableUNICODE

public static int enableUNICODE(int mode)
                         throws SDLException
Enables/Disables Unicode keyboard translation.

To obtain the character codes corresponding to received keyboard events, Unicode translation must first be turned on using this function. The translation incurs a slight overhead for each keyboard event and is therefore disabled by default. For each subsequently received key down event, the unicode member of the SDL_keysym structure will then contain the corresponding character code, or zero for keysyms that do not correspond to any character code.

A value of 1 for enable enables Unicode translation; 0 disables it, and -1 leaves it unchanged (useful for querying the current translation mode).

Note that only key press events will be translated, not release events.

Parameters:
enable - a boolean value
Returns:
The previous translation mode
Throws:
SDLException - if an error occurs

enableKeyRepeat

public static void enableKeyRepeat(int delay,
                                   int interval)
                            throws SDLException
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. Good default values are SDL_DEFAULT_REPEAT_DELAY and SDL_DEFAULT_REPEAT_INTERVAL

Parameters:
delay - an int value
interval - an int value
Throws:
SDLException - if an error occurs

getMouseState

public static MouseState getMouseState()
                                throws SDLException
Retrieve the current state of the mouse

Returns:
a SDLMouseState value
Throws:
SDLException - if an error occurs

getRelativeMouseState

public static MouseState getRelativeMouseState()
                                        throws SDLException
Retrieve the relative current state of the mouse since the last call to getRelativeMouseState()

Returns:
a MouseState value
Throws:
SDLException - if an error occurs

getAppState

public static SDLAppState getAppState()
                               throws SDLException
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:
an int value
Throws:
SDLException - if an error occurs

joystickEventState

public static int joystickEventState(SDLEventState state)
                              throws SDLException
This function is used to enable or disable joystick event processing. With joystick event processing disabled you will have to update joystick states with SDL_JoystickUpdate and read the joystick information manually. state is either SDL_QUERY, SDL_ENABLE or SDL_IGNORE.

Note: Joystick event handling is preferred

Parameters:
state - a SDLEventState value
Returns:
If state is SDL_QUERY then the current state is returned, otherwise the new processing state is returned.
Throws:
SDLException - if an error occurs

getType

public abstract int getType()
The type of the this event

Returns:
The type of event

processEvent

static final SDLEvent processEvent(SDL_Event swigEvent)