src/events/SDL_mouse.c
changeset 5473 5665ccbd6792
parent 5406 1517da4ab6b1
child 5535 96594ac5fd1a
     1.1 --- a/src/events/SDL_mouse.c	Fri Mar 11 13:59:52 2011 -0800
     1.2 +++ b/src/events/SDL_mouse.c	Fri Mar 11 14:14:38 2011 -0800
     1.3 @@ -360,24 +360,15 @@
     1.4      const Uint32 white = 0xFFFFFFFF;
     1.5      const Uint32 transparent = 0x00000000;
     1.6  
     1.7 -    if (!mouse->CreateCursor) {
     1.8 -        SDL_SetError("Cursors are not currently supported");
     1.9 -        return NULL;
    1.10 -    }
    1.11 -
    1.12 -    /* Sanity check the hot spot */
    1.13 -    if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
    1.14 -        SDL_SetError("Cursor hot spot doesn't lie within cursor");
    1.15 -        return NULL;
    1.16 -    }
    1.17 -
    1.18      /* Make sure the width is a multiple of 8 */
    1.19      w = ((w + 7) & ~7);
    1.20  
    1.21      /* Create the surface from a bitmap */
    1.22 -    surface =
    1.23 -        SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
    1.24 -                             0xFF000000);
    1.25 +    surface = SDL_CreateRGBSurface(0, w, h, 32,
    1.26 +                                   0x00FF0000,
    1.27 +                                   0x0000FF00,
    1.28 +                                   0x000000FF,
    1.29 +                                   0xFF000000);
    1.30      if (!surface) {
    1.31          return NULL;
    1.32      }
    1.33 @@ -398,13 +389,54 @@
    1.34          }
    1.35      }
    1.36  
    1.37 +    cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
    1.38 +
    1.39 +    SDL_FreeSurface(surface);
    1.40 +
    1.41 +    return cursor;
    1.42 +}
    1.43 +
    1.44 +SDL_Cursor *
    1.45 +SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
    1.46 +{
    1.47 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.48 +    SDL_Surface *temp = NULL;
    1.49 +    SDL_Cursor *cursor;
    1.50 +
    1.51 +    if (!surface) {
    1.52 +        SDL_SetError("Passed NULL cursor surface");
    1.53 +        return NULL;
    1.54 +    }
    1.55 +
    1.56 +    if (!mouse->CreateCursor) {
    1.57 +        SDL_SetError("Cursors are not currently supported");
    1.58 +        return NULL;
    1.59 +    }
    1.60 +
    1.61 +    /* Sanity check the hot spot */
    1.62 +    if ((hot_x < 0) || (hot_y < 0) ||
    1.63 +        (hot_x >= surface->w) || (hot_y >= surface->h)) {
    1.64 +        SDL_SetError("Cursor hot spot doesn't lie within cursor");
    1.65 +        return NULL;
    1.66 +    }
    1.67 +
    1.68 +    if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
    1.69 +        temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
    1.70 +        if (!temp) {
    1.71 +            return NULL;
    1.72 +        }
    1.73 +        surface = temp;
    1.74 +    }
    1.75 +
    1.76      cursor = mouse->CreateCursor(surface, hot_x, hot_y);
    1.77      if (cursor) {
    1.78          cursor->next = mouse->cursors;
    1.79          mouse->cursors = cursor;
    1.80      }
    1.81  
    1.82 -    SDL_FreeSurface(surface);
    1.83 +    if (temp) {
    1.84 +        SDL_FreeSurface(temp);
    1.85 +    }
    1.86  
    1.87      return cursor;
    1.88  }