test/testwm.c
changeset 826 3eddf51b649b
parent 609 a30b17e09cc0
child 1151 be9c9c8f6d53
     1.1 --- a/test/testwm.c	Sun Feb 15 18:45:45 2004 +0000
     1.2 +++ b/test/testwm.c	Sun Feb 15 20:31:27 2004 +0000
     1.3 @@ -10,6 +10,49 @@
     1.4  /* Is the cursor visible? */
     1.5  static int visible = 1;
     1.6  
     1.7 +static Uint8  video_bpp;
     1.8 +static Uint32 video_flags;
     1.9 +
    1.10 +int SetVideoMode(int w, int h)
    1.11 +{
    1.12 +	SDL_Surface *screen;
    1.13 +	int i;
    1.14 +	Uint8 *buffer;
    1.15 +	SDL_Color palette[256];
    1.16 +
    1.17 +	screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
    1.18 +	if (  screen == NULL ) {
    1.19 +		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
    1.20 +					w, h, video_bpp, SDL_GetError());
    1.21 +		return(-1);
    1.22 +	}
    1.23 +	printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
    1.24 +						"fullscreen" : "windowed");
    1.25 +
    1.26 +	/* Set the surface pixels and refresh! */
    1.27 +	for ( i=0; i<256; ++i ) {
    1.28 +		palette[i].r = 255-i;
    1.29 +		palette[i].g = 255-i;
    1.30 +		palette[i].b = 255-i;
    1.31 +	}
    1.32 +	SDL_SetColors(screen, palette, 0, 256);
    1.33 +	if ( SDL_LockSurface(screen) < 0 ) {
    1.34 +		fprintf(stderr, "Couldn't lock display surface: %s\n",
    1.35 +							SDL_GetError());
    1.36 +		return(-1);
    1.37 +	}
    1.38 +	buffer = (Uint8 *)screen->pixels;
    1.39 +	for ( i=0; i<screen->h; ++i ) {
    1.40 +		memset(buffer,(i*255)/screen->h,
    1.41 +				screen->w*screen->format->BytesPerPixel);
    1.42 +		buffer += screen->pitch;
    1.43 +	}
    1.44 +	SDL_UnlockSurface(screen);
    1.45 +	SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.46 +
    1.47 +	return(0);
    1.48 +}
    1.49 +
    1.50  SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
    1.51  {
    1.52  	SDL_Surface *icon;
    1.53 @@ -79,6 +122,8 @@
    1.54  		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
    1.55  	} else {
    1.56  		printf("Unable to toggle fullscreen mode\n");
    1.57 +		video_flags ^= SDL_FULLSCREEN;
    1.58 +		SetVideoMode(screen->w, screen->h);
    1.59  	}
    1.60  }
    1.61  
    1.62 @@ -207,49 +252,6 @@
    1.63  	}
    1.64  }
    1.65  
    1.66 -static Uint8  video_bpp;
    1.67 -static Uint32 video_flags;
    1.68 -
    1.69 -int SetVideoMode(int w, int h)
    1.70 -{
    1.71 -	SDL_Surface *screen;
    1.72 -	int i;
    1.73 -	Uint8 *buffer;
    1.74 -	SDL_Color palette[256];
    1.75 -
    1.76 -	screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
    1.77 -	if (  screen == NULL ) {
    1.78 -		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
    1.79 -					w, h, video_bpp, SDL_GetError());
    1.80 -		return(-1);
    1.81 -	}
    1.82 -	printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
    1.83 -						"fullscreen" : "windowed");
    1.84 -
    1.85 -	/* Set the surface pixels and refresh! */
    1.86 -	for ( i=0; i<256; ++i ) {
    1.87 -		palette[i].r = 255-i;
    1.88 -		palette[i].g = 255-i;
    1.89 -		palette[i].b = 255-i;
    1.90 -	}
    1.91 -	SDL_SetColors(screen, palette, 0, 256);
    1.92 -	if ( SDL_LockSurface(screen) < 0 ) {
    1.93 -		fprintf(stderr, "Couldn't lock display surface: %s\n",
    1.94 -							SDL_GetError());
    1.95 -		return(-1);
    1.96 -	}
    1.97 -	buffer = (Uint8 *)screen->pixels;
    1.98 -	for ( i=0; i<screen->h; ++i ) {
    1.99 -		memset(buffer,(i*255)/screen->h,
   1.100 -				screen->w*screen->format->BytesPerPixel);
   1.101 -		buffer += screen->pitch;
   1.102 -	}
   1.103 -	SDL_UnlockSurface(screen);
   1.104 -	SDL_UpdateRect(screen, 0, 0, 0, 0);
   1.105 -
   1.106 -	return(0);
   1.107 -}
   1.108 -
   1.109  int main(int argc, char *argv[])
   1.110  {
   1.111  	SDL_Event event;