From 568e5ad4641ebe08513b3444e95d3793ade6114e Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Wed, 14 Jun 2006 18:59:30 +0000 Subject: [PATCH] Add program to test mouse cursor change --- test/Makefile.in | 5 +- test/testcursor.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 test/testcursor.c diff --git a/test/Makefile.in b/test/Makefile.in index 52fd803e5..f589aaa4e 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -7,7 +7,7 @@ EXE = @EXE@ CFLAGS = @CFLAGS@ LIBS = @LIBS@ -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) +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) all: $(TARGETS) @@ -32,6 +32,9 @@ testblitspeed$(EXE): $(srcdir)/testblitspeed.c testcdrom$(EXE): $(srcdir)/testcdrom.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) +testcursor$(EXE): $(srcdir)/testcursor.c + $(CC) -o $@ $? $(CFLAGS) $(LIBS) + testdyngl$(EXE): $(srcdir)/testdyngl.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) diff --git a/test/testcursor.c b/test/testcursor.c new file mode 100644 index 000000000..38d58542e --- /dev/null +++ b/test/testcursor.c @@ -0,0 +1,121 @@ +#include +#include + +#include "SDL.h" + +/* This is an example 16x16 cursor + top left : black + top right : inverted color or black + bottom left: white + bottom right: transparent + (swap left and right for different endianness) +*/ + +Uint16 cursor_data[16]={ + 0xffff, + 0xffff, + 0xffff, + 0xffff, + + 0xffff, + 0xffff, + 0xffff, + 0xffff, + + 0x0000, + 0x0000, + 0x0000, + 0x0000, + + 0x0000, + 0x0000, + 0x0000, + 0x0000 +}; + +Uint16 cursor_mask[16]={ + 0xff00, + 0xff00, + 0xff00, + 0xff00, + + 0xff00, + 0xff00, + 0xff00, + 0xff00, + + 0xff00, + 0xff00, + 0xff00, + 0xff00, + + 0xff00, + 0xff00, + 0xff00, + 0xff00 +}; + +int main(int argc, char *argv[]) +{ + SDL_Surface *screen; + SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE; + SDL_Cursor *cursor; + SDL_Rect update_area; + + /* Load the SDL library */ + if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { + fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); + return(1); + } + + screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT); + if (screen==NULL) { + fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError()); + return(1); + } + + update_area.x = update_area.y = 0; + update_area.w = screen->w; + update_area.h = screen->h; + + SDL_FillRect(screen, NULL, 0x664422); + + cursor = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask, + 16, 16, 8, 8); + if (cursor==NULL) { + fprintf(stderr, "Couldn't initialize cursor: %s\n",SDL_GetError()); + return(1); + } + + SDL_SetCursor(cursor); + + while (!quit) { + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch(event.type) { + case SDL_KEYDOWN: + if (event.key.keysym.sym == SDLK_ESCAPE) { + quit = SDL_TRUE; + } + break; + case SDL_QUIT: + quit = SDL_TRUE; + break; + } + } + if (screen->flags & SDL_DOUBLEBUF) { + if (first_time) { + SDL_UpdateRects(screen, 1, &update_area); + first_time = SDL_FALSE; + } + } else { + SDL_Flip(screen); + } + SDL_Delay(1); + } + + SDL_FreeCursor(cursor); + + SDL_Quit(); + return(0); +}