6 /* This is an example 16x16 cursor
8 top right : inverted color or black
10 bottom right: transparent
11 (swap left and right for different endianness)
14 Uint16 cursor_data
[16]={
36 Uint16 cursor_mask
[16]={
58 /* another test cursor: smaller than 16x16, and with an odd height */
60 Uint8 small_cursor_data
[11] = { 0x00, 0x18, 0x08, 0x38, 0x44, 0x54, 0x44, 0x38, 0x20, 0x20, 0x00 };
61 Uint8 small_cursor_mask
[11] = { 0x3C, 0x3C, 0x3C, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x78, 0x70, 0x70 };
64 static const char *arrow
[] = {
65 /* width height num_colors chars_per_pixel */
107 static SDL_Cursor
*create_arrow_cursor()
115 for ( row
=0; row
<32; ++row
) {
116 for ( col
=0; col
<32; ++col
) {
122 data
[i
] = mask
[i
] = 0;
124 switch (arrow
[4+row
][col
]) {
137 sscanf(arrow
[4+row
], "%d,%d", &hot_x
, &hot_y
);
138 return SDL_CreateCursor(data
, mask
, 32, 32, hot_x
, hot_y
);
142 int main(int argc
, char *argv
[])
145 SDL_bool quit
= SDL_FALSE
, first_time
= SDL_TRUE
;
146 SDL_Cursor
*cursor
[3];
149 /* Load the SDL library */
150 if ( SDL_Init(SDL_INIT_VIDEO
) < 0 ) {
151 fprintf(stderr
, "Couldn't initialize SDL: %s\n",SDL_GetError());
155 screen
= SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT
);
157 fprintf(stderr
, "Couldn't initialize video mode: %s\n",SDL_GetError());
161 SDL_FillRect(screen
, NULL
, 0x664422);
163 cursor
[0] = SDL_CreateCursor((Uint8
*)cursor_data
, (Uint8
*)cursor_mask
,
165 if (cursor
[0]==NULL
) {
166 fprintf(stderr
, "Couldn't initialize test cursor: %s\n",SDL_GetError());
170 cursor
[1] = create_arrow_cursor();
171 if (cursor
[1]==NULL
) {
172 fprintf(stderr
, "Couldn't initialize arrow cursor: %s\n",SDL_GetError());
173 SDL_FreeCursor(cursor
[0]);
177 cursor
[2] = SDL_CreateCursor(small_cursor_data
, small_cursor_mask
,
179 if (cursor
[2]==NULL
) {
180 fprintf(stderr
, "Couldn't initialize test cursor: %s\n",SDL_GetError());
186 SDL_SetCursor(cursor
[current
]);
190 while (SDL_PollEvent(&event
)) {
192 case SDL_MOUSEBUTTONDOWN
:
193 current
= (current
+ 1)%3;
194 SDL_SetCursor(cursor
[current
]);
197 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
) {
210 SDL_FreeCursor(cursor
[0]);
211 SDL_FreeCursor(cursor
[1]);
212 SDL_FreeCursor(cursor
[2]);