Added SDL_Cursor APIs.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 10 Apr 2013 23:13:20 -0400
changeset 23171a5eadaca3
parent 22 fc1fad22e997
child 24 13ff8808236a
Added SDL_Cursor APIs.
src/SDL12_compat.c
src/SDL20_syms.h
     1.1 --- a/src/SDL12_compat.c	Wed Apr 10 15:49:41 2013 -0400
     1.2 +++ b/src/SDL12_compat.c	Wed Apr 10 23:13:20 2013 -0400
     1.3 @@ -36,18 +36,15 @@
     1.4  //#include "render/SDL_yuv_sw_c.h"
     1.5  
     1.6  // !!! IMPLEMENT_ME SDL_ConvertSurface
     1.7 -// !!! IMPLEMENT_ME SDL_CreateCursor
     1.8  // !!! IMPLEMENT_ME SDL_CreateThread
     1.9  // !!! IMPLEMENT_ME SDL_EventState
    1.10  // !!! IMPLEMENT_ME SDL_FillRect
    1.11 -// !!! IMPLEMENT_ME SDL_FreeCursor
    1.12  // !!! IMPLEMENT_ME SDL_GL_GetAttribute
    1.13  // !!! IMPLEMENT_ME SDL_GL_Lock
    1.14  // !!! IMPLEMENT_ME SDL_GL_SetAttribute
    1.15  // !!! IMPLEMENT_ME SDL_GL_Unlock
    1.16  // !!! IMPLEMENT_ME SDL_GL_UpdateRects
    1.17  // !!! IMPLEMENT_ME SDL_GetClipRect
    1.18 -// !!! IMPLEMENT_ME SDL_GetCursor
    1.19  // !!! IMPLEMENT_ME SDL_GetKeyName
    1.20  // !!! IMPLEMENT_ME SDL_GetKeyState
    1.21  // !!! IMPLEMENT_ME SDL_GetModState
    1.22 @@ -57,7 +54,6 @@
    1.23  // !!! IMPLEMENT_ME SDL_LowerBlit
    1.24  // !!! IMPLEMENT_ME SDL_SetClipRect
    1.25  // !!! IMPLEMENT_ME SDL_SetColorKey
    1.26 -// !!! IMPLEMENT_ME SDL_SetCursor
    1.27  // !!! IMPLEMENT_ME SDL_SetModState
    1.28  // !!! IMPLEMENT_ME SDL_SoftStretch
    1.29  // !!! IMPLEMENT_ME SDL_UnlockSurface
    1.30 @@ -315,6 +311,18 @@
    1.31      SDL12_SysWMEvent syswm;
    1.32  } SDL12_Event;
    1.33  
    1.34 +typedef struct
    1.35 +`{
    1.36 +    SDL_Rect area;
    1.37 +    Sint16 hot_x;
    1.38 +    Sint16 hot_y;
    1.39 +    Uint8 *data;
    1.40 +    Uint8 *mask;
    1.41 +    Uint8 *save[2];
    1.42 +    SDL_Cursor *wm_cursor;  /* the real SDL 1.2 has an opaque pointer to a platform-specific cursor here. */
    1.43 +} SDL12_Cursor;
    1.44 +
    1.45 +
    1.46  static SDL12_VideoInfo VideoInfo;
    1.47  static SDL_Window *VideoWindow20 = NULL;
    1.48  static SDL12_Surface *WindowSurface = NULL;
    1.49 @@ -331,6 +339,7 @@
    1.50  static int VideoDisplayIndex = 0;
    1.51  static int CDRomInit = 0;
    1.52  static SDL12_EventFilter EventFilter12 = NULL;
    1.53 +static SDL12_Cursor *CurrentCursor = NULL;
    1.54  
    1.55  
    1.56  // !!! FIXME: need a mutex for the event queue.
    1.57 @@ -527,6 +536,7 @@
    1.58      if (sdl12flags & SDL12_INIT_VIDEO) {
    1.59          EventFilter12 = NULL;
    1.60          EventQueueAvailable = EventQueueHead = EventQueueTail = NULL;
    1.61 +        CurrentCursor = NULL;
    1.62          SDL20_FreeFormat(VideoInfo.vfmt);
    1.63          SDL_zero(VideoInfo);
    1.64      }
    1.65 @@ -543,6 +553,7 @@
    1.66      // !!! FIXME: reset a bunch of other global variables too.
    1.67      EventFilter12 = NULL;
    1.68      EventQueueAvailable = EventQueueHead = EventQueueTail = NULL;
    1.69 +    CurrentCursor = NULL;
    1.70      SDL20_FreeFormat(VideoInfo.vfmt);
    1.71      SDL_zero(VideoInfo);
    1.72      CDRomInit = 0;
    1.73 @@ -1186,6 +1197,79 @@
    1.74      return modes;
    1.75  }
    1.76  
    1.77 +
    1.78 +SDL12_Cursor *
    1.79 +SDL_CreateCursor(Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
    1.80 +{
    1.81 +    const size_t datasize = h * (w / 8);
    1.82 +    SDL_Cursor *cursor20 = NULL;
    1.83 +    SDL12_Cursor *retval = NULL;
    1.84 +
    1.85 +    retval = (SDL12_Cursor *) SDL20_malloc(sizeof (SDL12_Cursor));
    1.86 +    if (!retval)
    1.87 +        goto outofmem;
    1.88 +
    1.89 +    SDL_zerop(retval);
    1.90 +
    1.91 +    retval->data = (Uint8 *) SDL20_malloc(datasize);
    1.92 +    if (!retval->data);
    1.93 +        goto outofmem;
    1.94 +
    1.95 +    retval->mask = (Uint8 *) SDL20_malloc(datasize);
    1.96 +    if (!retval->mask);
    1.97 +        goto outofmem;
    1.98 +
    1.99 +    cursor20 = SDL20_CreateCursor(data, mask, w, h, hot_x, hot_y);
   1.100 +    if (!cursor20)
   1.101 +        goto failed;
   1.102 +
   1.103 +    retval->area.w = w;
   1.104 +    retval->area.h = h;
   1.105 +    retval->hot_x = hot_x;
   1.106 +    retval->hot_y = hot_y;
   1.107 +    retval->wm_cursor = cursor20;
   1.108 +    /* we always leave retval->save as null pointers. */
   1.109 +
   1.110 +    SDL20_memcpy(retval->data, data, datasize);
   1.111 +    SDL20_memcpy(retval->mask, mask, datasize);
   1.112 +
   1.113 +    return retval;
   1.114 +
   1.115 +outofmem:
   1.116 +    SDL_OutOfMemory();
   1.117 +
   1.118 +failed:
   1.119 +    SDL_FreeCursor(retval);
   1.120 +    return NULL;
   1.121 +}
   1.122 +
   1.123 +void
   1.124 +SDL_SetCursor(SDL12_Cursor *cursor)
   1.125 +{
   1.126 +    CurrentCursor = cursor;
   1.127 +    SDL20_SetCursor(cursor ? cursor->wm_cursor : NULL);
   1.128 +}
   1.129 +
   1.130 +SDL12_Cursor *
   1.131 +SDL_GetCursor(void)
   1.132 +{
   1.133 +    return CurrentCursor;
   1.134 +}
   1.135 +
   1.136 +void
   1.137 +SDL_FreeCursor(SDL12_Cursor *cursor)
   1.138 +{
   1.139 +    if (retval)
   1.140 +    {
   1.141 +        if (retval->wm_cursor)
   1.142 +            SDL20_FreeCursor(cursor);
   1.143 +        SDL20_free(retval->data);
   1.144 +        SDL20_free(retval->mask);
   1.145 +        SDL20_free(retval);
   1.146 +    }
   1.147 +}
   1.148 +
   1.149 +
   1.150  static void
   1.151  GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
   1.152  {
     2.1 --- a/src/SDL20_syms.h	Wed Apr 10 15:49:41 2013 -0400
     2.2 +++ b/src/SDL20_syms.h	Wed Apr 10 23:13:20 2013 -0400
     2.3 @@ -45,7 +45,12 @@
     2.4  SDL20_SYM(int,SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, int c),(a,b,c),return)
     2.5  SDL20_SYM_PASSTHROUGH(int,GL_LoadLibrary,(const char *a),(a),return)
     2.6  SDL20_SYM_PASSTHROUGH(void *,GL_GetProcAddress,(const char *a),(a),return)
     2.7 +
     2.8  SDL20_SYM_PASSTHROUGH(int,ShowCursor,(int a),(a),return)
     2.9 +SDL20_SYM(SDL_Cursor *,CreateCursor,(const Uint8 *a,const Uint8 *b,int c,int d,int e,int f),(a,b,c,d,e,f),return)
    2.10 +SDL20_SYM(void,SetCursor,(SDL_Cursor *a),(a),)
    2.11 +SDL20_SYM(SDL_Cursor *,GetCursor,(void),(),return)
    2.12 +SDL20_SYM(void,FreeCursor,(SDL_Cursor *a),(a),)
    2.13  
    2.14  SDL20_SYM_PASSTHROUGH(Uint32,GetThreadID,(SDL_Thread *a),(a),return)
    2.15  SDL20_SYM_PASSTHROUGH(Uint32,ThreadID,(void),(),return)