annotate test/testcursor.c @ 1727:90a3e0fccb88 SDL-1.3

Started on the OpenGL API revamp.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 07 Jul 2006 10:29:16 +0000
parents cd14138a8703
children
rev   line source
1708
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 #include <stdio.h>
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 #include <stdlib.h>
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 #include "SDL.h"
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 /* This is an example 16x16 cursor
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 top left : black
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 top right : inverted color or black
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 bottom left: white
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 bottom right: transparent
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 (swap left and right for different endianness)
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 */
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 Uint16 cursor_data[16] = {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 0xffff,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 0xffff,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 0xffff,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 0xffff,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 0xffff,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 0xffff,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 0xffff,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 0xffff,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 0x0000,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 0x0000,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 0x0000,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 0x0000,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 0x0000,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 0x0000,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 0x0000,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 0x0000
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 };
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 Uint16 cursor_mask[16] = {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 0xff00,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 0xff00
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 };
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 /* another test cursor: smaller than 16x16, and with an odd height */
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 Uint8 small_cursor_data[11] =
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 { 0x00, 0x18, 0x08, 0x38, 0x44, 0x54, 0x44, 0x38, 0x20, 0x20, 0x00 };
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 Uint8 small_cursor_mask[11] =
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 { 0x3C, 0x3C, 0x3C, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x78, 0x70, 0x70 };
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 /* XPM */
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 static const char *arrow[] = {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 /* width height num_colors chars_per_pixel */
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 " 32 32 3 1",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 /* colors */
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 "X c #000000",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 ". c #ffffff",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 " c None",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 /* pixels */
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 "X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 "XX ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 "X.X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 "X..X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 "X...X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 "X....X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 "X.....X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 "X......X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 "X.......X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 "X........X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 "X.....XXXXX ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 "X..X..X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 "X.X X..X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 "XX X..X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 "X X..X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 " X..X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 " X..X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 " X..X ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 " XX ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 " ",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 "0,0"
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 };
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 static SDL_Cursor *
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 create_arrow_cursor()
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 int i, row, col;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 Uint8 data[4 * 32];
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 Uint8 mask[4 * 32];
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 int hot_x, hot_y;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 i = -1;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 for (row = 0; row < 32; ++row) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 for (col = 0; col < 32; ++col) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 if (col % 8) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 data[i] <<= 1;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 mask[i] <<= 1;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 } else {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 ++i;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 data[i] = mask[i] = 0;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 switch (arrow[4 + row][col]) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 case 'X':
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 data[i] |= 0x01;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 mask[i] |= 0x01;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 break;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 case '.':
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 mask[i] |= 0x01;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 break;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 case ' ':
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 break;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 sscanf(arrow[4 + row], "%d,%d", &hot_x, &hot_y);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 int
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 main(int argc, char *argv[])
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 SDL_Surface *screen;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 SDL_Cursor *cursor[3];
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 int current;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 /* Load the SDL library */
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 return (1);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 screen = SDL_SetVideoMode(320, 200, 8, SDL_ANYFORMAT);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 if (screen == NULL) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 fprintf(stderr, "Couldn't initialize video mode: %s\n",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 SDL_GetError());
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 return (1);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 SDL_FillRect(screen, NULL, 0x664422);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 cursor[0] = SDL_CreateCursor((Uint8 *) cursor_data, (Uint8 *) cursor_mask,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 16, 16, 8, 8);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 if (cursor[0] == NULL) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 fprintf(stderr, "Couldn't initialize test cursor: %s\n",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 SDL_GetError());
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 SDL_Quit();
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 return (1);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 cursor[1] = create_arrow_cursor();
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 if (cursor[1] == NULL) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 SDL_GetError());
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 SDL_FreeCursor(cursor[0]);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 SDL_Quit();
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 return (1);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 cursor[2] = SDL_CreateCursor(small_cursor_data, small_cursor_mask,
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 8, 11, 3, 5);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 if (cursor[2] == NULL) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 fprintf(stderr, "Couldn't initialize test cursor: %s\n",
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 SDL_GetError());
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 SDL_Quit();
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 return (1);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 current = 0;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 SDL_SetCursor(cursor[current]);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 while (!quit) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 SDL_Event event;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 while (SDL_PollEvent(&event)) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 switch (event.type) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 case SDL_MOUSEBUTTONDOWN:
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 current = (current + 1) % 3;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 SDL_SetCursor(cursor[current]);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 break;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 case SDL_KEYDOWN:
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 if (event.key.keysym.sym == SDLK_ESCAPE) {
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 quit = SDL_TRUE;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 break;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 case SDL_QUIT:
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 quit = SDL_TRUE;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 break;
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 SDL_Flip(screen);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 SDL_Delay(1);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 }
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 SDL_FreeCursor(cursor[0]);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 SDL_FreeCursor(cursor[1]);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 SDL_Quit();
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 return (0);
cd14138a8703 Merged fix for bug #240 from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 }