test/testwm.c
changeset 826 3eddf51b649b
parent 609 a30b17e09cc0
child 1151 be9c9c8f6d53
equal deleted inserted replaced
825:618fcc5861c8 826:3eddf51b649b
     7 
     7 
     8 #include "SDL.h"
     8 #include "SDL.h"
     9 
     9 
    10 /* Is the cursor visible? */
    10 /* Is the cursor visible? */
    11 static int visible = 1;
    11 static int visible = 1;
       
    12 
       
    13 static Uint8  video_bpp;
       
    14 static Uint32 video_flags;
       
    15 
       
    16 int SetVideoMode(int w, int h)
       
    17 {
       
    18 	SDL_Surface *screen;
       
    19 	int i;
       
    20 	Uint8 *buffer;
       
    21 	SDL_Color palette[256];
       
    22 
       
    23 	screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
       
    24 	if (  screen == NULL ) {
       
    25 		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
       
    26 					w, h, video_bpp, SDL_GetError());
       
    27 		return(-1);
       
    28 	}
       
    29 	printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
       
    30 						"fullscreen" : "windowed");
       
    31 
       
    32 	/* Set the surface pixels and refresh! */
       
    33 	for ( i=0; i<256; ++i ) {
       
    34 		palette[i].r = 255-i;
       
    35 		palette[i].g = 255-i;
       
    36 		palette[i].b = 255-i;
       
    37 	}
       
    38 	SDL_SetColors(screen, palette, 0, 256);
       
    39 	if ( SDL_LockSurface(screen) < 0 ) {
       
    40 		fprintf(stderr, "Couldn't lock display surface: %s\n",
       
    41 							SDL_GetError());
       
    42 		return(-1);
       
    43 	}
       
    44 	buffer = (Uint8 *)screen->pixels;
       
    45 	for ( i=0; i<screen->h; ++i ) {
       
    46 		memset(buffer,(i*255)/screen->h,
       
    47 				screen->w*screen->format->BytesPerPixel);
       
    48 		buffer += screen->pitch;
       
    49 	}
       
    50 	SDL_UnlockSurface(screen);
       
    51 	SDL_UpdateRect(screen, 0, 0, 0, 0);
       
    52 
       
    53 	return(0);
       
    54 }
    12 
    55 
    13 SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
    56 SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
    14 {
    57 {
    15 	SDL_Surface *icon;
    58 	SDL_Surface *icon;
    16 	Uint8       *pixels;
    59 	Uint8       *pixels;
    77 	if ( SDL_WM_ToggleFullScreen(screen) ) {
   120 	if ( SDL_WM_ToggleFullScreen(screen) ) {
    78 		printf("Toggled fullscreen mode - now %s\n",
   121 		printf("Toggled fullscreen mode - now %s\n",
    79 		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
   122 		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
    80 	} else {
   123 	} else {
    81 		printf("Unable to toggle fullscreen mode\n");
   124 		printf("Unable to toggle fullscreen mode\n");
       
   125 		video_flags ^= SDL_FULLSCREEN;
       
   126 		SetVideoMode(screen->w, screen->h);
    82 	}
   127 	}
    83 }
   128 }
    84 
   129 
    85 void HotKey_ToggleGrab(void)
   130 void HotKey_ToggleGrab(void)
    86 {
   131 {
   203 
   248 
   204 		/* Drop all other events */
   249 		/* Drop all other events */
   205 		default:
   250 		default:
   206 			return(0);
   251 			return(0);
   207 	}
   252 	}
   208 }
       
   209 
       
   210 static Uint8  video_bpp;
       
   211 static Uint32 video_flags;
       
   212 
       
   213 int SetVideoMode(int w, int h)
       
   214 {
       
   215 	SDL_Surface *screen;
       
   216 	int i;
       
   217 	Uint8 *buffer;
       
   218 	SDL_Color palette[256];
       
   219 
       
   220 	screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
       
   221 	if (  screen == NULL ) {
       
   222 		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
       
   223 					w, h, video_bpp, SDL_GetError());
       
   224 		return(-1);
       
   225 	}
       
   226 	printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
       
   227 						"fullscreen" : "windowed");
       
   228 
       
   229 	/* Set the surface pixels and refresh! */
       
   230 	for ( i=0; i<256; ++i ) {
       
   231 		palette[i].r = 255-i;
       
   232 		palette[i].g = 255-i;
       
   233 		palette[i].b = 255-i;
       
   234 	}
       
   235 	SDL_SetColors(screen, palette, 0, 256);
       
   236 	if ( SDL_LockSurface(screen) < 0 ) {
       
   237 		fprintf(stderr, "Couldn't lock display surface: %s\n",
       
   238 							SDL_GetError());
       
   239 		return(-1);
       
   240 	}
       
   241 	buffer = (Uint8 *)screen->pixels;
       
   242 	for ( i=0; i<screen->h; ++i ) {
       
   243 		memset(buffer,(i*255)/screen->h,
       
   244 				screen->w*screen->format->BytesPerPixel);
       
   245 		buffer += screen->pitch;
       
   246 	}
       
   247 	SDL_UnlockSurface(screen);
       
   248 	SDL_UpdateRect(screen, 0, 0, 0, 0);
       
   249 
       
   250 	return(0);
       
   251 }
   253 }
   252 
   254 
   253 int main(int argc, char *argv[])
   255 int main(int argc, char *argv[])
   254 {
   256 {
   255 	SDL_Event event;
   257 	SDL_Event event;