Mercurial > sdl-ios-xcode
annotate test/graywin.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 | d33645c36072 |
children | 782fd950bd46 c121d94672cb |
rev | line source |
---|---|
0 | 1 |
2 /* Simple program: Fill a colormap with gray and stripe it down the screen */ | |
3 | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <string.h> | |
7 #include <time.h> | |
8 | |
9 #include "SDL.h" | |
10 | |
11 #ifdef TEST_VGA16 /* Define this if you want to test VGA 16-color video modes */ | |
12 #define NUM_COLORS 16 | |
13 #else | |
14 #define NUM_COLORS 256 | |
15 #endif | |
16 | |
17 /* Draw a randomly sized and colored box centered about (X,Y) */ | |
380
bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
18 void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height) |
0 | 19 { |
20 static unsigned int seeded = 0; | |
21 SDL_Rect area; | |
22 Uint32 color; | |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
23 Uint32 randc; |
0 | 24 |
25 /* Seed the random number generator */ | |
26 if ( seeded == 0 ) { | |
27 srand(time(NULL)); | |
28 seeded = 1; | |
29 } | |
30 | |
31 /* Get the bounds of the rectangle */ | |
380
bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
32 area.w = (rand()%width); |
bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
33 area.h = (rand()%height); |
0 | 34 area.x = X-(area.w/2); |
35 area.y = Y-(area.h/2); | |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
36 randc = (rand()%NUM_COLORS); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
37 |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
38 if (screen->format->BytesPerPixel==1) |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
39 { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
40 color = randc; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
41 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
42 else |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
43 { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
44 color = SDL_MapRGB(screen->format, randc, randc, randc); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
45 } |
0 | 46 |
47 /* Do it! */ | |
48 SDL_FillRect(screen, &area, color); | |
538
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
49 if ( screen->flags & SDL_DOUBLEBUF ) { |
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
50 SDL_Flip(screen); |
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
51 } else { |
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
52 SDL_UpdateRects(screen, 1, &area); |
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
53 } |
0 | 54 } |
55 | |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
56 void DrawBackground(SDL_Surface *screen) |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
57 { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
58 int i, j, k; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
59 Uint8 *buffer; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
60 Uint16 *buffer16; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
61 Uint16 color; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
62 Uint8 gradient; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
63 |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
64 /* Set the surface pixels and refresh! */ |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
65 /* Use two loops in case the surface is double-buffered (both sides) */ |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
66 |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
67 for ( j=0; j<2; ++j ) { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
68 if ( SDL_LockSurface(screen) < 0 ) { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
69 fprintf(stderr, "Couldn't lock display surface: %s\n", |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
70 SDL_GetError()); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
71 return; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
72 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
73 buffer = (Uint8 *)screen->pixels; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
74 |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
75 if (screen->format->BytesPerPixel!=2) { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
76 for ( i=0; i<screen->h; ++i ) { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
77 memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
78 buffer += screen->pitch; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
79 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
80 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
81 else |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
82 { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
83 for ( i=0; i<screen->h; ++i ) { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
84 gradient=((i*(NUM_COLORS-1))/screen->h); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
85 color = SDL_MapRGB(screen->format, gradient, gradient, gradient); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
86 buffer16=(Uint16*)buffer; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
87 for (k=0; k<screen->w; k++) |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
88 { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
89 *(buffer16+k)=color; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
90 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
91 buffer += screen->pitch; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
92 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
93 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
94 |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
95 SDL_UnlockSurface(screen); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
96 if ( screen->flags & SDL_DOUBLEBUF ) { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
97 SDL_Flip(screen); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
98 } else { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
99 SDL_UpdateRect(screen, 0, 0, 0, 0); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
100 break; |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
101 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
102 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
103 } |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
104 |
0 | 105 SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags) |
106 { | |
107 SDL_Surface *screen; | |
108 int i; | |
109 SDL_Color palette[NUM_COLORS]; | |
110 | |
111 /* Set the video mode */ | |
112 screen = SDL_SetVideoMode(w, h, bpp, flags); | |
113 if ( screen == NULL ) { | |
114 fprintf(stderr, "Couldn't set display mode: %s\n", | |
115 SDL_GetError()); | |
116 return(NULL); | |
117 } | |
118 fprintf(stderr, "Screen is in %s mode\n", | |
119 (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); | |
120 | |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
121 if (bpp==8) { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
122 /* Set a gray colormap, reverse order from white to black */ |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
123 for ( i=0; i<NUM_COLORS; ++i ) { |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
124 palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
125 palette[i].g = (NUM_COLORS-1)-i * (256 / NUM_COLORS); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
126 palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS); |
538
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
127 } |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
128 SDL_SetColors(screen, palette, 0, NUM_COLORS); |
0 | 129 } |
130 | |
131 return(screen); | |
132 } | |
133 | |
134 int main(int argc, char *argv[]) | |
135 { | |
136 SDL_Surface *screen; | |
137 Uint32 videoflags; | |
138 int done; | |
139 SDL_Event event; | |
140 int width, height, bpp; | |
141 | |
142 /* Initialize SDL */ | |
143 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | |
144 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | |
145 exit(1); | |
146 } | |
147 | |
148 /* See if we try to get a hardware colormap */ | |
149 width = 640; | |
150 height = 480; | |
151 bpp = 8; | |
152 videoflags = SDL_SWSURFACE; | |
153 while ( argc > 1 ) { | |
154 --argc; | |
155 if ( argv[argc-1] && (strcmp(argv[argc-1], "-width") == 0) ) { | |
156 width = atoi(argv[argc]); | |
157 --argc; | |
158 } else | |
159 if ( argv[argc-1] && (strcmp(argv[argc-1], "-height") == 0) ) { | |
160 height = atoi(argv[argc]); | |
161 --argc; | |
162 } else | |
163 if ( argv[argc-1] && (strcmp(argv[argc-1], "-bpp") == 0) ) { | |
164 bpp = atoi(argv[argc]); | |
165 --argc; | |
166 } else | |
167 if ( argv[argc] && (strcmp(argv[argc], "-hw") == 0) ) { | |
168 videoflags |= SDL_HWSURFACE; | |
169 } else | |
170 if ( argv[argc] && (strcmp(argv[argc], "-hwpalette") == 0) ) { | |
171 videoflags |= SDL_HWPALETTE; | |
172 } else | |
538
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
173 if ( argv[argc] && (strcmp(argv[argc], "-flip") == 0) ) { |
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
174 videoflags |= SDL_DOUBLEBUF; |
d3abe873e3f7
Added support for testing video flipping with graywin.c
Sam Lantinga <slouken@libsdl.org>
parents:
380
diff
changeset
|
175 } else |
0 | 176 if ( argv[argc] && (strcmp(argv[argc], "-noframe") == 0) ) { |
177 videoflags |= SDL_NOFRAME; | |
178 } else | |
945
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
179 if ( argv[argc] && (strcmp(argv[argc], "-resize") == 0) ) { |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
180 videoflags |= SDL_RESIZABLE; |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
181 } else |
0 | 182 if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) { |
183 videoflags |= SDL_FULLSCREEN; | |
184 } else { | |
945
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
185 fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-flip] [-noframe] [-fullscreen] [-resize]\n", |
0 | 186 argv[0]); |
187 exit(1); | |
188 } | |
189 } | |
190 | |
191 /* Set a video mode */ | |
192 screen = CreateScreen(width, height, bpp, videoflags); | |
193 if ( screen == NULL ) { | |
194 exit(2); | |
195 } | |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
196 |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
197 DrawBackground(screen); |
0 | 198 |
199 /* Wait for a keystroke */ | |
200 done = 0; | |
201 while ( !done && SDL_WaitEvent(&event) ) { | |
202 switch (event.type) { | |
203 case SDL_MOUSEBUTTONDOWN: | |
380
bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
204 DrawBox(screen, event.button.x, event.button.y, width, height); |
0 | 205 break; |
206 case SDL_KEYDOWN: | |
207 /* Ignore ALT-TAB for windows */ | |
208 if ( (event.key.keysym.sym == SDLK_LALT) || | |
209 (event.key.keysym.sym == SDLK_TAB) ) { | |
210 break; | |
211 } | |
212 /* Center the mouse on <SPACE> */ | |
213 if ( event.key.keysym.sym == SDLK_SPACE ) { | |
380
bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
214 SDL_WarpMouse(width/2, height/2); |
0 | 215 break; |
216 } | |
217 /* Toggle fullscreen mode on <RETURN> */ | |
218 if ( event.key.keysym.sym == SDLK_RETURN ) { | |
219 videoflags ^= SDL_FULLSCREEN; | |
220 screen = CreateScreen( | |
221 screen->w, screen->h, | |
222 screen->format->BitsPerPixel, | |
223 videoflags); | |
224 if ( screen == NULL ) { | |
225 fprintf(stderr, | |
226 "Couldn't toggle fullscreen mode\n"); | |
227 done = 1; | |
228 } | |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
229 DrawBackground(screen); |
0 | 230 break; |
231 } | |
232 /* Any other key quits the application... */ | |
233 case SDL_QUIT: | |
234 done = 1; | |
235 break; | |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
236 case SDL_VIDEOEXPOSE: |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
237 DrawBackground(screen); |
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
538
diff
changeset
|
238 break; |
945
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
239 case SDL_VIDEORESIZE: |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
240 screen = CreateScreen( |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
241 event.resize.w, event.resize.h, |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
242 screen->format->BitsPerPixel, |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
243 videoflags); |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
244 if ( screen == NULL ) { |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
245 fprintf(stderr, |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
246 "Couldn't resize video mode\n"); |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
247 done = 1; |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
248 } |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
249 DrawBackground(screen); |
d33645c36072
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
250 break; |
0 | 251 default: |
252 break; | |
253 } | |
254 } | |
255 SDL_Quit(); | |
256 return(0); | |
257 } |