test/testcursor.c
changeset 1895 c121d94672cb
parent 1883 2780f547f5e7
child 2088 3bdb1408f734
     1.1 --- a/test/testcursor.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/test/testcursor.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -11,205 +11,213 @@
     1.4  	(swap left and right for different endianness)
     1.5  */
     1.6  
     1.7 -Uint16 cursor_data[16]={
     1.8 -	0xffff,
     1.9 -	0xffff,
    1.10 -	0xffff,
    1.11 -	0xffff,	
    1.12 +Uint16 cursor_data[16] = {
    1.13 +    0xffff,
    1.14 +    0xffff,
    1.15 +    0xffff,
    1.16 +    0xffff,
    1.17  
    1.18 -	0xffff,
    1.19 -	0xffff,
    1.20 -	0xffff,
    1.21 -	0xffff,	
    1.22 +    0xffff,
    1.23 +    0xffff,
    1.24 +    0xffff,
    1.25 +    0xffff,
    1.26  
    1.27 -	0x0000,
    1.28 -	0x0000,
    1.29 -	0x0000,
    1.30 -	0x0000,
    1.31 +    0x0000,
    1.32 +    0x0000,
    1.33 +    0x0000,
    1.34 +    0x0000,
    1.35  
    1.36 -	0x0000,
    1.37 -	0x0000,
    1.38 -	0x0000,
    1.39 -	0x0000
    1.40 +    0x0000,
    1.41 +    0x0000,
    1.42 +    0x0000,
    1.43 +    0x0000
    1.44  };
    1.45  
    1.46 -Uint16 cursor_mask[16]={
    1.47 -	0xff00,
    1.48 -	0xff00,
    1.49 -	0xff00,
    1.50 -	0xff00,
    1.51 +Uint16 cursor_mask[16] = {
    1.52 +    0xff00,
    1.53 +    0xff00,
    1.54 +    0xff00,
    1.55 +    0xff00,
    1.56  
    1.57 -	0xff00,
    1.58 -	0xff00,
    1.59 -	0xff00,
    1.60 -	0xff00,
    1.61 +    0xff00,
    1.62 +    0xff00,
    1.63 +    0xff00,
    1.64 +    0xff00,
    1.65  
    1.66 -	0xff00,
    1.67 -	0xff00,
    1.68 -	0xff00,
    1.69 -	0xff00,
    1.70 +    0xff00,
    1.71 +    0xff00,
    1.72 +    0xff00,
    1.73 +    0xff00,
    1.74  
    1.75 -	0xff00,
    1.76 -	0xff00,
    1.77 -	0xff00,
    1.78 -	0xff00
    1.79 +    0xff00,
    1.80 +    0xff00,
    1.81 +    0xff00,
    1.82 +    0xff00
    1.83  };
    1.84  
    1.85  /* another test cursor: smaller than 16x16, and with an odd height */
    1.86  
    1.87 -Uint8 small_cursor_data[11] = { 0x00, 0x18, 0x08, 0x38, 0x44, 0x54, 0x44, 0x38, 0x20, 0x20, 0x00 };
    1.88 -Uint8 small_cursor_mask[11] = { 0x3C, 0x3C, 0x3C, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x78, 0x70, 0x70 };
    1.89 +Uint8 small_cursor_data[11] =
    1.90 +    { 0x00, 0x18, 0x08, 0x38, 0x44, 0x54, 0x44, 0x38, 0x20, 0x20, 0x00 };
    1.91 +Uint8 small_cursor_mask[11] =
    1.92 +    { 0x3C, 0x3C, 0x3C, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x78, 0x70, 0x70 };
    1.93  
    1.94  /* XPM */
    1.95  static const char *arrow[] = {
    1.96 -  /* width height num_colors chars_per_pixel */
    1.97 -  "    32    32        3            1",
    1.98 -  /* colors */
    1.99 -  "X c #000000",
   1.100 -  ". c #ffffff",
   1.101 -  "  c None",
   1.102 -  /* pixels */
   1.103 -  "X                               ",
   1.104 -  "XX                              ",
   1.105 -  "X.X                             ",
   1.106 -  "X..X                            ",
   1.107 -  "X...X                           ",
   1.108 -  "X....X                          ",
   1.109 -  "X.....X                         ",
   1.110 -  "X......X                        ",
   1.111 -  "X.......X                       ",
   1.112 -  "X........X                      ",
   1.113 -  "X.....XXXXX                     ",
   1.114 -  "X..X..X                         ",
   1.115 -  "X.X X..X                        ",
   1.116 -  "XX  X..X                        ",
   1.117 -  "X    X..X                       ",
   1.118 -  "     X..X                       ",
   1.119 -  "      X..X                      ",
   1.120 -  "      X..X                      ",
   1.121 -  "       XX                       ",
   1.122 -  "                                ",
   1.123 -  "                                ",
   1.124 -  "                                ",
   1.125 -  "                                ",
   1.126 -  "                                ",
   1.127 -  "                                ",
   1.128 -  "                                ",
   1.129 -  "                                ",
   1.130 -  "                                ",
   1.131 -  "                                ",
   1.132 -  "                                ",
   1.133 -  "                                ",
   1.134 -  "                                ",
   1.135 -  "0,0"
   1.136 +    /* width height num_colors chars_per_pixel */
   1.137 +    "    32    32        3            1",
   1.138 +    /* colors */
   1.139 +    "X c #000000",
   1.140 +    ". c #ffffff",
   1.141 +    "  c None",
   1.142 +    /* pixels */
   1.143 +    "X                               ",
   1.144 +    "XX                              ",
   1.145 +    "X.X                             ",
   1.146 +    "X..X                            ",
   1.147 +    "X...X                           ",
   1.148 +    "X....X                          ",
   1.149 +    "X.....X                         ",
   1.150 +    "X......X                        ",
   1.151 +    "X.......X                       ",
   1.152 +    "X........X                      ",
   1.153 +    "X.....XXXXX                     ",
   1.154 +    "X..X..X                         ",
   1.155 +    "X.X X..X                        ",
   1.156 +    "XX  X..X                        ",
   1.157 +    "X    X..X                       ",
   1.158 +    "     X..X                       ",
   1.159 +    "      X..X                      ",
   1.160 +    "      X..X                      ",
   1.161 +    "       XX                       ",
   1.162 +    "                                ",
   1.163 +    "                                ",
   1.164 +    "                                ",
   1.165 +    "                                ",
   1.166 +    "                                ",
   1.167 +    "                                ",
   1.168 +    "                                ",
   1.169 +    "                                ",
   1.170 +    "                                ",
   1.171 +    "                                ",
   1.172 +    "                                ",
   1.173 +    "                                ",
   1.174 +    "                                ",
   1.175 +    "0,0"
   1.176  };
   1.177  
   1.178 -static SDL_Cursor *create_arrow_cursor()
   1.179 +static SDL_Cursor *
   1.180 +create_arrow_cursor()
   1.181  {
   1.182 -  int i, row, col;
   1.183 -  Uint8 data[4*32];
   1.184 -  Uint8 mask[4*32];
   1.185 -  int hot_x, hot_y;
   1.186 +    int i, row, col;
   1.187 +    Uint8 data[4 * 32];
   1.188 +    Uint8 mask[4 * 32];
   1.189 +    int hot_x, hot_y;
   1.190  
   1.191 -  i = -1;
   1.192 -  for ( row=0; row<32; ++row ) {
   1.193 -    for ( col=0; col<32; ++col ) {
   1.194 -      if ( col % 8 ) {
   1.195 -        data[i] <<= 1;
   1.196 -        mask[i] <<= 1;
   1.197 -      } else {
   1.198 -        ++i;
   1.199 -        data[i] = mask[i] = 0;
   1.200 -      }
   1.201 -      switch (arrow[4+row][col]) {
   1.202 -        case 'X':
   1.203 -          data[i] |= 0x01;
   1.204 -          mask[i] |= 0x01;
   1.205 -          break;
   1.206 -        case '.':
   1.207 -          mask[i] |= 0x01;
   1.208 -          break;
   1.209 -        case ' ':
   1.210 -          break;
   1.211 -      }
   1.212 +    i = -1;
   1.213 +    for (row = 0; row < 32; ++row) {
   1.214 +        for (col = 0; col < 32; ++col) {
   1.215 +            if (col % 8) {
   1.216 +                data[i] <<= 1;
   1.217 +                mask[i] <<= 1;
   1.218 +            } else {
   1.219 +                ++i;
   1.220 +                data[i] = mask[i] = 0;
   1.221 +            }
   1.222 +            switch (arrow[4 + row][col]) {
   1.223 +            case 'X':
   1.224 +                data[i] |= 0x01;
   1.225 +                mask[i] |= 0x01;
   1.226 +                break;
   1.227 +            case '.':
   1.228 +                mask[i] |= 0x01;
   1.229 +                break;
   1.230 +            case ' ':
   1.231 +                break;
   1.232 +            }
   1.233 +        }
   1.234      }
   1.235 -  }
   1.236 -  sscanf(arrow[4+row], "%d,%d", &hot_x, &hot_y);
   1.237 -  return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
   1.238 +    sscanf(arrow[4 + row], "%d,%d", &hot_x, &hot_y);
   1.239 +    return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
   1.240  }
   1.241  
   1.242  
   1.243 -int main(int argc, char *argv[])
   1.244 +int
   1.245 +main(int argc, char *argv[])
   1.246  {
   1.247 -	SDL_Surface *screen;
   1.248 -	SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
   1.249 -	SDL_Cursor *cursor[3];
   1.250 -	int current;
   1.251 +    SDL_Surface *screen;
   1.252 +    SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
   1.253 +    SDL_Cursor *cursor[3];
   1.254 +    int current;
   1.255  
   1.256 -	/* Load the SDL library */
   1.257 -	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   1.258 -		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
   1.259 -		return(1);
   1.260 -	}
   1.261 +    /* Load the SDL library */
   1.262 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   1.263 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.264 +        return (1);
   1.265 +    }
   1.266  
   1.267 -	screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT);
   1.268 -	if (screen==NULL) {
   1.269 -		fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError());
   1.270 -		return(1);
   1.271 -	}
   1.272 +    screen = SDL_SetVideoMode(320, 200, 8, SDL_ANYFORMAT);
   1.273 +    if (screen == NULL) {
   1.274 +        fprintf(stderr, "Couldn't initialize video mode: %s\n",
   1.275 +                SDL_GetError());
   1.276 +        return (1);
   1.277 +    }
   1.278  
   1.279 -	SDL_FillRect(screen, NULL, 0x664422);
   1.280 +    SDL_FillRect(screen, NULL, 0x664422);
   1.281  
   1.282 -	cursor[0] = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask,
   1.283 -		16, 16, 8, 8);
   1.284 -	if (cursor[0]==NULL) {
   1.285 -		fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError());
   1.286 -		SDL_Quit();
   1.287 -		return(1);
   1.288 -	}
   1.289 -	cursor[1] = create_arrow_cursor();
   1.290 -	if (cursor[1]==NULL) {
   1.291 -		fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",SDL_GetError());
   1.292 -		SDL_FreeCursor(cursor[0]);
   1.293 -		SDL_Quit();
   1.294 -		return(1);
   1.295 -	}
   1.296 -	cursor[2] = SDL_CreateCursor(small_cursor_data, small_cursor_mask,
   1.297 -		8, 11, 3, 5);
   1.298 -	if (cursor[2]==NULL) {
   1.299 -		fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError());
   1.300 -		SDL_Quit();
   1.301 -		return(1);
   1.302 -	}
   1.303 +    cursor[0] = SDL_CreateCursor((Uint8 *) cursor_data, (Uint8 *) cursor_mask,
   1.304 +                                 16, 16, 8, 8);
   1.305 +    if (cursor[0] == NULL) {
   1.306 +        fprintf(stderr, "Couldn't initialize test cursor: %s\n",
   1.307 +                SDL_GetError());
   1.308 +        SDL_Quit();
   1.309 +        return (1);
   1.310 +    }
   1.311 +    cursor[1] = create_arrow_cursor();
   1.312 +    if (cursor[1] == NULL) {
   1.313 +        fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",
   1.314 +                SDL_GetError());
   1.315 +        SDL_FreeCursor(cursor[0]);
   1.316 +        SDL_Quit();
   1.317 +        return (1);
   1.318 +    }
   1.319 +    cursor[2] = SDL_CreateCursor(small_cursor_data, small_cursor_mask,
   1.320 +                                 8, 11, 3, 5);
   1.321 +    if (cursor[2] == NULL) {
   1.322 +        fprintf(stderr, "Couldn't initialize test cursor: %s\n",
   1.323 +                SDL_GetError());
   1.324 +        SDL_Quit();
   1.325 +        return (1);
   1.326 +    }
   1.327  
   1.328 -	current = 0;
   1.329 -	SDL_SetCursor(cursor[current]);
   1.330 +    current = 0;
   1.331 +    SDL_SetCursor(cursor[current]);
   1.332  
   1.333 -	while (!quit) {
   1.334 -		SDL_Event	event;
   1.335 -		while (SDL_PollEvent(&event)) {
   1.336 -			switch(event.type) {
   1.337 -				case SDL_MOUSEBUTTONDOWN:
   1.338 -					current = (current + 1)%3;
   1.339 -					SDL_SetCursor(cursor[current]);
   1.340 -					break;
   1.341 -				case SDL_KEYDOWN:
   1.342 -					if (event.key.keysym.sym == SDLK_ESCAPE) {
   1.343 -						quit = SDL_TRUE;
   1.344 -					}
   1.345 -					break;
   1.346 -				case SDL_QUIT:
   1.347 -					quit = SDL_TRUE;
   1.348 -					break;
   1.349 -			}
   1.350 -		}	
   1.351 -		SDL_Flip(screen);
   1.352 -		SDL_Delay(1);
   1.353 -	}
   1.354 +    while (!quit) {
   1.355 +        SDL_Event event;
   1.356 +        while (SDL_PollEvent(&event)) {
   1.357 +            switch (event.type) {
   1.358 +            case SDL_MOUSEBUTTONDOWN:
   1.359 +                current = (current + 1) % 3;
   1.360 +                SDL_SetCursor(cursor[current]);
   1.361 +                break;
   1.362 +            case SDL_KEYDOWN:
   1.363 +                if (event.key.keysym.sym == SDLK_ESCAPE) {
   1.364 +                    quit = SDL_TRUE;
   1.365 +                }
   1.366 +                break;
   1.367 +            case SDL_QUIT:
   1.368 +                quit = SDL_TRUE;
   1.369 +                break;
   1.370 +            }
   1.371 +        }
   1.372 +        SDL_Flip(screen);
   1.373 +        SDL_Delay(1);
   1.374 +    }
   1.375  
   1.376 -	SDL_FreeCursor(cursor[0]);
   1.377 -	SDL_FreeCursor(cursor[1]);
   1.378 +    SDL_FreeCursor(cursor[0]);
   1.379 +    SDL_FreeCursor(cursor[1]);
   1.380  
   1.381 -	SDL_Quit();
   1.382 -	return(0);
   1.383 +    SDL_Quit();
   1.384 +    return (0);
   1.385  }