Mercurial > sdl-ios-xcode
comparison test/testcursor.c @ 1858:d3ac464fb3c1
Add program to test mouse cursor change
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Wed, 14 Jun 2006 18:59:30 +0000 |
parents | |
children | 2fce7697adca |
comparison
equal
deleted
inserted
replaced
1857:417f2af2bd52 | 1858:d3ac464fb3c1 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 | |
4 #include "SDL.h" | |
5 | |
6 /* This is an example 16x16 cursor | |
7 top left : black | |
8 top right : inverted color or black | |
9 bottom left: white | |
10 bottom right: transparent | |
11 (swap left and right for different endianness) | |
12 */ | |
13 | |
14 Uint16 cursor_data[16]={ | |
15 0xffff, | |
16 0xffff, | |
17 0xffff, | |
18 0xffff, | |
19 | |
20 0xffff, | |
21 0xffff, | |
22 0xffff, | |
23 0xffff, | |
24 | |
25 0x0000, | |
26 0x0000, | |
27 0x0000, | |
28 0x0000, | |
29 | |
30 0x0000, | |
31 0x0000, | |
32 0x0000, | |
33 0x0000 | |
34 }; | |
35 | |
36 Uint16 cursor_mask[16]={ | |
37 0xff00, | |
38 0xff00, | |
39 0xff00, | |
40 0xff00, | |
41 | |
42 0xff00, | |
43 0xff00, | |
44 0xff00, | |
45 0xff00, | |
46 | |
47 0xff00, | |
48 0xff00, | |
49 0xff00, | |
50 0xff00, | |
51 | |
52 0xff00, | |
53 0xff00, | |
54 0xff00, | |
55 0xff00 | |
56 }; | |
57 | |
58 int main(int argc, char *argv[]) | |
59 { | |
60 SDL_Surface *screen; | |
61 SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE; | |
62 SDL_Cursor *cursor; | |
63 SDL_Rect update_area; | |
64 | |
65 /* Load the SDL library */ | |
66 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | |
67 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | |
68 return(1); | |
69 } | |
70 | |
71 screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT); | |
72 if (screen==NULL) { | |
73 fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError()); | |
74 return(1); | |
75 } | |
76 | |
77 update_area.x = update_area.y = 0; | |
78 update_area.w = screen->w; | |
79 update_area.h = screen->h; | |
80 | |
81 SDL_FillRect(screen, NULL, 0x664422); | |
82 | |
83 cursor = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask, | |
84 16, 16, 8, 8); | |
85 if (cursor==NULL) { | |
86 fprintf(stderr, "Couldn't initialize cursor: %s\n",SDL_GetError()); | |
87 return(1); | |
88 } | |
89 | |
90 SDL_SetCursor(cursor); | |
91 | |
92 while (!quit) { | |
93 SDL_Event event; | |
94 while (SDL_PollEvent(&event)) { | |
95 switch(event.type) { | |
96 case SDL_KEYDOWN: | |
97 if (event.key.keysym.sym == SDLK_ESCAPE) { | |
98 quit = SDL_TRUE; | |
99 } | |
100 break; | |
101 case SDL_QUIT: | |
102 quit = SDL_TRUE; | |
103 break; | |
104 } | |
105 } | |
106 if (screen->flags & SDL_DOUBLEBUF) { | |
107 if (first_time) { | |
108 SDL_UpdateRects(screen, 1, &update_area); | |
109 first_time = SDL_FALSE; | |
110 } | |
111 } else { | |
112 SDL_Flip(screen); | |
113 } | |
114 SDL_Delay(1); | |
115 } | |
116 | |
117 SDL_FreeCursor(cursor); | |
118 | |
119 SDL_Quit(); | |
120 return(0); | |
121 } |