Skip to content

Latest commit

 

History

History
121 lines (101 loc) · 1.89 KB

testcursor.c

File metadata and controls

121 lines (101 loc) · 1.89 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <stdlib.h>
#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) {
Jun 14, 2006
Jun 14, 2006
107
108
SDL_Flip(screen);
} else {
109
110
111
112
113
114
115
116
117
118
119
120
121
if (first_time) {
SDL_UpdateRects(screen, 1, &update_area);
first_time = SDL_FALSE;
}
}
SDL_Delay(1);
}
SDL_FreeCursor(cursor);
SDL_Quit();
return(0);
}