test/testcursor.c
changeset 1883 2780f547f5e7
parent 1862 fe99535ac064
child 1895 c121d94672cb
child 3912 e7d2858670c1
equal deleted inserted replaced
1882:339d733e3699 1883:2780f547f5e7
    53 	0xff00,
    53 	0xff00,
    54 	0xff00,
    54 	0xff00,
    55 	0xff00
    55 	0xff00
    56 };
    56 };
    57 
    57 
       
    58 /* another test cursor: smaller than 16x16, and with an odd height */
       
    59 
       
    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 };
    58 
    62 
    59 /* XPM */
    63 /* XPM */
    60 static const char *arrow[] = {
    64 static const char *arrow[] = {
    61   /* width height num_colors chars_per_pixel */
    65   /* width height num_colors chars_per_pixel */
    62   "    32    32        3            1",
    66   "    32    32        3            1",
   137 
   141 
   138 int main(int argc, char *argv[])
   142 int main(int argc, char *argv[])
   139 {
   143 {
   140 	SDL_Surface *screen;
   144 	SDL_Surface *screen;
   141 	SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
   145 	SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
   142 	SDL_Cursor *cursor[2];
   146 	SDL_Cursor *cursor[3];
   143 	int current;
   147 	int current;
   144 
   148 
   145 	/* Load the SDL library */
   149 	/* Load the SDL library */
   146 	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   150 	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   147 		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
   151 		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
   168 		fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",SDL_GetError());
   172 		fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",SDL_GetError());
   169 		SDL_FreeCursor(cursor[0]);
   173 		SDL_FreeCursor(cursor[0]);
   170 		SDL_Quit();
   174 		SDL_Quit();
   171 		return(1);
   175 		return(1);
   172 	}
   176 	}
       
   177 	cursor[2] = SDL_CreateCursor(small_cursor_data, small_cursor_mask,
       
   178 		8, 11, 3, 5);
       
   179 	if (cursor[2]==NULL) {
       
   180 		fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError());
       
   181 		SDL_Quit();
       
   182 		return(1);
       
   183 	}
   173 
   184 
   174 	current = 0;
   185 	current = 0;
   175 	SDL_SetCursor(cursor[current]);
   186 	SDL_SetCursor(cursor[current]);
   176 
   187 
   177 	while (!quit) {
   188 	while (!quit) {
   178 		SDL_Event	event;
   189 		SDL_Event	event;
   179 		while (SDL_PollEvent(&event)) {
   190 		while (SDL_PollEvent(&event)) {
   180 			switch(event.type) {
   191 			switch(event.type) {
   181 				case SDL_MOUSEBUTTONDOWN:
   192 				case SDL_MOUSEBUTTONDOWN:
   182 					current = !current;
   193 					current = (current + 1)%3;
   183 					SDL_SetCursor(cursor[current]);
   194 					SDL_SetCursor(cursor[current]);
   184 					break;
   195 					break;
   185 				case SDL_KEYDOWN:
   196 				case SDL_KEYDOWN:
   186 					if (event.key.keysym.sym == SDLK_ESCAPE) {
   197 					if (event.key.keysym.sym == SDLK_ESCAPE) {
   187 						quit = SDL_TRUE;
   198 						quit = SDL_TRUE;