Add program to test mouse cursor change
authorPatrice Mandin <patmandin@gmail.com>
Wed, 14 Jun 2006 18:59:30 +0000
changeset 1858d3ac464fb3c1
parent 1857 417f2af2bd52
child 1859 2fce7697adca
Add program to test mouse cursor change
test/Makefile.in
test/testcursor.c
     1.1 --- a/test/Makefile.in	Wed Jun 14 18:57:58 2006 +0000
     1.2 +++ b/test/Makefile.in	Wed Jun 14 18:59:30 2006 +0000
     1.3 @@ -7,7 +7,7 @@
     1.4  CFLAGS  = @CFLAGS@
     1.5  LIBS	= @LIBS@
     1.6  
     1.7 -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
     1.8 +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
     1.9  
    1.10  all: $(TARGETS)
    1.11  
    1.12 @@ -32,6 +32,9 @@
    1.13  testcdrom$(EXE): $(srcdir)/testcdrom.c
    1.14  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.15  
    1.16 +testcursor$(EXE): $(srcdir)/testcursor.c
    1.17 +	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.18 +
    1.19  testdyngl$(EXE): $(srcdir)/testdyngl.c
    1.20  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.21  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/testcursor.c	Wed Jun 14 18:59:30 2006 +0000
     2.3 @@ -0,0 +1,121 @@
     2.4 +#include <stdio.h>
     2.5 +#include <stdlib.h>
     2.6 +
     2.7 +#include "SDL.h"
     2.8 +
     2.9 +/* This is an example 16x16 cursor
    2.10 +	top left :	black
    2.11 +	top right : inverted color or black
    2.12 +	bottom left: white
    2.13 +	bottom right: transparent
    2.14 +	(swap left and right for different endianness)
    2.15 +*/
    2.16 +
    2.17 +Uint16 cursor_data[16]={
    2.18 +	0xffff,
    2.19 +	0xffff,
    2.20 +	0xffff,
    2.21 +	0xffff,	
    2.22 +
    2.23 +	0xffff,
    2.24 +	0xffff,
    2.25 +	0xffff,
    2.26 +	0xffff,	
    2.27 +
    2.28 +	0x0000,
    2.29 +	0x0000,
    2.30 +	0x0000,
    2.31 +	0x0000,
    2.32 +
    2.33 +	0x0000,
    2.34 +	0x0000,
    2.35 +	0x0000,
    2.36 +	0x0000
    2.37 +};
    2.38 +
    2.39 +Uint16 cursor_mask[16]={
    2.40 +	0xff00,
    2.41 +	0xff00,
    2.42 +	0xff00,
    2.43 +	0xff00,
    2.44 +
    2.45 +	0xff00,
    2.46 +	0xff00,
    2.47 +	0xff00,
    2.48 +	0xff00,
    2.49 +
    2.50 +	0xff00,
    2.51 +	0xff00,
    2.52 +	0xff00,
    2.53 +	0xff00,
    2.54 +
    2.55 +	0xff00,
    2.56 +	0xff00,
    2.57 +	0xff00,
    2.58 +	0xff00
    2.59 +};
    2.60 +
    2.61 +int main(int argc, char *argv[])
    2.62 +{
    2.63 +	SDL_Surface *screen;
    2.64 +	SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
    2.65 +	SDL_Cursor *cursor;
    2.66 +	SDL_Rect update_area;
    2.67 +
    2.68 +	/* Load the SDL library */
    2.69 +	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    2.70 +		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    2.71 +		return(1);
    2.72 +	}
    2.73 +
    2.74 +	screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT);
    2.75 +	if (screen==NULL) {
    2.76 +		fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError());
    2.77 +		return(1);
    2.78 +	}
    2.79 +
    2.80 +	update_area.x = update_area.y = 0;
    2.81 +	update_area.w = screen->w;
    2.82 +	update_area.h = screen->h;
    2.83 +
    2.84 +	SDL_FillRect(screen, NULL, 0x664422);
    2.85 +
    2.86 +	cursor = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask,
    2.87 +		16, 16, 8, 8);
    2.88 +	if (cursor==NULL) {
    2.89 +		fprintf(stderr, "Couldn't initialize cursor: %s\n",SDL_GetError());
    2.90 +		return(1);
    2.91 +	}
    2.92 +
    2.93 +	SDL_SetCursor(cursor);
    2.94 +
    2.95 +	while (!quit) {
    2.96 +		SDL_Event	event;
    2.97 +		while (SDL_PollEvent(&event)) {
    2.98 +			switch(event.type) {
    2.99 +				case SDL_KEYDOWN:
   2.100 +					if (event.key.keysym.sym == SDLK_ESCAPE) {
   2.101 +						quit = SDL_TRUE;
   2.102 +					}
   2.103 +					break;
   2.104 +				case SDL_QUIT:
   2.105 +					quit = SDL_TRUE;
   2.106 +					break;
   2.107 +			}
   2.108 +		}	
   2.109 +		if (screen->flags & SDL_DOUBLEBUF) {
   2.110 +			if (first_time) {
   2.111 +				SDL_UpdateRects(screen, 1, &update_area);
   2.112 +				first_time = SDL_FALSE;
   2.113 +			}
   2.114 +		} else {
   2.115 +			SDL_Flip(screen);
   2.116 +		}	
   2.117 +		SDL_Delay(1);
   2.118 +	}
   2.119 +
   2.120 +	SDL_FreeCursor(cursor);
   2.121 +
   2.122 +	SDL_Quit();
   2.123 +	return(0);
   2.124 +}