| 882 | } |
| 883 | |
| 884 | SDL_Cursor * |
| 885 | SDL_CreateCursor(const Uint8 * data, const Uint8 * mask, |
| 886 | int w, int h, int hot_x, int hot_y) |
| 887 | { |
| 888 | SDL_Surface *surface; |
| 889 | SDL_Cursor *cursor; |
| 890 | int x, y; |
| 891 | Uint32 *pixel; |
| 892 | Uint8 datab = 0, maskb = 0; |
| 893 | const Uint32 black = 0xFF000000; |
| 894 | const Uint32 white = 0xFFFFFFFF; |
| 895 | const Uint32 transparent = 0x00000000; |
| 896 | |
| 897 | /* Make sure the width is a multiple of 8 */ |
| 898 | w = ((w + 7) & ~7); |
| 899 | |
| 900 | /* Create the surface from a bitmap */ |
| 901 | surface = SDL_CreateRGBSurface(0, w, h, 32, |
| 902 | 0x00FF0000, |
| 903 | 0x0000FF00, |
| 904 | 0x000000FF, |
| 905 | 0xFF000000); |
| 906 | if (!surface) { |
| 907 | return NULL; |
| 908 | } |
| 909 | for (y = 0; y < h; ++y) { |
| 910 | pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch); |
| 911 | for (x = 0; x < w; ++x) { |
| 912 | if ((x % 8) == 0) { |
| 913 | datab = *data++; |
| 914 | maskb = *mask++; |
| 915 | } |
| 916 | if (maskb & 0x80) { |
| 917 | *pixel++ = (datab & 0x80) ? black : white; |
| 918 | } else { |
| 919 | *pixel++ = (datab & 0x80) ? black : transparent; |
| 920 | } |
| 921 | datab <<= 1; |
| 922 | maskb <<= 1; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | cursor = SDL_CreateColorCursor(surface, hot_x, hot_y); |
| 927 | |
| 928 | SDL_FreeSurface(surface); |
| 929 | |
| 930 | return cursor; |
| 931 | } |
| 932 | |
| 933 | SDL_Cursor * |
| 934 | SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y) |