include/SDL_compat.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 25 Mar 2010 01:08:26 -0700
changeset 4429 faa9fc8e7f67
parent 4425 a3e71b957215
child 4468 82f357a91d43
permissions -rw-r--r--
General improvements for user custom event registration

* Switched event type to enum (int32)
* Switched polling by mask to polling by type range
* Added SDL_RegisterEvents() to allow dynamic user event registration
* Spread events out to allow inserting new related events without breaking binary compatibility
* Added padding to event structures so they're the same size regardless of 32-bit compiler structure packing settings
* Split SDL_HasEvent() to SDL_HasEvent() for a single event and SDL_HasEvents() for a range of events
* Added SDL_GetEventState() as a shortcut for SDL_EventState(X, SDL_QUERY)
* Added SDL_FlushEvent() and SDL_FlushEvents() to clear events from the event queue
     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  *  \defgroup Compatibility SDL 1.2 Compatibility API
    25  */
    26 /*@{*/
    27 
    28 /**
    29  *  \file SDL_compat.h
    30  *
    31  *  This file contains functions for backwards compatibility with SDL 1.2.
    32  */
    33 
    34 /**
    35  *  \def SDL_NO_COMPAT
    36  *
    37  *  #define SDL_NO_COMPAT to prevent SDL_compat.h from being included.
    38  *  SDL_NO_COMPAT is intended to make it easier to covert SDL 1.2 code to
    39  *  SDL 1.3/2.0.
    40  */
    41 
    42  /*@}*/
    43 
    44 #ifdef SDL_NO_COMPAT
    45 #define _SDL_compat_h
    46 #endif
    47 
    48 #ifndef _SDL_compat_h
    49 #define _SDL_compat_h
    50 
    51 #include "SDL_video.h"
    52 #include "SDL_version.h"
    53 
    54 #include "begin_code.h"
    55 /* Set up for C function definitions, even when using C++ */
    56 #ifdef __cplusplus
    57 /* *INDENT-OFF* */
    58 extern "C" {
    59 /* *INDENT-ON* */
    60 #endif
    61 
    62 /**
    63  *  \addtogroup Compatibility
    64  */
    65 /*@{*/
    66 
    67 /**
    68  *  \name Surface flags
    69  */
    70 /*@{*/
    71 #define SDL_SWSURFACE       0x00000000  /**< \note Not used */
    72 #define SDL_SRCALPHA        0x00010000
    73 #define SDL_SRCCOLORKEY     0x00020000
    74 #define SDL_ANYFORMAT       0x00100000
    75 #define SDL_HWPALETTE       0x00200000
    76 #define SDL_DOUBLEBUF       0x00400000
    77 #define SDL_FULLSCREEN      0x00800000
    78 #define SDL_RESIZABLE       0x01000000
    79 #define SDL_NOFRAME         0x02000000
    80 #define SDL_OPENGL          0x04000000
    81 #define SDL_HWSURFACE       0x08000001  /**< \note Not used */
    82 #define SDL_ASYNCBLIT       0x08000000  /**< \note Not used */
    83 #define SDL_RLEACCELOK      0x08000000  /**< \note Not used */
    84 #define SDL_HWACCEL         0x08000000  /**< \note Not used */
    85 /*@}*//*Surface flags*/
    86 
    87 #define SDL_APPMOUSEFOCUS	0x01
    88 #define SDL_APPINPUTFOCUS	0x02
    89 #define SDL_APPACTIVE		0x04
    90 
    91 #define SDL_LOGPAL 0x01
    92 #define SDL_PHYSPAL 0x02
    93 
    94 #define SDL_ACTIVEEVENT	SDL_EVENT_COMPAT1
    95 #define SDL_VIDEORESIZE	SDL_EVENT_COMPAT2
    96 #define SDL_VIDEOEXPOSE	SDL_EVENT_COMPAT3
    97 #define SDL_ACTIVEEVENTMASK	SDL_ACTIVEEVENT, SDL_ACTIVEEVENT
    98 #define SDL_VIDEORESIZEMASK SDL_VIDEORESIZE, SDL_VIDEORESIZE
    99 #define SDL_VIDEOEXPOSEMASK SDL_VIDEOEXPOSE, SDL_VIDEOEXPOSE
   100 #define SDL_WINDOWEVENTMASK SDL_WINDOWEVENT, SDL_WINDOWEVENT
   101 #define SDL_KEYDOWNMASK SDL_KEYDOWN, SDL_KEYDOWN
   102 #define SDL_KEYUPMASK SDL_KEYUP, SDL_KEYUP
   103 #define SDL_KEYEVENTMASK SDL_KEYDOWN, SDL_KEYUP
   104 #define SDL_TEXTEDITINGMASK SDL_TEXTEDITING, SDL_TEXTEDITING
   105 #define SDL_TEXTINPUTMASK SDL_TEXTINPUT, SDL_TEXTINPUT
   106 #define SDL_MOUSEMOTIONMASK SDL_MOUSEMOTION, SDL_MOUSEMOTION
   107 #define SDL_MOUSEBUTTONDOWNMASK SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN
   108 #define SDL_MOUSEBUTTONUPMASK SDL_MOUSEBUTTONUP, SDL_MOUSEBUTTONUP
   109 #define SDL_MOUSEWHEELMASK SDL_MOUSEWHEEL, SDL_MOUSEWHEEL
   110 #define SDL_MOUSEEVENTMASK SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP
   111 #define SDL_JOYAXISMOTIONMASK SDL_JOYAXISMOTION, SDL_JOYAXISMOTION
   112 #define SDL_JOYBALLMOTIONMASK SDL_JOYBALLMOTION, SDL_JOYBALLMOTION
   113 #define SDL_JOYHATMOTIONMASK SDL_JOYHATMOTION, SDL_JOYHATMOTION
   114 #define SDL_JOYBUTTONDOWNMASK SDL_JOYBUTTONDOWN, SDL_JOYBUTTONDOWN
   115 #define SDL_JOYBUTTONUPMASK SDL_JOYBUTTONUP, SDL_JOYBUTTONUP
   116 #define SDL_JOYEVENTMASK SDL_JOYAXISMOTION, SDL_JOYBUTTONUP
   117 #define SDL_QUITMASK SDL_QUIT, SDL_QUIT
   118 #define SDL_SYSWMEVENTMASK SDL_SYSWMEVENT, SDL_SYSWMEVENT
   119 #define SDL_PROXIMITYINMASK SDL_PROXIMITYIN, SDL_PROXIMITYIN
   120 #define SDL_PROXIMITYOUTMASK SDL_PROXIMITYOUT, SDL_PROXIMITYOUT
   121 #define SDL_ALLEVENTS SDL_FIRSTEVENT, SDL_LASTEVENT
   122 
   123 #define SDL_BUTTON_WHEELUP	4
   124 #define SDL_BUTTON_WHEELDOWN	5
   125 
   126 #define SDL_DEFAULT_REPEAT_DELAY	500
   127 #define SDL_DEFAULT_REPEAT_INTERVAL	30
   128 
   129 typedef struct SDL_VideoInfo
   130 {
   131     Uint32 hw_available:1;
   132     Uint32 wm_available:1;
   133     Uint32 UnusedBits1:6;
   134     Uint32 UnusedBits2:1;
   135     Uint32 blit_hw:1;
   136     Uint32 blit_hw_CC:1;
   137     Uint32 blit_hw_A:1;
   138     Uint32 blit_sw:1;
   139     Uint32 blit_sw_CC:1;
   140     Uint32 blit_sw_A:1;
   141     Uint32 blit_fill:1;
   142     Uint32 UnusedBits3:16;
   143     Uint32 video_mem;
   144 
   145     SDL_PixelFormat *vfmt;
   146 
   147     int current_w;
   148     int current_h;
   149 } SDL_VideoInfo;
   150 
   151 /**
   152  *  \name Overlay formats
   153  *
   154  *  The most common video overlay formats.
   155  *  
   156  *  For an explanation of these pixel formats, see:
   157  *  http://www.webartz.com/fourcc/indexyuv.htm
   158  *  
   159  *  For information on the relationship between color spaces, see:
   160  *  http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
   161  */
   162 /*@{*/
   163 #define SDL_YV12_OVERLAY  0x32315659    /**< Planar mode: Y + V + U  (3 planes) */
   164 #define SDL_IYUV_OVERLAY  0x56555949    /**< Planar mode: Y + U + V  (3 planes) */
   165 #define SDL_YUY2_OVERLAY  0x32595559    /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
   166 #define SDL_UYVY_OVERLAY  0x59565955    /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
   167 #define SDL_YVYU_OVERLAY  0x55595659    /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
   168 /*@}*//*Overlay formats*/
   169 
   170 /**
   171  *  The YUV hardware video overlay.
   172  */
   173 typedef struct SDL_Overlay
   174 {
   175     Uint32 format;              /**< Read-only */
   176     int w, h;                   /**< Read-only */
   177     int planes;                 /**< Read-only */
   178     Uint16 *pitches;            /**< Read-only */
   179     Uint8 **pixels;             /**< Read-write */
   180 
   181     /** 
   182      *  \name Hardware-specific surface info
   183      */
   184     /*@{*/
   185     struct private_yuvhwfuncs *hwfuncs;
   186     struct private_yuvhwdata *hwdata;
   187     /*@}*//*Hardware-specific surface info*/
   188 
   189     /** 
   190      *  \name Special flags
   191      */
   192     /*@{*/
   193     Uint32 hw_overlay:1;        /**< Flag: This overlay hardware accelerated? */
   194     Uint32 UnusedBits:31;
   195     /*@}*//*Special flags*/
   196 } SDL_Overlay;
   197 
   198 typedef enum
   199 {
   200     SDL_GRAB_QUERY = -1,
   201     SDL_GRAB_OFF = 0,
   202     SDL_GRAB_ON = 1
   203 } SDL_GrabMode;
   204 
   205 struct SDL_SysWMinfo;
   206 
   207 /**
   208  *  \name Obsolete or renamed key codes
   209  */
   210 /*@{*/
   211 
   212 /** 
   213  *  \name Renamed keys
   214  *
   215  *  These key constants were renamed for clarity or consistency. 
   216  */
   217 /*@{*/
   218 #define SDLK_KP0 SDLK_KP_0
   219 #define SDLK_KP1 SDLK_KP_1
   220 #define SDLK_KP2 SDLK_KP_2
   221 #define SDLK_KP3 SDLK_KP_3
   222 #define SDLK_KP4 SDLK_KP_4
   223 #define SDLK_KP5 SDLK_KP_5
   224 #define SDLK_KP6 SDLK_KP_6
   225 #define SDLK_KP7 SDLK_KP_7
   226 #define SDLK_KP8 SDLK_KP_8
   227 #define SDLK_KP9 SDLK_KP_9
   228 #define SDLK_NUMLOCK SDLK_NUMLOCKCLEAR
   229 #define SDLK_SCROLLOCK SDLK_SCROLLLOCK
   230 #define SDLK_PRINT SDLK_PRINTSCREEN
   231 #define SDLK_LMETA SDLK_LGUI
   232 #define SDLK_RMETA SDLK_RGUI
   233 /*@}*//*Renamed keys*/
   234 
   235 /**
   236  *  \name META modifier
   237  *  
   238  *  The META modifier is equivalent to the GUI modifier from the USB standard.
   239  */
   240 /*@{*/
   241 #define KMOD_LMETA KMOD_LGUI
   242 #define KMOD_RMETA KMOD_RGUI
   243 #define KMOD_META KMOD_GUI
   244 /*@}*//*META modifier*/
   245 
   246 /** 
   247  *  \name Not in USB
   248  *
   249  *  These keys don't appear in the USB specification (or at least not under 
   250  *  those names). I'm unsure if the following assignments make sense or if these
   251  *  codes should be defined as actual additional SDLK_ constants.
   252  */
   253 /*@{*/
   254 #define SDLK_LSUPER SDLK_LMETA
   255 #define SDLK_RSUPER SDLK_RMETA
   256 #define SDLK_COMPOSE SDLK_APPLICATION
   257 #define SDLK_BREAK SDLK_STOP
   258 #define SDLK_EURO SDLK_2
   259 /*@}*//*Not in USB*/
   260 
   261 /*@}*//*Obsolete or renamed key codes*/
   262 
   263 #define SDL_SetModuleHandle(x)
   264 #define SDL_AllocSurface    SDL_CreateRGBSurface
   265 
   266 extern DECLSPEC const SDL_version *SDLCALL SDL_Linked_Version(void);
   267 extern DECLSPEC char *SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen);
   268 extern DECLSPEC char *SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen);
   269 extern DECLSPEC const SDL_VideoInfo *SDLCALL SDL_GetVideoInfo(void);
   270 extern DECLSPEC int SDLCALL SDL_VideoModeOK(int width,
   271                                             int height,
   272                                             int bpp, Uint32 flags);
   273 extern DECLSPEC SDL_Rect **SDLCALL SDL_ListModes(const SDL_PixelFormat *
   274                                                  format, Uint32 flags);
   275 extern DECLSPEC SDL_Surface *SDLCALL SDL_SetVideoMode(int width, int height,
   276                                                       int bpp, Uint32 flags);
   277 extern DECLSPEC SDL_Surface *SDLCALL SDL_GetVideoSurface(void);
   278 extern DECLSPEC void SDLCALL SDL_UpdateRects(SDL_Surface * screen,
   279                                              int numrects, SDL_Rect * rects);
   280 extern DECLSPEC void SDLCALL SDL_UpdateRect(SDL_Surface * screen,
   281                                             Sint32 x,
   282                                             Sint32 y, Uint32 w, Uint32 h);
   283 extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface * screen);
   284 extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface * surface,
   285                                          Uint32 flag, Uint8 alpha);
   286 extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormat(SDL_Surface * surface);
   287 extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *
   288                                                             surface);
   289 extern DECLSPEC void SDLCALL SDL_WM_SetCaption(const char *title,
   290                                                const char *icon);
   291 extern DECLSPEC void SDLCALL SDL_WM_GetCaption(const char **title,
   292                                                const char **icon);
   293 extern DECLSPEC void SDLCALL SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask);
   294 extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void);
   295 extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface * surface);
   296 extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode);
   297 extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface,
   298                                            int flags,
   299                                            const SDL_Color * colors,
   300                                            int firstcolor, int ncolors);
   301 extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface * surface,
   302                                           const SDL_Color * colors,
   303                                           int firstcolor, int ncolors);
   304 extern DECLSPEC int SDLCALL SDL_GetWMInfo(struct SDL_SysWMinfo *info);
   305 extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void);
   306 extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y);
   307 extern DECLSPEC SDL_Overlay *SDLCALL SDL_CreateYUVOverlay(int width,
   308                                                           int height,
   309                                                           Uint32 format,
   310                                                           SDL_Surface *
   311                                                           display);
   312 extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay * overlay);
   313 extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay * overlay);
   314 extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay,
   315                                                   SDL_Rect * dstrect);
   316 extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay);
   317 extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
   318 extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
   319 extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
   320 extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
   321 
   322 #define SDL_TextureID SDL_Texture*
   323 #define SDL_WindowID SDL_Window*
   324 #define SDL_RenderPoint SDL_RenderDrawPoint
   325 #define SDL_RenderLine SDL_RenderDrawLine
   326 #define SDL_RenderFill(X)  (X) ? SDL_RenderFillRect(X) : SDL_RenderClear()
   327 
   328 extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
   329 
   330 /*@}*//*Compatibility*/
   331 
   332 /* Ends C function definitions when using C++ */
   333 #ifdef __cplusplus
   334 /* *INDENT-OFF* */
   335 }
   336 /* *INDENT-ON* */
   337 #endif
   338 #include "close_code.h"
   339 
   340 #endif /* _SDL_compat_h */
   341 
   342 /* vi: set ts=4 sw=4 expandtab: */