include/SDL_events.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 15 Apr 2010 22:14:26 -0700
changeset 4434 5c64052fb476
parent 4429 faa9fc8e7f67
child 4435 e953700da4ca
permissions -rw-r--r--
changeset: 4433:25667ea797fa
tag: tip
user: Jiang Jiang <gzjjgod@gmail.com>
date: Thu Apr 15 12:01:46 2010 +0800
summary: Add windowID to text editing event
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /**
    24  *  \file SDL_events.h
    25  *  
    26  *  Include file for SDL event handling.
    27  */
    28 
    29 #ifndef _SDL_events_h
    30 #define _SDL_events_h
    31 
    32 #include "SDL_stdinc.h"
    33 #include "SDL_error.h"
    34 #include "SDL_video.h"
    35 #include "SDL_keyboard.h"
    36 #include "SDL_mouse.h"
    37 #include "SDL_joystick.h"
    38 #include "SDL_quit.h"
    39 
    40 #include "begin_code.h"
    41 /* Set up for C function definitions, even when using C++ */
    42 #ifdef __cplusplus
    43 /* *INDENT-OFF* */
    44 extern "C" {
    45 /* *INDENT-ON* */
    46 #endif
    47 
    48 /* General keyboard/mouse state definitions */
    49 #define SDL_RELEASED	0
    50 #define SDL_PRESSED	1
    51 
    52 /**
    53  * \brief The types of events that can be delivered.
    54  */
    55 typedef enum
    56 {
    57     SDL_FIRSTEVENT     = 0,     /**< Unused (do not remove) */
    58 
    59     /* Application events */
    60     SDL_QUIT           = 0x100, /**< User-requested quit */
    61 
    62     /* Window events */
    63     SDL_WINDOWEVENT    = 0x200, /**< Window state change */
    64     SDL_SYSWMEVENT,             /**< System specific event */
    65 
    66     /* Keyboard events */
    67     SDL_KEYDOWN        = 0x300, /**< Keys pressed */
    68     SDL_KEYUP,                  /**< Keys released */
    69     SDL_TEXTEDITING,            /**< Keyboard text editing (composition) */
    70     SDL_TEXTINPUT,              /**< Keyboard text input */
    71 
    72     /* Mouse events */
    73     SDL_MOUSEMOTION    = 0x400, /**< Mouse moved */
    74     SDL_MOUSEBUTTONDOWN,        /**< Mouse button pressed */
    75     SDL_MOUSEBUTTONUP,          /**< Mouse button released */
    76     SDL_MOUSEWHEEL,             /**< Mouse wheel motion */
    77 
    78     /* Tablet events */
    79     SDL_PROXIMITYIN    = 0x500, /**< Proximity In event */
    80     SDL_PROXIMITYOUT,           /**< Proximity Out event */
    81 
    82     /* Joystick events */
    83     SDL_JOYAXISMOTION  = 0x600, /**< Joystick axis motion */
    84     SDL_JOYBALLMOTION,          /**< Joystick trackball motion */
    85     SDL_JOYHATMOTION,           /**< Joystick hat position change */
    86     SDL_JOYBUTTONDOWN,          /**< Joystick button pressed */
    87     SDL_JOYBUTTONUP,            /**< Joystick button released */
    88 
    89     /* Obsolete events */
    90     SDL_EVENT_COMPAT1 = 0x7000, /**< SDL 1.2 events for compatibility */
    91     SDL_EVENT_COMPAT2,
    92     SDL_EVENT_COMPAT3,
    93 
    94     /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
    95      *  and should be allocated with SDL_RegisterEvents()
    96      */
    97     SDL_USEREVENT    = 0x8000,
    98 
    99     /**
   100      *  This last event is only for bounding internal arrays
   101      */
   102     SDL_LASTEVENT    = 0xFFFF
   103 } SDL_EventType;
   104 
   105 /**
   106  *  \brief Window state change event data (event.window.*)
   107  */
   108 typedef struct SDL_WindowEvent
   109 {
   110     Uint32 type;        /**< ::SDL_WINDOWEVENT */
   111     Uint32 windowID;    /**< The associated window */
   112     Uint8 event;        /**< ::SDL_WindowEventID */
   113     Uint8 padding1;
   114     Uint8 padding2;
   115     Uint8 padding3;
   116     int data1;          /**< event dependent data */
   117     int data2;          /**< event dependent data */
   118 } SDL_WindowEvent;
   119 
   120 /**
   121  *  \brief Keyboard button event structure (event.key.*)
   122  */
   123 typedef struct SDL_KeyboardEvent
   124 {
   125     Uint32 type;        /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
   126     Uint32 windowID;    /**< The window with keyboard focus, if any */
   127     Uint8 which;        /**< The keyboard device index */
   128     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   129     Uint8 padding1;
   130     Uint8 padding2;
   131     SDL_keysym keysym;  /**< The key that was pressed or released */
   132 } SDL_KeyboardEvent;
   133 
   134 #define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
   135 /**
   136  *  \brief Keyboard text editing event structure (event.edit.*)
   137  */
   138 typedef struct SDL_TextEditingEvent
   139 {
   140     Uint32 type;                                /**< ::SDL_TEXTEDITING */
   141     Uint32 windowID;                            /**< The window with keyboard focus, if any */
   142     char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
   143     int start;                                  /**< The start cursor of selected editing text */
   144     int length;                                 /**< The length of selected editing text */
   145 } SDL_TextEditingEvent;
   146 
   147 
   148 #define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
   149 /**
   150  *  \brief Keyboard text input event structure (event.text.*)
   151  */
   152 typedef struct SDL_TextInputEvent
   153 {
   154     Uint32 type;                              /**< ::SDL_TEXTINPUT */
   155     Uint32 windowID;                          /**< The window with keyboard focus, if any */
   156     Uint8 which;                              /**< The keyboard device index */
   157     Uint8 padding1;
   158     Uint8 padding2;
   159     Uint8 padding3;
   160     char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];  /**< The input text */
   161 } SDL_TextInputEvent;
   162 
   163 /**
   164  *  \brief Mouse motion event structure (event.motion.*)
   165  */
   166 typedef struct SDL_MouseMotionEvent
   167 {
   168     Uint32 type;        /**< ::SDL_MOUSEMOTION */
   169     Uint32 windowID;    /**< The window with mouse focus, if any */
   170     Uint8 which;        /**< The mouse device index */
   171     Uint8 state;        /**< The current button state */
   172     Uint8 padding1;
   173     Uint8 padding2;
   174     int x;              /**< X coordinate, relative to window */
   175     int y;              /**< Y coordinate, relative to window */
   176     int z;              /**< Z coordinate, for future use */
   177     int pressure;       /**< Pressure reported by tablets */
   178     int pressure_max;   /**< Maximum value of the pressure reported by the device */
   179     int pressure_min;   /**< Minimum value of the pressure reported by the device */
   180     int rotation;       /**< For future use */
   181     int tilt_x;         /**< For future use */
   182     int tilt_y;         /**< For future use */
   183     int cursor;         /**< The cursor being used in the event */
   184     int xrel;           /**< The relative motion in the X direction */
   185     int yrel;           /**< The relative motion in the Y direction */
   186 } SDL_MouseMotionEvent;
   187 
   188 /**
   189  *  \brief Mouse button event structure (event.button.*)
   190  */
   191 typedef struct SDL_MouseButtonEvent
   192 {
   193     Uint32 type;        /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
   194     Uint32 windowID;    /**< The window with mouse focus, if any */
   195     Uint8 which;        /**< The mouse device index */
   196     Uint8 button;       /**< The mouse button index */
   197     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   198     Uint8 padding1;
   199     int x;              /**< X coordinate, relative to window */
   200     int y;              /**< Y coordinate, relative to window */
   201 } SDL_MouseButtonEvent;
   202 
   203 /**
   204  *  \brief Mouse wheel event structure (event.wheel.*)
   205  */
   206 typedef struct SDL_MouseWheelEvent
   207 {
   208     Uint32 type;        /**< ::SDL_MOUSEWHEEL */
   209     Uint32 windowID;    /**< The window with mouse focus, if any */
   210     Uint8 which;        /**< The mouse device index */
   211     Uint8 padding1;
   212     Uint8 padding2;
   213     Uint8 padding3;
   214     int x;              /**< The amount scrolled horizontally */
   215     int y;              /**< The amount scrolled vertically */
   216 } SDL_MouseWheelEvent;
   217 
   218 /**
   219  * \brief Tablet pen proximity event
   220  */
   221 typedef struct SDL_ProximityEvent
   222 {
   223     Uint32 type;        /**< ::SDL_PROXIMITYIN or ::SDL_PROXIMITYOUT */
   224     Uint32 windowID;    /**< The associated window */
   225     Uint8 which;
   226     Uint8 padding1;
   227     Uint8 padding2;
   228     Uint8 padding3;
   229     int cursor;
   230     int x;
   231     int y;
   232 } SDL_ProximityEvent;
   233 
   234 /**
   235  *  \brief Joystick axis motion event structure (event.jaxis.*)
   236  */
   237 typedef struct SDL_JoyAxisEvent
   238 {
   239     Uint32 type;        /**< ::SDL_JOYAXISMOTION */
   240     Uint8 which;        /**< The joystick device index */
   241     Uint8 axis;         /**< The joystick axis index */
   242     Uint8 padding1;
   243     Uint8 padding2;
   244     int value;          /**< The axis value (range: -32768 to 32767) */
   245 } SDL_JoyAxisEvent;
   246 
   247 /**
   248  *  \brief Joystick trackball motion event structure (event.jball.*)
   249  */
   250 typedef struct SDL_JoyBallEvent
   251 {
   252     Uint32 type;        /**< ::SDL_JOYBALLMOTION */
   253     Uint8 which;        /**< The joystick device index */
   254     Uint8 ball;         /**< The joystick trackball index */
   255     Uint8 padding1;
   256     Uint8 padding2;
   257     int xrel;           /**< The relative motion in the X direction */
   258     int yrel;           /**< The relative motion in the Y direction */
   259 } SDL_JoyBallEvent;
   260 
   261 /**
   262  *  \brief Joystick hat position change event structure (event.jhat.*)
   263  */
   264 typedef struct SDL_JoyHatEvent
   265 {
   266     Uint32 type;        /**< ::SDL_JOYHATMOTION */
   267     Uint8 which;        /**< The joystick device index */
   268     Uint8 hat;          /**< The joystick hat index */
   269     Uint8 value;        /**< The hat position value.
   270                          *   \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
   271                          *   \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
   272                          *   \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
   273                          *   
   274                          *   Note that zero means the POV is centered.
   275                          */
   276     Uint8 padding1;
   277 } SDL_JoyHatEvent;
   278 
   279 /**
   280  *  \brief Joystick button event structure (event.jbutton.*)
   281  */
   282 typedef struct SDL_JoyButtonEvent
   283 {
   284     Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
   285     Uint8 which;        /**< The joystick device index */
   286     Uint8 button;       /**< The joystick button index */
   287     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   288     Uint8 padding1;
   289 } SDL_JoyButtonEvent;
   290 
   291 /**
   292  *  \brief The "quit requested" event
   293  */
   294 typedef struct SDL_QuitEvent
   295 {
   296     Uint32 type;        /**< ::SDL_QUIT */
   297 } SDL_QuitEvent;
   298 
   299 /**
   300  *  \brief A user-defined event type (event.user.*)
   301  */
   302 typedef struct SDL_UserEvent
   303 {
   304     Uint32 type;        /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */
   305     Uint32 windowID;    /**< The associated window if any */
   306     int code;           /**< User defined event code */
   307     void *data1;        /**< User defined data pointer */
   308     void *data2;        /**< User defined data pointer */
   309 } SDL_UserEvent;
   310 
   311 struct SDL_SysWMmsg;
   312 typedef struct SDL_SysWMmsg SDL_SysWMmsg;
   313 
   314 /**
   315  *  \brief A video driver dependent system event (event.syswm.*)
   316  *  
   317  *  \note If you want to use this event, you should include SDL_syswm.h.
   318  */
   319 typedef struct SDL_SysWMEvent
   320 {
   321     Uint32 type;        /**< ::SDL_SYSWMEVENT */
   322     SDL_SysWMmsg *msg;  /**< driver dependent data, defined in SDL_syswm.h */
   323 } SDL_SysWMEvent;
   324 
   325 #ifndef SDL_NO_COMPAT
   326 /**
   327  *  \addtogroup Compatibility 
   328  */
   329 /*@{*/
   330 
   331 /**
   332  *  \name Typedefs for backwards compatibility
   333  */
   334 /*@{*/
   335 typedef struct SDL_ActiveEvent
   336 {
   337     Uint32 type;
   338     Uint8 gain;
   339     Uint8 state;
   340 } SDL_ActiveEvent;
   341 
   342 typedef struct SDL_ResizeEvent
   343 {
   344     Uint32 type;
   345     int w;
   346     int h;
   347 } SDL_ResizeEvent;
   348 /*@}*/
   349 
   350 /*@}*//*Compatibility*/
   351 #endif
   352 
   353 /**
   354  *  \brief General event structure
   355  */
   356 typedef union SDL_Event
   357 {
   358     Uint32 type;                    /**< Event type, shared with all events */
   359     SDL_WindowEvent window;         /**< Window event data */
   360     SDL_KeyboardEvent key;          /**< Keyboard event data */
   361     SDL_TextEditingEvent edit;      /**< Text editing event data */
   362     SDL_TextInputEvent text;        /**< Text input event data */
   363     SDL_MouseMotionEvent motion;    /**< Mouse motion event data */
   364     SDL_MouseButtonEvent button;    /**< Mouse button event data */
   365     SDL_MouseWheelEvent wheel;      /**< Mouse wheel event data */
   366     SDL_JoyAxisEvent jaxis;         /**< Joystick axis event data */
   367     SDL_JoyBallEvent jball;         /**< Joystick ball event data */
   368     SDL_JoyHatEvent jhat;           /**< Joystick hat event data */
   369     SDL_JoyButtonEvent jbutton;     /**< Joystick button event data */
   370     SDL_QuitEvent quit;             /**< Quit request event data */
   371     SDL_UserEvent user;             /**< Custom event data */
   372     SDL_SysWMEvent syswm;           /**< System dependent window event data */
   373     SDL_ProximityEvent proximity;   /**< Proximity In or Out event */
   374 
   375     /** Temporarily here for backwards compatibility */
   376     /*@{*/
   377 #ifndef SDL_NO_COMPAT
   378     SDL_ActiveEvent active;
   379     SDL_ResizeEvent resize;
   380 #endif
   381     /*@}*/
   382 } SDL_Event;
   383 
   384 
   385 /* Function prototypes */
   386 
   387 /**
   388  *  Pumps the event loop, gathering events from the input devices.
   389  *  
   390  *  This function updates the event queue and internal input device state.
   391  *  
   392  *  This should only be run in the thread that sets the video mode.
   393  */
   394 extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
   395 
   396 /*@{*/
   397 typedef enum
   398 {
   399     SDL_ADDEVENT,
   400     SDL_PEEKEVENT,
   401     SDL_GETEVENT
   402 } SDL_eventaction;
   403 
   404 /**
   405  *  Checks the event queue for messages and optionally returns them.
   406  *  
   407  *  If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
   408  *  the back of the event queue.
   409  *  
   410  *  If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
   411  *  of the event queue, matching \c mask, will be returned and will not
   412  *  be removed from the queue.
   413  *  
   414  *  If \c action is ::SDL_GETEVENT, up to \c numevents events at the front 
   415  *  of the event queue, matching \c mask, will be returned and will be
   416  *  removed from the queue.
   417  *  
   418  *  \return The number of events actually stored, or -1 if there was an error.
   419  *  
   420  *  This function is thread-safe.
   421  */
   422 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
   423                                            SDL_eventaction action,
   424                                            Uint32 minType, Uint32 maxType);
   425 /*@}*/
   426 
   427 /**
   428  *  Checks to see if certain event types are in the event queue.
   429  */
   430 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
   431 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
   432 
   433 /**
   434  *  This function clears events from the event queue
   435  */
   436 extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
   437 extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
   438 
   439 /**
   440  *  \brief Polls for currently pending events.
   441  *  
   442  *  \return 1 if there are any pending events, or 0 if there are none available.
   443  *  
   444  *  \param event If not NULL, the next event is removed from the queue and 
   445  *               stored in that area.
   446  */
   447 extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
   448 
   449 /**
   450  *  \brief Waits indefinitely for the next available event.
   451  *  
   452  *  \return 1, or 0 if there was an error while waiting for events.
   453  *   
   454  *  \param event If not NULL, the next event is removed from the queue and 
   455  *               stored in that area.
   456  */
   457 extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
   458 
   459 /**
   460  *  \brief Waits until the specified timeout (in milliseconds) for the next 
   461  *         available event.
   462  *  
   463  *  \return 1, or 0 if there was an error while waiting for events.
   464  *  
   465  *  \param event If not NULL, the next event is removed from the queue and 
   466  *               stored in that area.
   467  */
   468 extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
   469                                                  int timeout);
   470 
   471 /**
   472  *  \brief Add an event to the event queue.
   473  *  
   474  *  \return 1 on success, 0 if the event was filtered, or -1 if the event queue 
   475  *          was full or there was some other error.
   476  */
   477 extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
   478 
   479 typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
   480 
   481 /**
   482  *  Sets up a filter to process all events before they change internal state and
   483  *  are posted to the internal event queue.
   484  *  
   485  *  The filter is protypted as:
   486  *  \code
   487  *      int SDL_EventFilter(void *userdata, SDL_Event * event);
   488  *  \endcode
   489  *
   490  *  If the filter returns 1, then the event will be added to the internal queue.
   491  *  If it returns 0, then the event will be dropped from the queue, but the 
   492  *  internal state will still be updated.  This allows selective filtering of
   493  *  dynamically arriving events.
   494  *  
   495  *  \warning  Be very careful of what you do in the event filter function, as 
   496  *            it may run in a different thread!
   497  *  
   498  *  There is one caveat when dealing with the ::SDL_QUITEVENT event type.  The
   499  *  event filter is only called when the window manager desires to close the
   500  *  application window.  If the event filter returns 1, then the window will
   501  *  be closed, otherwise the window will remain open if possible.
   502  *
   503  *  If the quit event is generated by an interrupt signal, it will bypass the
   504  *  internal queue and be delivered to the application at the next event poll.
   505  */
   506 extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
   507                                                 void *userdata);
   508 
   509 /**
   510  *  Return the current event filter - can be used to "chain" filters.
   511  *  If there is no event filter set, this function returns SDL_FALSE.
   512  */
   513 extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
   514                                                     void **userdata);
   515 
   516 /**
   517  *  Run the filter function on the current event queue, removing any
   518  *  events for which the filter returns 0.
   519  */
   520 extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
   521                                               void *userdata);
   522 
   523 /*@{*/
   524 #define SDL_QUERY	-1
   525 #define SDL_IGNORE	 0
   526 #define SDL_DISABLE	 0
   527 #define SDL_ENABLE	 1
   528 
   529 /**
   530  *  This function allows you to set the state of processing certain events.
   531  *   - If \c state is set to ::SDL_IGNORE, that event will be automatically 
   532  *     dropped from the event queue and will not event be filtered.
   533  *   - If \c state is set to ::SDL_ENABLE, that event will be processed 
   534  *     normally.
   535  *   - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the 
   536  *     current processing state of the specified event.
   537  */
   538 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
   539 /*@}*/
   540 #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
   541 
   542 /**
   543  *  This function allocates a set of user-defined events, and returns
   544  *  the beginning event number for that set of events.
   545  *
   546  *  If there aren't enough user-defined events left, this function
   547  *  returns (Uint32)-1
   548  */
   549 extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
   550 
   551 /* Ends C function definitions when using C++ */
   552 #ifdef __cplusplus
   553 /* *INDENT-OFF* */
   554 }
   555 /* *INDENT-ON* */
   556 #endif
   557 #include "close_code.h"
   558 
   559 #endif /* _SDL_events_h */
   560 
   561 /* vi: set ts=4 sw=4 expandtab: */