src/events/SDL_mouse.c
changeset 5473 5665ccbd6792
parent 5406 1517da4ab6b1
child 5535 96594ac5fd1a
equal deleted inserted replaced
5472:674d45edfaeb 5473:5665ccbd6792
   358     Uint8 datab = 0, maskb = 0;
   358     Uint8 datab = 0, maskb = 0;
   359     const Uint32 black = 0xFF000000;
   359     const Uint32 black = 0xFF000000;
   360     const Uint32 white = 0xFFFFFFFF;
   360     const Uint32 white = 0xFFFFFFFF;
   361     const Uint32 transparent = 0x00000000;
   361     const Uint32 transparent = 0x00000000;
   362 
   362 
   363     if (!mouse->CreateCursor) {
       
   364         SDL_SetError("Cursors are not currently supported");
       
   365         return NULL;
       
   366     }
       
   367 
       
   368     /* Sanity check the hot spot */
       
   369     if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
       
   370         SDL_SetError("Cursor hot spot doesn't lie within cursor");
       
   371         return NULL;
       
   372     }
       
   373 
       
   374     /* Make sure the width is a multiple of 8 */
   363     /* Make sure the width is a multiple of 8 */
   375     w = ((w + 7) & ~7);
   364     w = ((w + 7) & ~7);
   376 
   365 
   377     /* Create the surface from a bitmap */
   366     /* Create the surface from a bitmap */
   378     surface =
   367     surface = SDL_CreateRGBSurface(0, w, h, 32,
   379         SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
   368                                    0x00FF0000,
   380                              0xFF000000);
   369                                    0x0000FF00,
       
   370                                    0x000000FF,
       
   371                                    0xFF000000);
   381     if (!surface) {
   372     if (!surface) {
   382         return NULL;
   373         return NULL;
   383     }
   374     }
   384     for (y = 0; y < h; ++y) {
   375     for (y = 0; y < h; ++y) {
   385         pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
   376         pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
   396             datab <<= 1;
   387             datab <<= 1;
   397             maskb <<= 1;
   388             maskb <<= 1;
   398         }
   389         }
   399     }
   390     }
   400 
   391 
       
   392     cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
       
   393 
       
   394     SDL_FreeSurface(surface);
       
   395 
       
   396     return cursor;
       
   397 }
       
   398 
       
   399 SDL_Cursor *
       
   400 SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
       
   401 {
       
   402     SDL_Mouse *mouse = SDL_GetMouse();
       
   403     SDL_Surface *temp = NULL;
       
   404     SDL_Cursor *cursor;
       
   405 
       
   406     if (!surface) {
       
   407         SDL_SetError("Passed NULL cursor surface");
       
   408         return NULL;
       
   409     }
       
   410 
       
   411     if (!mouse->CreateCursor) {
       
   412         SDL_SetError("Cursors are not currently supported");
       
   413         return NULL;
       
   414     }
       
   415 
       
   416     /* Sanity check the hot spot */
       
   417     if ((hot_x < 0) || (hot_y < 0) ||
       
   418         (hot_x >= surface->w) || (hot_y >= surface->h)) {
       
   419         SDL_SetError("Cursor hot spot doesn't lie within cursor");
       
   420         return NULL;
       
   421     }
       
   422 
       
   423     if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
       
   424         temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
       
   425         if (!temp) {
       
   426             return NULL;
       
   427         }
       
   428         surface = temp;
       
   429     }
       
   430 
   401     cursor = mouse->CreateCursor(surface, hot_x, hot_y);
   431     cursor = mouse->CreateCursor(surface, hot_x, hot_y);
   402     if (cursor) {
   432     if (cursor) {
   403         cursor->next = mouse->cursors;
   433         cursor->next = mouse->cursors;
   404         mouse->cursors = cursor;
   434         mouse->cursors = cursor;
   405     }
   435     }
   406 
   436 
   407     SDL_FreeSurface(surface);
   437     if (temp) {
       
   438         SDL_FreeSurface(temp);
       
   439     }
   408 
   440 
   409     return cursor;
   441     return cursor;
   410 }
   442 }
   411 
   443 
   412 /* SDL_SetCursor(NULL) can be used to force the cursor redraw,
   444 /* SDL_SetCursor(NULL) can be used to force the cursor redraw,