annotate test/testcursor.c @ 4139:568c9b3c0167 SDL-1.2

* Added configure option --enable-screensaver, to allow enabling the screensaver by default. * Use XResetScreenSaver() instead of disabling screensaver entirely. Full discussion summary from Erik on the SDL mailing list: Current behaviour ================= SDL changes the user's display power management settings without permission from the user and without telling the user. The interface that it uses to do so is DPMSDisable/DPMSEnable, which should only ever be used by configuration utilities like KControl, never by normal application programs, let alone by the libraries that they use. Using an interface that is not at all intended for what SDL tries to achieve means that it will not work as it should. Firstly, the power management is completely disabled during the whole lifetime of the SDL program, not only when it should be. Secondly, it makes SDL non-reentrant, meaning that things will break when multiple SDL programs are clients of the same X server simultaneously. Thirdly, no cleanup mechanism ensures that the setting is restored if the client does not do that (for example if it crashes). In addition to that, this interface is broken on xorg, [http://bugs.freedesktop.org/show_bug.cgi?id=13962], so what SDL tries to do does not work at all on that implementation of the X Window System. (The reason that the DPMSEnable works in KControl is that it calls DPMSSetTimeout immediately after, [http://websvn.kde.org/tags/KDE/3.5.9/kdebase/kcontrol/energy/energy.cpp?annotate=774532#l343]). The problems that the current behaviour causes ============================================== 1. Information leak. When the user is away, someone might see what the user has on the display when the user counts on the screensaver preventing this. This does not even require physical access to the workstation, it is enough to see it from a distance. 2. Draining battery. An SDL program that runs on a laptop will quickly drain the battery while the user is away. The system will soon shut down and require recharging before being usable again, while it should in fact have consumed very little energy if the user's settings would have been obeyed. 3. Wasting energy. Even if battery issues are not considered, energy as such is wasted. 4. Display wear. The display may be worn out. The problems that the current behaviour tries to solve ====================================================== 1. Preventing screensaver while playing movies. Many SDL applications are media players. They have reasons to prevent screensavers from being activated while a movie is being played. When a user clicks on the play button it can be interpreted as saying "play this movie, but do not turn off the display while playing it, because I will watch it even though I do not interact with the system". 2. Preventing screensaver when some input bypasses X. Sometimes SDL uses input from another source than the X server, so that the X server is bypassed. This obviously breaks the screensaver handling. SDL tries to work around that. 3. Preventing screensaver when all input bypasses X. There is something called Direct Graphics Access mode, where a program takes control of both the display and the input devices from the X server. This obviously means that the X server can not handle the screensaver alone, since screensaver handling depends on input handling. SDL does not do what it should to help the X server to handle the screensaver. Nor does SDL take care of screeensaver handling itself. SDL simply disables the screensaver completely. How the problems should be solved ================================= The correct way for an application program to prevent the screensaver under X is to call XResetScreenSaver. This was recently discovered and implemented by the mplayer developers, [http://svn.mplayerhq.hu/mplayer?view=rev&revision=25637]. SDL needs to wrap this in an API call (SDL_ResetScreenSaver) and implement it for the other video targets (if they do not have a corresponding call, SDL should do what it takes on that particular target, for example sending fake key events). 1. When a movie is played, the player should reset the screensaver when the animation is advanced to a new frame. The same applies to anything similar, like slideshows. 2. When the X server is handling input, it must handle all input (keyboards, mice, gamepads, ...). This is necessary, not only to be able to handle the screensaver, but also so that it can send the events to the correct (the currently active) client. If there is an input device that the X server can not handle for some reason (such as lack of Plug and Play capability), the program that handles the device as a workaround must simulate what would happen if the X server would have handled the device, by calling XResetScreenSaver when input is received from the device. 3. When the X server is not handling the input, it depends on the program that does to call XResetScreenSaver whenever an input event occurs. Alternatively the program must handle the screensaver countdown internally and call XActivateScreenSaver.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 29 Feb 2008 13:55:44 +0000
parents e7d2858670c1
children
rev   line source
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
1883
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
58 /* another test cursor: smaller than 16x16, and with an odd height */
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
59
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
60 Uint8 small_cursor_data[11] = { 0x00, 0x18, 0x08, 0x38, 0x44, 0x54, 0x44, 0x38, 0x20, 0x20, 0x00 };
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
61 Uint8 small_cursor_mask[11] = { 0x3C, 0x3C, 0x3C, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x78, 0x70, 0x70 };
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
62
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
63 /* XPM */
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
64 static const char *arrow[] = {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
65 /* width height num_colors chars_per_pixel */
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
66 " 32 32 3 1",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
67 /* colors */
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
68 "X c #000000",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
69 ". c #ffffff",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
70 " c None",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
71 /* pixels */
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
72 "X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
73 "XX ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
74 "X.X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
75 "X..X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
76 "X...X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
77 "X....X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
78 "X.....X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
79 "X......X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
80 "X.......X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
81 "X........X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
82 "X.....XXXXX ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
83 "X..X..X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
84 "X.X X..X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
85 "XX X..X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
86 "X X..X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
87 " X..X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
88 " X..X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
89 " X..X ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
90 " XX ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
91 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
92 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
93 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
94 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
95 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
96 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
97 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
98 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
99 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
100 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
101 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
102 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
103 " ",
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
104 "0,0"
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
105 };
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
106
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
107 static SDL_Cursor *create_arrow_cursor()
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
108 {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
109 int i, row, col;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
110 Uint8 data[4*32];
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
111 Uint8 mask[4*32];
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
112 int hot_x, hot_y;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
113
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
114 i = -1;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
115 for ( row=0; row<32; ++row ) {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
116 for ( col=0; col<32; ++col ) {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
117 if ( col % 8 ) {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
118 data[i] <<= 1;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
119 mask[i] <<= 1;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
120 } else {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
121 ++i;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
122 data[i] = mask[i] = 0;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
123 }
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
124 switch (arrow[4+row][col]) {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
125 case 'X':
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
126 data[i] |= 0x01;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
127 mask[i] |= 0x01;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
128 break;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
129 case '.':
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
130 mask[i] |= 0x01;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
131 break;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
132 case ' ':
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
133 break;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
134 }
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
135 }
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
136 }
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
137 sscanf(arrow[4+row], "%d,%d", &hot_x, &hot_y);
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
138 return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
139 }
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
140
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
141
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
142 int main(int argc, char *argv[])
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
143 {
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
144 SDL_Surface *screen;
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
145 SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
1883
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
146 SDL_Cursor *cursor[3];
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
147 int current;
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
148
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
149 /* Load the SDL library */
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
150 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
151 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
152 return(1);
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
153 }
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
154
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
155 screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT);
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
156 if (screen==NULL) {
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
157 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
158 return(1);
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
159 }
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
160
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
161 SDL_FillRect(screen, NULL, 0x664422);
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
162
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
163 cursor[0] = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask,
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
164 16, 16, 8, 8);
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
165 if (cursor[0]==NULL) {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
166 fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError());
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
167 SDL_Quit();
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
168 return(1);
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
169 }
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
170 cursor[1] = create_arrow_cursor();
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
171 if (cursor[1]==NULL) {
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
172 fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",SDL_GetError());
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
173 SDL_FreeCursor(cursor[0]);
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
174 SDL_Quit();
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
175 return(1);
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
176 }
1883
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
177 cursor[2] = SDL_CreateCursor(small_cursor_data, small_cursor_mask,
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
178 8, 11, 3, 5);
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
179 if (cursor[2]==NULL) {
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
180 fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError());
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
181 SDL_Quit();
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
182 return(1);
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
183 }
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
184
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
185 current = 0;
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
186 SDL_SetCursor(cursor[current]);
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
187
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
188 while (!quit) {
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
189 SDL_Event event;
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
190 while (SDL_PollEvent(&event)) {
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
191 switch(event.type) {
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
192 case SDL_MOUSEBUTTONDOWN:
1883
2780f547f5e7 Fix for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1862
diff changeset
193 current = (current + 1)%3;
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
194 SDL_SetCursor(cursor[current]);
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
195 break;
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
196 case SDL_KEYDOWN:
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
197 if (event.key.keysym.sym == SDLK_ESCAPE) {
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
198 quit = SDL_TRUE;
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
199 }
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
200 break;
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
201 case SDL_QUIT:
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
202 quit = SDL_TRUE;
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
203 break;
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
204 }
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
205 }
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
206 SDL_Flip(screen);
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
207 SDL_Delay(1);
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
208 }
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
209
1862
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
210 SDL_FreeCursor(cursor[0]);
fe99535ac064 Test case for bug #240
Sam Lantinga <slouken@libsdl.org>
parents: 1859
diff changeset
211 SDL_FreeCursor(cursor[1]);
3912
e7d2858670c1 Free all the created cursors in test/testcursor.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 1883
diff changeset
212 SDL_FreeCursor(cursor[2]);
1858
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
213
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
214 SDL_Quit();
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
215 return(0);
d3ac464fb3c1 Add program to test mouse cursor change
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
216 }