src/SDL12_compat.c
changeset 18 221a624a97fb
parent 17 473158daa1de
child 19 bb548168a73b
     1.1 --- a/src/SDL12_compat.c	Fri Mar 08 00:10:44 2013 -0500
     1.2 +++ b/src/SDL12_compat.c	Sun Mar 31 22:19:24 2013 -0400
     1.3 @@ -48,7 +48,6 @@
     1.4  // !!! IMPLEMENT_ME SDL_GL_UpdateRects
     1.5  // !!! IMPLEMENT_ME SDL_GetClipRect
     1.6  // !!! IMPLEMENT_ME SDL_GetCursor
     1.7 -// !!! IMPLEMENT_ME SDL_GetEventFilter
     1.8  // !!! IMPLEMENT_ME SDL_GetKeyName
     1.9  // !!! IMPLEMENT_ME SDL_GetKeyState
    1.10  // !!! IMPLEMENT_ME SDL_GetModState
    1.11 @@ -56,14 +55,9 @@
    1.12  // !!! IMPLEMENT_ME SDL_GetRelativeMouseState
    1.13  // !!! IMPLEMENT_ME SDL_LockSurface
    1.14  // !!! IMPLEMENT_ME SDL_LowerBlit
    1.15 -// !!! IMPLEMENT_ME SDL_PeepEvents
    1.16 -// !!! IMPLEMENT_ME SDL_PollEvent
    1.17 -// !!! IMPLEMENT_ME SDL_PumpEvents
    1.18 -// !!! IMPLEMENT_ME SDL_PushEvent
    1.19  // !!! IMPLEMENT_ME SDL_SetClipRect
    1.20  // !!! IMPLEMENT_ME SDL_SetColorKey
    1.21  // !!! IMPLEMENT_ME SDL_SetCursor
    1.22 -// !!! IMPLEMENT_ME SDL_SetEventFilter
    1.23  // !!! IMPLEMENT_ME SDL_SetModState
    1.24  // !!! IMPLEMENT_ME SDL_ShowCursor
    1.25  // !!! IMPLEMENT_ME SDL_SoftStretch
    1.26 @@ -123,6 +117,24 @@
    1.27      Uint8 alpha;
    1.28  } SDL12_PixelFormat;
    1.29  
    1.30 +typedef struct SDL12_Surface
    1.31 +{
    1.32 +    Uint32 flags;
    1.33 +    SDL12_PixelFormat *format;
    1.34 +    int w;
    1.35 +    int h;
    1.36 +    Uint16 pitch;
    1.37 +    void *pixels;
    1.38 +    int offset;
    1.39 +    void *hwdata;
    1.40 +    SDL_Rect clip_rect;
    1.41 +    Uint32 unused1;
    1.42 +    Uint32 locked;
    1.43 +    void *blitmap;
    1.44 +    unsigned int format_version;
    1.45 +    int refcount;
    1.46 +} SDL12_Surface;
    1.47 +
    1.48  typedef struct
    1.49  {
    1.50      Uint32 hw_available :1;
    1.51 @@ -161,6 +173,148 @@
    1.52  #define SDL12_SRCALPHA 0x00010000
    1.53  #define SDL12_PREALLOC 0x01000000
    1.54  
    1.55 +typedef int (SDLCALL *SDL12_EventFilter)(const SDL12_Event *event12);
    1.56 +static int EventFilter20to12(void *data, SDL_Event *event20);
    1.57 +
    1.58 +typedef enum
    1.59 +{
    1.60 +    SDL12_NOEVENT = 0,
    1.61 +    SDL12_ACTIVEEVENT,
    1.62 +    SDL12_KEYDOWN,
    1.63 +    SDL12_KEYUP,
    1.64 +    SDL12_MOUSEMOTION,
    1.65 +    SDL12_MOUSEBUTTONDOWN,
    1.66 +    SDL12_MOUSEBUTTONUP,
    1.67 +    SDL12_JOYAXISMOTION,
    1.68 +    SDL12_JOYBALLMOTION,
    1.69 +    SDL12_JOYHATMOTION,
    1.70 +    SDL12_JOYBUTTONDOWN,
    1.71 +    SDL12_JOYBUTTONUP,
    1.72 +    SDL12_QUIT,
    1.73 +    SDL12_SYSWMEVENT,
    1.74 +    SDL12_EVENT_RESERVEDA,
    1.75 +    SDL12_EVENT_RESERVEDB,
    1.76 +    SDL12_VIDEORESIZE,
    1.77 +    SDL12_VIDEOEXPOSE,
    1.78 +    SDL12_USEREVENT = 24,
    1.79 +    SDL12_NUMEVENTS = 32
    1.80 +} SDL12_EventType;
    1.81 +
    1.82 +typedef struct
    1.83 +{
    1.84 +    Uint8 type;
    1.85 +    Uint8 gain;
    1.86 +    Uint8 state;
    1.87 +} SDL12_ActiveEvent;
    1.88 +
    1.89 +typedef struct
    1.90 +{
    1.91 +    Uint8 type;
    1.92 +    Uint8 which;
    1.93 +    Uint8 state;
    1.94 +    SDL12_keysym keysym;
    1.95 +} SDL12_KeyboardEvent;
    1.96 +
    1.97 +typedef struct
    1.98 +{
    1.99 +    Uint8 type;
   1.100 +    Uint8 which;
   1.101 +    Uint8 state;
   1.102 +    Uint16 x, y;
   1.103 +    Sint16 xrel;
   1.104 +    Sint16 yrel;
   1.105 +} SDL12_MouseMotionEvent;
   1.106 +
   1.107 +typedef struct
   1.108 +{
   1.109 +    Uint8 type;
   1.110 +    Uint8 which;
   1.111 +    Uint8 button;
   1.112 +    Uint8 state;
   1.113 +    Uint16 x, y;
   1.114 +} SDL12_MouseButtonEvent;
   1.115 +
   1.116 +typedef struct
   1.117 +{
   1.118 +    Uint8 type;
   1.119 +    Uint8 which;
   1.120 +    Uint8 axis;
   1.121 +    Sint16 value;
   1.122 +} SDL12_JoyAxisEvent;
   1.123 +
   1.124 +typedef struct
   1.125 +{
   1.126 +    Uint8 type;
   1.127 +    Uint8 which;
   1.128 +    Uint8 ball;
   1.129 +    Sint16 xrel;
   1.130 +    Sint16 yrel;
   1.131 +} SDL12_JoyBallEvent;
   1.132 +
   1.133 +typedef struct
   1.134 +{
   1.135 +    Uint8 type;
   1.136 +    Uint8 which;
   1.137 +    Uint8 hat;
   1.138 +    Uint8 value;
   1.139 +} SDL12_JoyHatEvent;
   1.140 +
   1.141 +typedef struct
   1.142 +{
   1.143 +    Uint8 type;
   1.144 +    Uint8 which;
   1.145 +    Uint8 button;
   1.146 +    Uint8 state;
   1.147 +} SDL12_JoyButtonEvent;
   1.148 +
   1.149 +typedef struct
   1.150 +{
   1.151 +    Uint8 type;
   1.152 +    int w;
   1.153 +    int h;
   1.154 +} SDL12_ResizeEvent;
   1.155 +
   1.156 +typedef struct
   1.157 +{
   1.158 +    Uint8 type;
   1.159 +} SDL12_ExposeEvent;
   1.160 +
   1.161 +typedef struct
   1.162 +{
   1.163 +    Uint8 type;
   1.164 +} SDL12_QuitEvent;
   1.165 +
   1.166 +typedef struct
   1.167 +{
   1.168 +    Uint8 type;
   1.169 +    int code;
   1.170 +    void *data1;
   1.171 +    void *data2;
   1.172 +} SDL12_UserEvent;
   1.173 +
   1.174 +typedef struct
   1.175 +{
   1.176 +    Uint8 type;
   1.177 +    void *msg;
   1.178 +} SDL12_SysWMEvent;
   1.179 +
   1.180 +typedef union
   1.181 +{
   1.182 +    Uint8 type;
   1.183 +    SDL12_ActiveEvent active;
   1.184 +    SDL12_KeyboardEvent key;
   1.185 +    SDL12_MouseMotionEvent motion;
   1.186 +    SDL12_MouseButtonEvent button;
   1.187 +    SDL12_JoyAxisEvent jaxis;
   1.188 +    SDL12_JoyBallEvent jball;
   1.189 +    SDL12_JoyHatEvent jhat;
   1.190 +    SDL12_JoyButtonEvent jbutton;
   1.191 +    SDL12_ResizeEvent resize;
   1.192 +    SDL12_ExposeEvent expose;
   1.193 +    SDL12_QuitEvent quit;
   1.194 +    SDL12_UserEvent user;
   1.195 +    SDL12_SysWMEvent syswm;
   1.196 +} SDL12_Event;
   1.197  
   1.198  static SDL12_VideoInfo VideoInfo;
   1.199  static SDL_Window *VideoWindow = NULL;
   1.200 @@ -177,6 +331,14 @@
   1.201  static int EnabledUnicode = 0;
   1.202  static int VideoDisplayIndex = 0;
   1.203  static int CDRomInit = 0;
   1.204 +static SDL12_EventFilter EventFilter12 = NULL;
   1.205 +
   1.206 +
   1.207 +// !!! FIXME: need a mutex for the event queue.
   1.208 +#define SDL12_MAXEVENTS 128
   1.209 +static SDL12_Event EventQueue[SDL12_MAXEVENTS];
   1.210 +static int EventQueueRead = 0;
   1.211 +static int EventQueueWrite = 0;
   1.212  
   1.213  /* Obviously we can't use SDL_LoadObject() to load SDL2.  :)  */
   1.214  #if defined(_WINDOWS)
   1.215 @@ -284,7 +446,13 @@
   1.216  
   1.217      rc = justsubs ? SDL20_InitSubSystem(sdl20flags) : SDL20_Init(sdl20flags);
   1.218      if ((rc == 0) && (sdl20flags & SDL_INIT_VIDEO))
   1.219 +    {
   1.220 +        EventQueueRead = EventQueueWrite = 0;
   1.221 +        SDL_zero(EventQueue);
   1.222 +        SDL20_SetEventFilter(EventFilter20to12, NULL);
   1.223          VideoDisplayIndex = GetVideoDisplay();
   1.224 +    }
   1.225 +
   1.226      return rc;
   1.227  }
   1.228  
   1.229 @@ -343,6 +511,9 @@
   1.230  
   1.231      // !!! FIXME: reset a bunch of other global variables too.
   1.232      if (sdl12flags & SDL12_INIT_VIDEO) {
   1.233 +        EventFilter12 = NULL;
   1.234 +        EventQueueRead = EventQueueWrite = 0;
   1.235 +        SDL_zero(EventQueue);
   1.236          SDL20_FreeFormat(VideoInfo.vfmt);
   1.237          SDL_zero(VideoInfo);
   1.238      }
   1.239 @@ -357,6 +528,9 @@
   1.240  SDL_Quit(void)
   1.241  {
   1.242      // !!! FIXME: reset a bunch of other global variables too.
   1.243 +    EventFilter12 = NULL;
   1.244 +    EventQueueRead = EventQueueWrite = 0;
   1.245 +    SDL_zero(EventQueue);
   1.246      SDL20_FreeFormat(VideoInfo.vfmt);
   1.247      SDL_zero(VideoInfo);
   1.248      CDRomInit = 0;
   1.249 @@ -419,23 +593,278 @@
   1.250      return GetDriverName(SDL20_GetCurrentVideoDriver(), namebuf, maxlen);
   1.251  }
   1.252  
   1.253 -typedef struct SDL12_Surface
   1.254 +static int
   1.255 +EventFilter20to12(void *data, SDL_Event *event20)
   1.256  {
   1.257 -    Uint32 flags;
   1.258 -    SDL12_PixelFormat *format;
   1.259 -    int w;
   1.260 -    int h;
   1.261 -    Uint16 pitch;
   1.262 -    void *pixels;
   1.263 -    int offset;
   1.264 -    void *hwdata;
   1.265 -    SDL_Rect clip_rect;
   1.266 -    Uint32 unused1;
   1.267 -    Uint32 locked;
   1.268 -    void *blitmap;
   1.269 -    unsigned int format_version;
   1.270 -    int refcount;
   1.271 -} SDL12_Surface;
   1.272 +    const int maxUserEvents12 = SDL12_NUMEVENTS - SDL12_USEREVENT;
   1.273 +    SDL12_Event event12;
   1.274 +
   1.275 +    SDL_assert(data == NULL);  /* currently unused. */
   1.276 +
   1.277 +    SDL_zero(event12);
   1.278 +
   1.279 +    switch (event20->type)
   1.280 +    {
   1.281 +        case SDL_QUIT:
   1.282 +            event12->type = SDL12_QUIT;
   1.283 +            break;
   1.284 +
   1.285 +        case SDL_WINDOWEVENT:
   1.286 +            switch (event20->window.event)
   1.287 +            {
   1.288 +                case SDL_WINDOWEVENT_CLOSE:
   1.289 +                    event12->type = SDL12_QUIT;
   1.290 +                    break;
   1.291 +
   1.292 +                case SDL_WINDOWEVENT_SHOWN:
   1.293 +                case SDL_WINDOWEVENT_EXPOSED:
   1.294 +                    event12->type = SDL12_VIDEOEXPOSE;
   1.295 +                    break;
   1.296 +
   1.297 +                case SDL_WINDOWEVENT_RESIZED:
   1.298 +                case SDL_WINDOWEVENT_SIZE_CHANGED:  // !!! FIXME: what's the difference between RESIZED and SIZE_CHANGED?
   1.299 +                    event12->type = SDL12_VIDEORESIZE;
   1.300 +                    event12->resize.w = event20->window.data1;
   1.301 +                    event12->resize.h = event20->window.data2;
   1.302 +                    break;
   1.303 +
   1.304 +                case SDL_WINDOWEVENT_MINIMIZED:
   1.305 +                    event12->type = SDL_ACTIVEEVENT;
   1.306 +                    event12->active.gain = 0;
   1.307 +                    event12->active.state = SDL_APPACTIVE;
   1.308 +                    break;
   1.309 +
   1.310 +                case SDL_WINDOWEVENT_RESTORED:
   1.311 +                    event12->type = SDL_ACTIVEEVENT;
   1.312 +                    event12->active.gain = 1;
   1.313 +                    event12->active.state = SDL_APPACTIVE;
   1.314 +                    break;
   1.315 +
   1.316 +                case SDL_WINDOWEVENT_ENTER:
   1.317 +                    event12->type = SDL_ACTIVEEVENT;
   1.318 +                    event12->active.gain = 1;
   1.319 +                    event12->active.state = SDL_APPMOUSEFOCUS;
   1.320 +                    break;
   1.321 +
   1.322 +                case SDL_WINDOWEVENT_LEAVE:
   1.323 +                    event12->type = SDL_ACTIVEEVENT;
   1.324 +                    event12->active.gain = 0;
   1.325 +                    event12->active.state = SDL_APPMOUSEFOCUS;
   1.326 +                    break;
   1.327 +
   1.328 +                case SDL_WINDOWEVENT_FOCUS_GAINED:
   1.329 +                    event12->type = SDL_ACTIVEEVENT;
   1.330 +                    event12->active.gain = 1;
   1.331 +                    event12->active.state = SDL_APPINPUTFOCUS;
   1.332 +                    break;
   1.333 +
   1.334 +                case SDL_WINDOWEVENT_FOCUS_LOST:
   1.335 +                    event12->type = SDL_ACTIVEEVENT;
   1.336 +                    event12->active.gain = 0;
   1.337 +                    event12->active.state = SDL_APPINPUTFOCUS;
   1.338 +                    break;
   1.339 +            }
   1.340 +            break;
   1.341 +
   1.342 +        // !!! FIXME: this is sort of a mess to convert.
   1.343 +        //case SDL_SYSWMEVENT:
   1.344 +
   1.345 +        // !!! FIXME: write me
   1.346 +        case SDL_KEYDOWN:
   1.347 +        case SDL_KEYUP:
   1.348 +            return 0;
   1.349 +
   1.350 +        // !!! FIXME: write me
   1.351 +        case SDL_TEXTEDITING:
   1.352 +        case SDL_TEXTINPUT:
   1.353 +            return 0;
   1.354 +
   1.355 +        case SDL_MOUSEMOTION:
   1.356 +        	event12->type = SDL12_MOUSEMOTION;
   1.357 +            event12->motion.which = (Uint8) event20->motion.which;
   1.358 +            event12->motion.state = event20->motion.state;
   1.359 +            event12->motion.x = (Uint16) event20->motion.x;
   1.360 +            event12->motion.y = (Uint16) event20->motion.y;
   1.361 +            event12->motion.xrel = (Sint16) event20->motion.xrel;
   1.362 +            event12->motion.yrel = (Sint16) event20->motion.yrel;
   1.363 +            break;
   1.364 +
   1.365 +        case SDL_MOUSEBUTTONDOWN:
   1.366 +        	event12->type = SDL12_MOUSEBUTTONDOWN;
   1.367 +            event12->button.which = (Uint8) event20->button.which;
   1.368 +            event12->button.button = event20->button.button;
   1.369 +            event12->button.state = event20->button.state;
   1.370 +            event12->button.x = (Uint16) event20->button.x;
   1.371 +            event12->button.y = (Uint16) event20->button.y;
   1.372 +            break;
   1.373 +
   1.374 +        case SDL_MOUSEBUTTONUP:
   1.375 +        	event12->type = SDL12_MOUSEBUTTONUP;
   1.376 +            event12->button.which = (Uint8) event20->button.which;
   1.377 +            event12->button.button = event20->button.button;
   1.378 +            event12->button.state = event20->button.state;
   1.379 +            event12->button.x = (Uint16) event20->button.x;
   1.380 +            event12->button.y = (Uint16) event20->button.y;
   1.381 +            break;
   1.382 +
   1.383 +        case SDL_MOUSEWHEEL:
   1.384 +            return 0;  // !!! FIXME
   1.385 +        	//event12->type = SDL12_MOUSEBUTTONDOWN;
   1.386 +            //check app filter, push event
   1.387 +        	//event12->type = SDL12_MOUSEBUTTONUP;
   1.388 +            break;
   1.389 +
   1.390 +        case SDL_JOYAXISMOTION:
   1.391 +            event12->type = SDL12_JOYAXISMOTION;
   1.392 +            event12->jaxis.which = (Uint8) event20->jaxis.which;
   1.393 +            event12->jaxis.axis = event20->jaxis.axis;
   1.394 +            event12->jaxis.value = event20->jaxis.value;
   1.395 +            break;
   1.396 +
   1.397 +        case SDL_JOYBALLMOTION:
   1.398 +            event12->type = SDL12_JOYBALLMOTION;
   1.399 +            event12->jball.which = (Uint8) event20->jball.which;
   1.400 +            event12->jball.ball = event20->jball.ball;
   1.401 +            event12->jball.xrel = event20->jball.xrel;
   1.402 +            event12->jball.yrel = event20->jball.yrel;
   1.403 +            break;
   1.404 +
   1.405 +        case SDL_JOYHATMOTION:
   1.406 +            event12->type = SDL12_JOYHATMOTION;
   1.407 +            event12->jhat.which = (Uint8) event20->jhat.which;
   1.408 +            event12->jhat.hat = event20->jhat.hat;
   1.409 +            event12->jhat.value = event20->jhat.xrel;
   1.410 +            break;
   1.411 +
   1.412 +        case SDL_JOYBUTTONDOWN:
   1.413 +            event12->type = SDL12_JOYBUTTONDOWN;
   1.414 +            event12->jbutton.which = (Uint8) event20->jbutton.which;
   1.415 +            event12->jbutton.button = event20->jbutton.button;
   1.416 +            event12->jbutton.state = event20->jbutton.state;
   1.417 +            break;
   1.418 +
   1.419 +        case SDL_JOYBUTTONUP:
   1.420 +            event12->type = SDL12_JOYBUTTONUP;
   1.421 +            event12->jbutton.which = (Uint8) event20->jbutton.which;
   1.422 +            event12->jbutton.button = event20->jbutton.button;
   1.423 +            event12->jbutton.state = event20->jbutton.state;
   1.424 +            break;
   1.425 +
   1.426 +        //case SDL_JOYDEVICEADDED:
   1.427 +        //case SDL_JOYDEVICEREMOVED:
   1.428 +	    //case SDL_CONTROLLERAXISMOTION:
   1.429 +	    //case SDL_CONTROLLERBUTTONDOWN:
   1.430 +	    //case SDL_CONTROLLERBUTTONUP:
   1.431 +	    //case SDL_CONTROLLERDEVICEADDED:
   1.432 +	    //case SDL_CONTROLLERDEVICEREMOVED:
   1.433 +	    //case SDL_CONTROLLERDEVICEREMAPPED:
   1.434 +        //case SDL_FINGERDOWN:
   1.435 +        //case SDL_FINGERUP:
   1.436 +        //case SDL_FINGERMOTION:
   1.437 +        //case SDL_DOLLARGESTURE:
   1.438 +        //case SDL_DOLLARRECORD:
   1.439 +        //case SDL_MULTIGESTURE:
   1.440 +        //case SDL_CLIPBOARDUPDATE:
   1.441 +        //case SDL_DROPFILE:
   1.442 +
   1.443 +        default:
   1.444 +            return 0;  /* drop everything else. */
   1.445 +    }
   1.446 +
   1.447 +    if ((!EventFilter12) || (EventFilter12(&event12)))
   1.448 +        SDL_PushEvent(&event12);
   1.449 +
   1.450 +    return 0;  /* always drop it from the 2.0 event queue. */
   1.451 +}
   1.452 +
   1.453 +int
   1.454 +SDL_PollEvent(SDL12_Event *event12)
   1.455 +{
   1.456 +    SDL20_PumpEvents();  /* this will run our filter and build our 1.2 queue. */
   1.457 +
   1.458 +    if (EventQueueRead >= EventQueueWrite)
   1.459 +        return 0;  /* no events at the moment. */
   1.460 +
   1.461 +    SDL_memcpy(event12, &EventQueue[EventQueueRead % SDL12_MAXEVENTS], sizeof (SDL12_Event));
   1.462 +    EventQueueRead++;
   1.463 +    return 1;
   1.464 +}
   1.465 +
   1.466 +int
   1.467 +SDL_PushEvent(SDL12_Event *event12)
   1.468 +{
   1.469 +    if ((EventQueueWrite - EventQueueRead) >= SDL12_MAXEVENTS)
   1.470 +        return -1;  /* no space available at the moment. */
   1.471 +
   1.472 +    SDL_memcpy(&EventQueue[EventQueueWrite % SDL12_MAXEVENTS], event12, sizeof (SDL12_Event));
   1.473 +    EventQueueWrite++;
   1.474 +    return 0;
   1.475 +}
   1.476 +
   1.477 +int
   1.478 +SDL_PeepEvents(SDL12_Event *events12, int numevents, SDL_eventaction action, Uint32 mask)
   1.479 +{
   1.480 +    int i;
   1.481 +
   1.482 +    if (action == SDL_ADDEVENT)
   1.483 +    {
   1.484 +        for (i = 0; i < numevents; i++)
   1.485 +        {
   1.486 +            if ((EventQueueWrite - EventQueueRead) >= SDL12_MAXEVENTS)
   1.487 +                break;  /* out of space for more events. */
   1.488 +            SDL_memcpy(&EventQueue[EventQueueWrite % SDL12_MAXEVENTS], &events12[i], sizeof (SDL12_Event));
   1.489 +            EventQueueWrite++;
   1.490 +        }
   1.491 +        return i;
   1.492 +    }
   1.493 +    else if ((action == SDL_PEEKEVENT) || (action == SDL_GETEVENT))
   1.494 +    {
   1.495 +        const SDL_bool isGet = (action == SDL_GETEVENT);
   1.496 +        int seen = 0;
   1.497 +        int chosen = 0;
   1.498 +        while (chosen < numevents)
   1.499 +        {
   1.500 +            const SDL12_Event *event12;
   1.501 +
   1.502 +            if ((EventQueueRead + seen) >= EventQueueWrite)
   1.503 +                break;  /* no more events at the moment. */
   1.504 +
   1.505 +            event12 = &EventQueue[(EventQueueRead+seen) % SDL12_MAXEVENTS];
   1.506 +            seen++;
   1.507 +
   1.508 +            if (mask & (1<<event12->type))
   1.509 +            {
   1.510 +                SDL_memcpy(&events12[chosen++], event12, sizeof (SDL12_Event));
   1.511 +                if (isGet) {
   1.512 +                    event12->type = 0xFF;  /* mark it used. */
   1.513 +                }
   1.514 +            }
   1.515 +        }
   1.516 +
   1.517 +        if (isGet)
   1.518 +        {
   1.519 +            // !!! FIXME: remove events we ate.
   1.520 +        }
   1.521 +
   1.522 +        return chosen;
   1.523 +    }
   1.524 +
   1.525 +    return 0;
   1.526 +}
   1.527 +
   1.528 +void
   1.529 +SDL_SetEventFilter(SDL12_EventFilter filter12)
   1.530 +{
   1.531 +    /* We always have a filter installed, but will call the app's too. */
   1.532 +    EventFilter12 = filter12;
   1.533 +}
   1.534 +
   1.535 +SDL12_EventFilter
   1.536 +SDL_GetEventFilter(void)
   1.537 +{
   1.538 +    return EventFilter12;
   1.539 +}
   1.540 +
   1.541  
   1.542  SDL12_Surface *
   1.543  Surface20to12(SDL_Surface *surface20)
   1.544 @@ -727,148 +1156,6 @@
   1.545      return modes;
   1.546  }
   1.547  
   1.548 -/* !!! FIXME: don't need a filter, just do this in the SDL_PumpEvents() implementation. */
   1.549 -static int
   1.550 -SDL_CompatEventFilter(void *userdata, SDL_Event * event)
   1.551 -{
   1.552 -    SDL_Event fake;
   1.553 -
   1.554 -    switch (event->type) {
   1.555 -    case SDL_WINDOWEVENT:
   1.556 -        switch (event->window.event) {
   1.557 -        case SDL_WINDOWEVENT_EXPOSED:
   1.558 -            if (!SDL20_HasEvent(SDL_VIDEOEXPOSE)) {
   1.559 -                fake.type = SDL_VIDEOEXPOSE;
   1.560 -                SDL20_PushEvent(&fake);
   1.561 -            }
   1.562 -            break;
   1.563 -        case SDL_WINDOWEVENT_RESIZED:
   1.564 -            SDL_FlushEvent(SDL_VIDEORESIZE);
   1.565 -            /* We don't want to expose that the window width and height will
   1.566 -               be different if we don't get the desired fullscreen mode.
   1.567 -            */
   1.568 -            if (VideoWindow && !(SDL_GetWindowFlags(VideoWindow) & SDL_WINDOW_FULLSCREEN)) {
   1.569 -                fake.type = SDL_VIDEORESIZE;
   1.570 -                fake.resize.w = event->window.data1;
   1.571 -                fake.resize.h = event->window.data2;
   1.572 -                SDL_PushEvent(&fake);
   1.573 -            }
   1.574 -            break;
   1.575 -        case SDL_WINDOWEVENT_MINIMIZED:
   1.576 -            fake.type = SDL_ACTIVEEVENT;
   1.577 -            fake.active.gain = 0;
   1.578 -            fake.active.state = SDL_APPACTIVE;
   1.579 -            SDL_PushEvent(&fake);
   1.580 -            break;
   1.581 -        case SDL_WINDOWEVENT_RESTORED:
   1.582 -            fake.type = SDL_ACTIVEEVENT;
   1.583 -            fake.active.gain = 1;
   1.584 -            fake.active.state = SDL_APPACTIVE;
   1.585 -            SDL_PushEvent(&fake);
   1.586 -            break;
   1.587 -        case SDL_WINDOWEVENT_ENTER:
   1.588 -            fake.type = SDL_ACTIVEEVENT;
   1.589 -            fake.active.gain = 1;
   1.590 -            fake.active.state = SDL_APPMOUSEFOCUS;
   1.591 -            SDL_PushEvent(&fake);
   1.592 -            break;
   1.593 -        case SDL_WINDOWEVENT_LEAVE:
   1.594 -            fake.type = SDL_ACTIVEEVENT;
   1.595 -            fake.active.gain = 0;
   1.596 -            fake.active.state = SDL_APPMOUSEFOCUS;
   1.597 -            SDL_PushEvent(&fake);
   1.598 -            break;
   1.599 -        case SDL_WINDOWEVENT_FOCUS_GAINED:
   1.600 -            fake.type = SDL_ACTIVEEVENT;
   1.601 -            fake.active.gain = 1;
   1.602 -            fake.active.state = SDL_APPINPUTFOCUS;
   1.603 -            SDL_PushEvent(&fake);
   1.604 -            break;
   1.605 -        case SDL_WINDOWEVENT_FOCUS_LOST:
   1.606 -            fake.type = SDL_ACTIVEEVENT;
   1.607 -            fake.active.gain = 0;
   1.608 -            fake.active.state = SDL_APPINPUTFOCUS;
   1.609 -            SDL_PushEvent(&fake);
   1.610 -            break;
   1.611 -        case SDL_WINDOWEVENT_CLOSE:
   1.612 -            fake.type = SDL_QUIT;
   1.613 -            SDL_PushEvent(&fake);
   1.614 -            break;
   1.615 -        }
   1.616 -    case SDL_KEYDOWN:
   1.617 -    case SDL_KEYUP:
   1.618 -        {
   1.619 -            Uint32 unicode = 0;
   1.620 -            if (event->key.type == SDL_KEYDOWN && event->key.keysym.sym < 256) {
   1.621 -                unicode = event->key.keysym.sym;
   1.622 -                if (unicode >= 'a' && unicode <= 'z') {
   1.623 -                    int shifted = !!(event->key.keysym.mod & KMOD_SHIFT);
   1.624 -                    int capslock = !!(event->key.keysym.mod & KMOD_CAPS);
   1.625 -                    if ((shifted ^ capslock) != 0) {
   1.626 -                        unicode = SDL_toupper(unicode);
   1.627 -                    }
   1.628 -                }
   1.629 -            }
   1.630 -            if (unicode) {
   1.631 -                event->key.keysym.unicode = unicode;
   1.632 -            }
   1.633 -            break;
   1.634 -        }
   1.635 -    case SDL_TEXTINPUT:
   1.636 -        {
   1.637 -            /* FIXME: Generate an old style key repeat event if needed */
   1.638 -            //printf("TEXTINPUT: '%s'\n", event->text.text);
   1.639 -            break;
   1.640 -        }
   1.641 -    case SDL_MOUSEMOTION:
   1.642 -        {
   1.643 -            event->motion.x -= VideoViewport.x;
   1.644 -            event->motion.y -= VideoViewport.y;
   1.645 -            break;
   1.646 -        }
   1.647 -    case SDL_MOUSEBUTTONDOWN:
   1.648 -    case SDL_MOUSEBUTTONUP:
   1.649 -        {
   1.650 -            event->button.x -= VideoViewport.x;
   1.651 -            event->button.y -= VideoViewport.y;
   1.652 -            break;
   1.653 -        }
   1.654 -    case SDL_MOUSEWHEEL:
   1.655 -        {
   1.656 -            Uint8 button;
   1.657 -            int x, y;
   1.658 -
   1.659 -            if (event->wheel.y == 0) {
   1.660 -                break;
   1.661 -            }
   1.662 -
   1.663 -            SDL_GetMouseState(&x, &y);
   1.664 -
   1.665 -            if (event->wheel.y > 0) {
   1.666 -                button = SDL_BUTTON_WHEELUP;
   1.667 -            } else {
   1.668 -                button = SDL_BUTTON_WHEELDOWN;
   1.669 -            }
   1.670 -
   1.671 -            fake.button.button = button;
   1.672 -            fake.button.x = x;
   1.673 -            fake.button.y = y;
   1.674 -            fake.button.windowID = event->wheel.windowID;
   1.675 -
   1.676 -            fake.type = SDL_MOUSEBUTTONDOWN;
   1.677 -            fake.button.state = SDL_PRESSED;
   1.678 -            SDL_PushEvent(&fake);
   1.679 -
   1.680 -            fake.type = SDL_MOUSEBUTTONUP;
   1.681 -            fake.button.state = SDL_RELEASED;
   1.682 -            SDL_PushEvent(&fake);
   1.683 -            break;
   1.684 -        }
   1.685 -
   1.686 -    }
   1.687 -    return 1;
   1.688 -}
   1.689 -
   1.690  static void
   1.691  GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
   1.692  {