1SDL_CreateCursor(3) SDL API Reference SDL_CreateCursor(3)
2
3
4
6 SDL_CreateCursor - Creates a new mouse cursor.
7
9 #include "SDL.h"
10
11 SDL_Cursor *SDL_CreateCursor(Uint8 *data, Uint8 *mask, int w, int h,
12 int hot_x, int hot_y);
13
15 Create a cursor using the specified data and mask (in MSB format). The
16 cursor width must be a multiple of 8 bits.
17
18 The cursor is created in black and white according to the following:
19
20 Data / Mask Resulting pixel on screen
21
22 0 / 1 White
23
24 1 / 1 Black
25
26 0 / 0 Transparent
27
28 1 / 0 Inverted color if possible, black if not.
29
30 Cursors created with this function must be freed with SDL_FreeCursor.
31
33 /* Stolen from the mailing list */
34 /* Creates a new mouse cursor from an XPM */
35
36
37 /* XPM */
38 static const char *arrow[] = {
39 /* width height num_colors chars_per_pixel */
40 " 32 32 3 1",
41 /* colors */
42 "X c #000000",
43 ". c #ffffff",
44 " c None",
45 /* pixels */
46 "X ",
47 "XX ",
48 "X.X ",
49 "X..X ",
50 "X...X ",
51 "X....X ",
52 "X.....X ",
53 "X......X ",
54 "X.......X ",
55 "X........X ",
56 "X.....XXXXX ",
57 "X..X..X ",
58 "X.X X..X ",
59 "XX X..X ",
60 "X X..X ",
61 " X..X ",
62 " X..X ",
63 " X..X ",
64 " XX ",
65 " ",
66 " ",
67 " ",
68 " ",
69 " ",
70 " ",
71 " ",
72 " ",
73 " ",
74 " ",
75 " ",
76 " ",
77 " ",
78 "0,0"
79 };
80
81 static SDL_Cursor *init_system_cursor(const char *image[])
82 {
83 int i, row, col;
84 Uint8 data[4*32];
85 Uint8 mask[4*32];
86 int hot_x, hot_y;
87
88 i = -1;
89 for ( row=0; row<32; ++row ) {
90 for ( col=0; col<32; ++col ) {
91 if ( col % 8 ) {
92 data[i] <<= 1;
93 mask[i] <<= 1;
94 } else {
95 ++i;
96 data[i] = mask[i] = 0;
97 }
98 switch (image[4+row][col]) {
99 case 'X':
100 data[i] |= 0x01;
101 k[i] |= 0x01;
102 break;
103 case '.':
104 mask[i] |= 0x01;
105 break;
106 case ' ':
107 break;
108 }
109 }
110 }
111 sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
112 return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
113 }
114
116 SDL_FreeCursor, SDL_SetCursor, SDL_ShowCursor
117
118
119
120SDL Tue 11 Sep 2001, 23:01 SDL_CreateCursor(3)