annotate test/testwm.c @ 5019:64a2d8f538a1

Updated the snapshot script for Mercurial
author Sam Lantinga <slouken@libsdl.org>
date Tue, 18 Jan 2011 14:21:10 -0800
parents c127755eebee
children 25d4feb7c127
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 /* Test out the window manager interaction functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
3
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4 #include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 #include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 #include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 /* Is the cursor visible? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 static int visible = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
13 static Uint8 video_bpp;
826
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
14 static Uint32 video_flags;
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
15
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 826
diff changeset
16 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
17 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
18 quit(int rc)
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 826
diff changeset
19 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
20 SDL_Quit();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
21 exit(rc);
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 826
diff changeset
22 }
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 826
diff changeset
23
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
24 int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
25 SetVideoMode(int w, int h)
826
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
26 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
27 SDL_Surface *screen;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
28 int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
29 Uint8 *buffer;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
30 SDL_Color palette[256];
826
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
31
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
32 screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
33 if (screen == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
34 fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
35 w, h, video_bpp, SDL_GetError());
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
36 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
37 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
38 printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
39 "fullscreen" : "windowed");
826
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
40
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
41 /* Set the surface pixels and refresh! */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
42 for (i = 0; i < 256; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
43 palette[i].r = 255 - i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
44 palette[i].g = 255 - i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
45 palette[i].b = 255 - i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
46 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
47 SDL_SetColors(screen, palette, 0, 256);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
48 if (SDL_LockSurface(screen) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
49 fprintf(stderr, "Couldn't lock display surface: %s\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
50 SDL_GetError());
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
51 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
52 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
53 buffer = (Uint8 *) screen->pixels;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
54 for (i = 0; i < screen->h; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
55 memset(buffer, (i * 255) / screen->h,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
56 screen->w * screen->format->BytesPerPixel);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
57 buffer += screen->pitch;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
58 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
59 SDL_UnlockSurface(screen);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
60 SDL_UpdateRect(screen, 0, 0, 0, 0);
826
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
61
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
62 return (0);
826
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
63 }
3eddf51b649b Showed how to toggle fullscreen mode if the API isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 609
diff changeset
64
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
65 SDL_Surface *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
66 LoadIconSurface(char *file, Uint8 ** maskp)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
68 SDL_Surface *icon;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
69 Uint8 *pixels;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
70 Uint8 *mask;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
71 int mlen, i, j;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
72
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
73 *maskp = NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
75 /* Load the icon surface */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
76 icon = SDL_LoadBMP(file);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
77 if (icon == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
78 fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
79 return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
80 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
82 /* Check width and height
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
83 if ( (icon->w%8) != 0 ) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
84 fprintf(stderr, "Icon width must be a multiple of 8!\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
85 SDL_FreeSurface(icon);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
86 return(NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
87 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
88 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
89
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
91 if (icon->format->palette == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
92 fprintf(stderr, "Icon must have a palette!\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
93 SDL_FreeSurface(icon);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
94 return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
95 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
96
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
97 /* Set the colorkey */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
98 SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *) icon->pixels));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
100 /* Create the mask */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
101 pixels = (Uint8 *) icon->pixels;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
102 printf("Transparent pixel: (%d,%d,%d)\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
103 icon->format->palette->colors[*pixels].r,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
104 icon->format->palette->colors[*pixels].g,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
105 icon->format->palette->colors[*pixels].b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
106 mlen = (icon->w * icon->h + 7) / 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
107 mask = (Uint8 *) malloc(mlen);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
108 if (mask == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
109 fprintf(stderr, "Out of memory!\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
110 SDL_FreeSurface(icon);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
111 return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
112 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
113 memset(mask, 0, mlen);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
114 for (i = 0; i < icon->h; i++)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
115 for (j = 0; j < icon->w; j++) {
591
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
116 int pindex = i * icon->pitch + j;
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
117 int mindex = i * icon->w + j;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
118 if (pixels[pindex] != *pixels)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
119 mask[mindex >> 3] |= 1 << (7 - (mindex & 7));
591
9c9598e4b904 Allow icons of any size
Sam Lantinga <slouken@libsdl.org>
parents: 87
diff changeset
120 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
121 *maskp = mask;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
122 return (icon);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
125 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
126 HotKey_ToggleFullScreen(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
128 SDL_Surface *screen;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
130 screen = SDL_GetVideoSurface();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
131 if (SDL_WM_ToggleFullScreen(screen)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
132 printf("Toggled fullscreen mode - now %s\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
133 (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
134 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
135 printf("Unable to toggle fullscreen mode\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
136 video_flags ^= SDL_FULLSCREEN;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
137 SetVideoMode(screen->w, screen->h);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
138 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
141 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
142 HotKey_ToggleGrab(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
144 SDL_GrabMode mode;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
146 printf("Ctrl-G: toggling input grab!\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
147 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
148 if (mode == SDL_GRAB_ON) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
149 printf("Grab was on\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
150 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
151 printf("Grab was off\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
152 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
153 mode = SDL_WM_GrabInput(mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
154 if (mode == SDL_GRAB_ON) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
155 printf("Grab is now on\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
156 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
157 printf("Grab is now off\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
158 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
161 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
162 HotKey_Iconify(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
164 printf("Ctrl-Z: iconifying window!\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
165 SDL_WM_IconifyWindow();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
168 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
169 HotKey_Quit(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
171 SDL_Event event;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
173 printf("Posting internal quit request\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
174 event.type = SDL_USEREVENT;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
175 SDL_PushEvent(&event);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177
3634
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
178
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
179 static void
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
180 print_modifiers(void)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
181 {
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
182 int mod;
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
183 printf(" modifiers:");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
184 mod = SDL_GetModState();
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
185 if(!mod) {
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
186 printf(" (none)");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
187 return;
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
188 }
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
189 if(mod & KMOD_LSHIFT)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
190 printf(" LSHIFT");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
191 if(mod & KMOD_RSHIFT)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
192 printf(" RSHIFT");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
193 if(mod & KMOD_LCTRL)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
194 printf(" LCTRL");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
195 if(mod & KMOD_RCTRL)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
196 printf(" RCTRL");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
197 if(mod & KMOD_LALT)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
198 printf(" LALT");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
199 if(mod & KMOD_RALT)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
200 printf(" RALT");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
201 if(mod & KMOD_LMETA)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
202 printf(" LMETA");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
203 if(mod & KMOD_RMETA)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
204 printf(" RMETA");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
205 if(mod & KMOD_NUM)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
206 printf(" NUM");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
207 if(mod & KMOD_CAPS)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
208 printf(" CAPS");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
209 if(mod & KMOD_MODE)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
210 printf(" MODE");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
211 }
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
212
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
213 static void PrintKey(const SDL_keysym *sym, int pressed)
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
214 {
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
215 /* Print the keycode, name and state */
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
216 if ( sym->sym ) {
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
217 printf("Key %s: %d-%s ", pressed ? "pressed" : "released",
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
218 sym->sym, SDL_GetKeyName(sym->sym));
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
219 } else {
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
220 printf("Unknown Key (scancode = %d) %s ", sym->scancode,
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
221 pressed ? "pressed" : "released");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
222 }
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
223
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
224 /* Print the translated character, if one exists */
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
225 if ( sym->unicode ) {
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
226 /* Is it a control-character? */
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
227 if ( sym->unicode < ' ' ) {
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
228 printf(" (^%c)", sym->unicode+'@');
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
229 } else {
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
230 #ifdef UNICODE
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
231 printf(" (%c)", sym->unicode);
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
232 #else
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
233 /* This is a Latin-1 program, so only show 8-bits */
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
234 if ( !(sym->unicode & 0xFF00) )
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
235 printf(" (%c)", sym->unicode);
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
236 else
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
237 printf(" (0x%X)", sym->unicode);
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
238 #endif
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
239 }
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
240 }
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
241 print_modifiers();
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
242 printf("\n");
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
243 }
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
244
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
245
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2179
diff changeset
246 static int (SDLCALL * old_filterfunc) (void *, SDL_Event *);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
247 static void *old_filterdata;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
249 int SDLCALL
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
250 FilterEvents(void *userdata, SDL_Event * event)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
251 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
252 static int reallyquit = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
253
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
254 if (old_filterfunc) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
255 old_filterfunc(old_filterdata, event);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
256 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
257
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
258 switch (event->type) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
260 case SDL_ACTIVEEVENT:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
261 /* See what happened */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
262 printf("App %s ", event->active.gain ? "gained" : "lost");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
263 if (event->active.state & SDL_APPACTIVE)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
264 printf("active ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
265 if (event->active.state & SDL_APPINPUTFOCUS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
266 printf("input ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
267 if (event->active.state & SDL_APPMOUSEFOCUS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
268 printf("mouse ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
269 printf("focus\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
271 /* See if we are iconified or restored */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
272 if (event->active.state & SDL_APPACTIVE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
273 printf("App has been %s\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
274 event->active.gain ? "restored" : "iconified");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
275 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
276 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
278 /* We want to toggle visibility on buttonpress */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
279 case SDL_MOUSEBUTTONDOWN:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
280 case SDL_MOUSEBUTTONUP:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
281 if (event->button.state == SDL_PRESSED) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
282 visible = !visible;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
283 SDL_ShowCursor(visible);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
284 }
3545
6d91cff0ec79 Added mouse position for button handling
Sam Lantinga <slouken@libsdl.org>
parents: 2185
diff changeset
285 printf("Mouse button %d has been %s at %d,%d\n",
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
286 event->button.button,
3545
6d91cff0ec79 Added mouse position for button handling
Sam Lantinga <slouken@libsdl.org>
parents: 2185
diff changeset
287 (event->button.state == SDL_PRESSED) ? "pressed" : "released",
6d91cff0ec79 Added mouse position for button handling
Sam Lantinga <slouken@libsdl.org>
parents: 2185
diff changeset
288 event->button.x, event->button.y);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
289 return (0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
290
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
291 /* Show relative mouse motion */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
292 case SDL_MOUSEMOTION:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293 #if 0
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
294 printf("Mouse motion: {%d,%d} (%d,%d)\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
295 event->motion.x, event->motion.y,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
296 event->motion.xrel, event->motion.yrel);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
298 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
300 case SDL_KEYDOWN:
3634
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
301 PrintKey(&event->key.keysym, 1);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
302 if (event->key.keysym.sym == SDLK_ESCAPE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
303 HotKey_Quit();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
304 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
305 if ((event->key.keysym.sym == SDLK_g) &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
306 (event->key.keysym.mod & KMOD_CTRL)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
307 HotKey_ToggleGrab();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
308 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
309 if ((event->key.keysym.sym == SDLK_z) &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
310 (event->key.keysym.mod & KMOD_CTRL)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
311 HotKey_Iconify();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
312 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
313 if ((event->key.keysym.sym == SDLK_RETURN) &&
4942
c127755eebee Allow META-Enter to toggle fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 3634
diff changeset
314 (event->key.keysym.mod & (KMOD_ALT|KMOD_META))) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
315 HotKey_ToggleFullScreen();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
316 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
317 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318
3634
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
319 case SDL_KEYUP:
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
320 PrintKey(&event->key.keysym, 0);
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
321 return(0);
1e31a24c41a6 Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 3545
diff changeset
322
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
323 /* Pass the video resize event through .. */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
324 case SDL_VIDEORESIZE:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
325 return (1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
327 /* This is important! Queue it if we want to quit. */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
328 case SDL_QUIT:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
329 if (!reallyquit) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
330 reallyquit = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
331 printf("Quit requested\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
332 return (0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
333 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
334 printf("Quit demanded\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
335 return (1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
337 /* This will never happen because events queued directly
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
338 to the event queue are not filtered.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
339 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
340 case SDL_USEREVENT:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
341 return (1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
343 /* Drop all other events */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
344 default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
345 return (0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
346 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
349 int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
350 main(int argc, char *argv[])
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
352 SDL_Event event;
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
353 const char *title;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
354 SDL_Surface *icon;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
355 Uint8 *icon_mask;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
356 int parsed;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
357 int w, h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
359 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
360 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
361 return (1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
362 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
364 /* Check command line arguments */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
365 w = 640;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
366 h = 480;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
367 video_bpp = 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
368 video_flags = SDL_SWSURFACE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
369 parsed = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
370 while (parsed) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
371 if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
372 video_flags |= SDL_FULLSCREEN;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
373 argc -= 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
374 argv += 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
375 } else if ((argc >= 2) && (strcmp(argv[1], "-resize") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
376 video_flags |= SDL_RESIZABLE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
377 argc -= 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
378 argv += 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
379 } else if ((argc >= 2) && (strcmp(argv[1], "-noframe") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
380 video_flags |= SDL_NOFRAME;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
381 argc -= 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
382 argv += 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
383 } else if ((argc >= 3) && (strcmp(argv[1], "-width") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
384 w = atoi(argv[2]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
385 argc -= 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
386 argv += 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
387 } else if ((argc >= 3) && (strcmp(argv[1], "-height") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
388 h = atoi(argv[2]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
389 argc -= 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
390 argv += 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
391 } else if ((argc >= 3) && (strcmp(argv[1], "-bpp") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
392 video_bpp = atoi(argv[2]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
393 argc -= 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
394 argv += 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
395 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
396 parsed = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
397 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
398 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
400 /* Set the icon -- this must be done before the first mode set */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
401 icon = LoadIconSurface("icon.bmp", &icon_mask);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
402 if (icon != NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
403 SDL_WM_SetIcon(icon, icon_mask);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
404 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
405 if (icon_mask != NULL)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
406 free(icon_mask);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
408 /* Set the title bar */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
409 if (argv[1] == NULL)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
410 title = "Testing 1.. 2.. 3...";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
411 else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
412 title = argv[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
413 SDL_WM_SetCaption(title, "testwm");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
415 /* See if it's really set */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
416 SDL_WM_GetCaption(&title, NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
417 if (title)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
418 printf("Title was set to: %s\n", title);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
419 else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
420 printf("No window title was set!\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
422 /* Initialize the display */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
423 if (SetVideoMode(w, h) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
424 quit(1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
425 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
426
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
427 /* Set an event filter that discards everything but QUIT */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
428 SDL_GetEventFilter(&old_filterfunc, &old_filterdata);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
429 SDL_SetEventFilter(FilterEvents, NULL);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
430
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
431 /* Loop, waiting for QUIT */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
432 while (SDL_WaitEvent(&event)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
433 switch (event.type) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
434 case SDL_VIDEORESIZE:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
435 printf("Got a resize event: %dx%d\n",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
436 event.resize.w, event.resize.h);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
437 SetVideoMode(event.resize.w, event.resize.h);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
438 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
439 case SDL_USEREVENT:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
440 printf("Handling internal quit request\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
441 /* Fall through to the quit handler */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
442 case SDL_QUIT:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
443 printf("Bye bye..\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
444 quit(0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
445 default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
446 /* This should never happen */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
447 printf("Warning: Event %d wasn't filtered\n", event.type);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
448 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
449 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
450 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
451 printf("SDL_WaitEvent() error: %s\n", SDL_GetError());
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
452 SDL_Quit();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1779
diff changeset
453 return (255);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
454 }