author | Brandon Schaefer <brandon.schaefer@canonical.com> |
Wed, 13 Jul 2016 07:39:01 -0700 | |
changeset 10195 | 23fb5052dab4 |
parent 10194 | a4eb7861e89c |
permissions | -rw-r--r-- |
10194
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
1 |
/* |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
2 |
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
3 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
4 |
This software is provided 'as-is', without any express or implied |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
5 |
warranty. In no event will the authors be held liable for any damages |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
6 |
arising from the use of this software. |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
7 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
8 |
Permission is granted to anyone to use this software for any purpose, |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
9 |
including commercial applications, and to alter it and redistribute it |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
10 |
freely. |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
11 |
*/ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
12 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
13 |
#include <stdlib.h> |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
14 |
#include <stdio.h> |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
15 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
16 |
#ifdef __EMSCRIPTEN__ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
17 |
#include <emscripten/emscripten.h> |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
18 |
#endif |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
19 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
20 |
#include "SDL_test_common.h" |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
21 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
22 |
/* Stolen from the mailing list */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
23 |
/* Creates a new mouse cursor from an XPM */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
24 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
25 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
26 |
/* XPM */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
27 |
static const char *arrow[] = { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
28 |
/* width height num_colors chars_per_pixel */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
29 |
" 32 32 3 1", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
30 |
/* colors */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
31 |
"X c #000000", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
32 |
". c #ffffff", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
33 |
" c None", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
34 |
/* pixels */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
35 |
"X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
36 |
"XX ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
37 |
"X.X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
38 |
"X..X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
39 |
"X...X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
40 |
"X....X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
41 |
"X.....X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
42 |
"X......X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
43 |
"X.......X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
44 |
"X........X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
45 |
"X.....XXXXX ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
46 |
"X..X..X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
47 |
"X.X X..X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
48 |
"XX X..X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
49 |
"X X..X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
50 |
" X..X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
51 |
" X..X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
52 |
" X..X ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
53 |
" XX ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
54 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
55 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
56 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
57 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
58 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
59 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
60 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
61 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
62 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
63 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
64 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
65 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
66 |
" ", |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
67 |
"0,0" |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
68 |
}; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
69 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
70 |
static SDL_Cursor* |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
71 |
init_system_cursor(const char *image[]) |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
72 |
{ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
73 |
int i, row, col; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
74 |
Uint8 data[4*32]; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
75 |
Uint8 mask[4*32]; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
76 |
int hot_x, hot_y; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
77 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
78 |
i = -1; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
79 |
for (row=0; row<32; ++row) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
80 |
for (col=0; col<32; ++col) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
81 |
if (col % 8) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
82 |
data[i] <<= 1; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
83 |
mask[i] <<= 1; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
84 |
} else { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
85 |
++i; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
86 |
data[i] = mask[i] = 0; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
87 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
88 |
switch (image[4+row][col]) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
89 |
case 'X': |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
90 |
data[i] |= 0x01; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
91 |
mask[i] |= 0x01; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
92 |
break; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
93 |
case '.': |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
94 |
mask[i] |= 0x01; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
95 |
break; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
96 |
case ' ': |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
97 |
break; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
98 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
99 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
100 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
101 |
sscanf(image[4+row], "%d,%d", &hot_x, &hot_y); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
102 |
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
103 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
104 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
105 |
static SDLTest_CommonState *state; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
106 |
int done; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
107 |
SDL_Cursor *cursor = NULL; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
108 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
109 |
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
110 |
static void |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
111 |
quit(int rc) |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
112 |
{ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
113 |
SDLTest_CommonQuit(state); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
114 |
exit(rc); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
115 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
116 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
117 |
void |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
118 |
loop() |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
119 |
{ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
120 |
int i; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
121 |
SDL_Event event; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
122 |
/* Check for events */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
123 |
while (SDL_PollEvent(&event)) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
124 |
SDLTest_CommonEvent(state, &event, &done); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
125 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
126 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
127 |
for (i = 0; i < state->num_windows; ++i) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
128 |
SDL_Renderer *renderer = state->renderers[i]; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
129 |
SDL_RenderClear(renderer); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
130 |
SDL_RenderPresent(renderer); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
131 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
132 |
#ifdef __EMSCRIPTEN__ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
133 |
if (done) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
134 |
emscripten_cancel_main_loop(); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
135 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
136 |
#endif |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
137 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
138 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
139 |
int |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
140 |
main(int argc, char *argv[]) |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
141 |
{ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
142 |
int i; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
143 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
144 |
/* Enable standard application logging */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
145 |
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
146 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
147 |
/* Initialize test framework */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
148 |
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
149 |
if (!state) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
150 |
return 1; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
151 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
152 |
for (i = 1; i < argc;) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
153 |
int consumed; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
154 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
155 |
consumed = SDLTest_CommonArg(state, i); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
156 |
if (consumed == 0) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
157 |
consumed = -1; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
158 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
159 |
if (consumed < 0) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
160 |
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
161 |
quit(1); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
162 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
163 |
i += consumed; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
164 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
165 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
166 |
if (!SDLTest_CommonInit(state)) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
167 |
quit(2); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
168 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
169 |
|
10195
23fb5052dab4
Tests: Somehow tabs leaked in...
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
10194
diff
changeset
|
170 |
for (i = 0; i < state->num_windows; ++i) { |
23fb5052dab4
Tests: Somehow tabs leaked in...
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
10194
diff
changeset
|
171 |
SDL_Renderer *renderer = state->renderers[i]; |
23fb5052dab4
Tests: Somehow tabs leaked in...
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
10194
diff
changeset
|
172 |
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); |
23fb5052dab4
Tests: Somehow tabs leaked in...
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
10194
diff
changeset
|
173 |
SDL_RenderClear(renderer); |
23fb5052dab4
Tests: Somehow tabs leaked in...
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
10194
diff
changeset
|
174 |
} |
10194
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
175 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
176 |
cursor = init_system_cursor(arrow); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
177 |
SDL_SetCursor(cursor); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
178 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
179 |
/* Main render loop */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
180 |
done = 0; |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
181 |
#ifdef __EMSCRIPTEN__ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
182 |
emscripten_set_main_loop(loop, 0, 1); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
183 |
#else |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
184 |
while (!done) { |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
185 |
loop(); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
186 |
} |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
187 |
#endif |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
188 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
189 |
SDL_FreeCursor(cursor); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
190 |
quit(0); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
191 |
|
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
192 |
/* keep the compiler happy ... */ |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
193 |
return(0); |
a4eb7861e89c
Tests: Add a manual test for a custom cursor (Taken from the API docs)
Brandon Schaefer <brandon.schaefer@canonical.com>
parents:
diff
changeset
|
194 |
} |