test/testcursor.c
changeset 1858 d3ac464fb3c1
child 1859 2fce7697adca
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testcursor.c	Wed Jun 14 18:59:30 2006 +0000
     1.3 @@ -0,0 +1,121 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +
     1.7 +#include "SDL.h"
     1.8 +
     1.9 +/* This is an example 16x16 cursor
    1.10 +	top left :	black
    1.11 +	top right : inverted color or black
    1.12 +	bottom left: white
    1.13 +	bottom right: transparent
    1.14 +	(swap left and right for different endianness)
    1.15 +*/
    1.16 +
    1.17 +Uint16 cursor_data[16]={
    1.18 +	0xffff,
    1.19 +	0xffff,
    1.20 +	0xffff,
    1.21 +	0xffff,	
    1.22 +
    1.23 +	0xffff,
    1.24 +	0xffff,
    1.25 +	0xffff,
    1.26 +	0xffff,	
    1.27 +
    1.28 +	0x0000,
    1.29 +	0x0000,
    1.30 +	0x0000,
    1.31 +	0x0000,
    1.32 +
    1.33 +	0x0000,
    1.34 +	0x0000,
    1.35 +	0x0000,
    1.36 +	0x0000
    1.37 +};
    1.38 +
    1.39 +Uint16 cursor_mask[16]={
    1.40 +	0xff00,
    1.41 +	0xff00,
    1.42 +	0xff00,
    1.43 +	0xff00,
    1.44 +
    1.45 +	0xff00,
    1.46 +	0xff00,
    1.47 +	0xff00,
    1.48 +	0xff00,
    1.49 +
    1.50 +	0xff00,
    1.51 +	0xff00,
    1.52 +	0xff00,
    1.53 +	0xff00,
    1.54 +
    1.55 +	0xff00,
    1.56 +	0xff00,
    1.57 +	0xff00,
    1.58 +	0xff00
    1.59 +};
    1.60 +
    1.61 +int main(int argc, char *argv[])
    1.62 +{
    1.63 +	SDL_Surface *screen;
    1.64 +	SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
    1.65 +	SDL_Cursor *cursor;
    1.66 +	SDL_Rect update_area;
    1.67 +
    1.68 +	/* Load the SDL library */
    1.69 +	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    1.70 +		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    1.71 +		return(1);
    1.72 +	}
    1.73 +
    1.74 +	screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT);
    1.75 +	if (screen==NULL) {
    1.76 +		fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError());
    1.77 +		return(1);
    1.78 +	}
    1.79 +
    1.80 +	update_area.x = update_area.y = 0;
    1.81 +	update_area.w = screen->w;
    1.82 +	update_area.h = screen->h;
    1.83 +
    1.84 +	SDL_FillRect(screen, NULL, 0x664422);
    1.85 +
    1.86 +	cursor = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask,
    1.87 +		16, 16, 8, 8);
    1.88 +	if (cursor==NULL) {
    1.89 +		fprintf(stderr, "Couldn't initialize cursor: %s\n",SDL_GetError());
    1.90 +		return(1);
    1.91 +	}
    1.92 +
    1.93 +	SDL_SetCursor(cursor);
    1.94 +
    1.95 +	while (!quit) {
    1.96 +		SDL_Event	event;
    1.97 +		while (SDL_PollEvent(&event)) {
    1.98 +			switch(event.type) {
    1.99 +				case SDL_KEYDOWN:
   1.100 +					if (event.key.keysym.sym == SDLK_ESCAPE) {
   1.101 +						quit = SDL_TRUE;
   1.102 +					}
   1.103 +					break;
   1.104 +				case SDL_QUIT:
   1.105 +					quit = SDL_TRUE;
   1.106 +					break;
   1.107 +			}
   1.108 +		}	
   1.109 +		if (screen->flags & SDL_DOUBLEBUF) {
   1.110 +			if (first_time) {
   1.111 +				SDL_UpdateRects(screen, 1, &update_area);
   1.112 +				first_time = SDL_FALSE;
   1.113 +			}
   1.114 +		} else {
   1.115 +			SDL_Flip(screen);
   1.116 +		}	
   1.117 +		SDL_Delay(1);
   1.118 +	}
   1.119 +
   1.120 +	SDL_FreeCursor(cursor);
   1.121 +
   1.122 +	SDL_Quit();
   1.123 +	return(0);
   1.124 +}