Mercurial > sdl-ios-xcode
diff test/testcursor.c @ 1862:fe99535ac064
Test case for bug #240
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 20 Jun 2006 04:04:25 +0000 |
parents | 2fce7697adca |
children | 2780f547f5e7 |
line wrap: on
line diff
--- a/test/testcursor.c Tue Jun 20 03:52:41 2006 +0000 +++ b/test/testcursor.c Tue Jun 20 04:04:25 2006 +0000 @@ -55,12 +55,92 @@ 0xff00 }; + +/* XPM */ +static const char *arrow[] = { + /* width height num_colors chars_per_pixel */ + " 32 32 3 1", + /* colors */ + "X c #000000", + ". c #ffffff", + " c None", + /* pixels */ + "X ", + "XX ", + "X.X ", + "X..X ", + "X...X ", + "X....X ", + "X.....X ", + "X......X ", + "X.......X ", + "X........X ", + "X.....XXXXX ", + "X..X..X ", + "X.X X..X ", + "XX X..X ", + "X X..X ", + " X..X ", + " X..X ", + " X..X ", + " XX ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + "0,0" +}; + +static SDL_Cursor *create_arrow_cursor() +{ + int i, row, col; + Uint8 data[4*32]; + Uint8 mask[4*32]; + int hot_x, hot_y; + + i = -1; + for ( row=0; row<32; ++row ) { + for ( col=0; col<32; ++col ) { + if ( col % 8 ) { + data[i] <<= 1; + mask[i] <<= 1; + } else { + ++i; + data[i] = mask[i] = 0; + } + switch (arrow[4+row][col]) { + case 'X': + data[i] |= 0x01; + mask[i] |= 0x01; + break; + case '.': + mask[i] |= 0x01; + break; + case ' ': + break; + } + } + } + sscanf(arrow[4+row], "%d,%d", &hot_x, &hot_y); + return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y); +} + + 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; + SDL_Cursor *cursor[2]; + int current; /* Load the SDL library */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { @@ -74,25 +154,34 @@ 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, + cursor[0] = 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()); + if (cursor[0]==NULL) { + fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError()); + SDL_Quit(); + return(1); + } + cursor[1] = create_arrow_cursor(); + if (cursor[1]==NULL) { + fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",SDL_GetError()); + SDL_FreeCursor(cursor[0]); + SDL_Quit(); return(1); } - SDL_SetCursor(cursor); + current = 0; + SDL_SetCursor(cursor[current]); while (!quit) { SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { + case SDL_MOUSEBUTTONDOWN: + current = !current; + SDL_SetCursor(cursor[current]); + break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) { quit = SDL_TRUE; @@ -103,18 +192,12 @@ break; } } - if (screen->flags & SDL_DOUBLEBUF) { - SDL_Flip(screen); - } else { - if (first_time) { - SDL_UpdateRects(screen, 1, &update_area); - first_time = SDL_FALSE; - } - } + SDL_Flip(screen); SDL_Delay(1); } - SDL_FreeCursor(cursor); + SDL_FreeCursor(cursor[0]); + SDL_FreeCursor(cursor[1]); SDL_Quit(); return(0);