annotate test/testwm.c @ 4393:9afe12fb4c41 SDL-1.2

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