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