19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Simple program:  Fill a colormap with gray and stripe it down the screen */
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h>
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdlib.h>
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <string.h>
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <time.h>
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL.h"
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef TEST_VGA16 /* Define this if you want to test VGA 16-color video modes */
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NUM_COLORS	16
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NUM_COLORS	256
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Draw a randomly sized and colored box centered about (X,Y) */
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid DrawBox(SDL_Surface *screen, int X, int Y, int width, int height)
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	static unsigned int seeded = 0;
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Rect area;
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32 color;
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        Uint32 randc;
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Seed the random number generator */
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( seeded == 0 ) {
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		srand(time(NULL));
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		seeded = 1;
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Get the bounds of the rectangle */
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	area.w = (rand()%width);
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	area.h = (rand()%height);
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	area.x = X-(area.w/2);
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	area.y = Y-(area.h/2);
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        randc = (rand()%NUM_COLORS);
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (screen->format->BytesPerPixel==1)
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            color = randc;
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        else
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            color = SDL_MapRGB(screen->format, randc, randc, randc);
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Do it! */
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_FillRect(screen, &area, color);
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( screen->flags & SDL_DOUBLEBUF ) {
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_Flip(screen);
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_UpdateRects(screen, 1, &area);
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid DrawBackground(SDL_Surface *screen)
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i, j, k;
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint8  *buffer;
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint16 *buffer16;
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        Uint16 color;
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        Uint8  gradient;
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Set the surface pixels and refresh! */
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Use two loops in case the surface is double-buffered (both sides) */
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for ( j=0; j<2; ++j ) {
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( SDL_LockSurface(screen) < 0 ) {
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			fprintf(stderr, "Couldn't lock display surface: %s\n",
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall								SDL_GetError());
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			return;
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		buffer = (Uint8 *)screen->pixels;
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if (screen->format->BytesPerPixel!=2) {
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			for ( i=0; i<screen->h; ++i ) {
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				buffer += screen->pitch;
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                else
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                {
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			for ( i=0; i<screen->h; ++i ) {
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				gradient=((i*(NUM_COLORS-1))/screen->h);
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                buffer16=(Uint16*)buffer;
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                for (k=0; k<screen->w; k++)
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                {
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                   *(buffer16+k)=color;
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                }
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				buffer += screen->pitch;
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                }
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_UnlockSurface(screen);
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( screen->flags & SDL_DOUBLEBUF ) {
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_Flip(screen);
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_UpdateRect(screen, 0, 0, 0, 0);
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                        break;
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Surface *screen;
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i;
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Color palette[NUM_COLORS];
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Set the video mode */
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	screen = SDL_SetVideoMode(w, h, bpp, flags);
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( screen == NULL ) {
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		fprintf(stderr, "Couldn't set display mode: %s\n",
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall							SDL_GetError());
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(NULL);
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fprintf(stderr, "Screen is in %s mode\n",
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		(screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (bpp==8) {
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* Set a gray colormap, reverse order from white to black */
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		for ( i=0; i<NUM_COLORS; ++i ) {
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			palette[i].g = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_SetColors(screen, palette, 0, NUM_COLORS);
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(screen);
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint main(int argc, char *argv[])
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Surface *screen;
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32 videoflags;
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int    done;
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Event event;
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int width, height, bpp;
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Initialize SDL */
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		exit(1);
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* See if we try to get a hardware colormap */
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	width = 640;
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	height = 480;
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bpp = 8;
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	videoflags = SDL_SWSURFACE;
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	while ( argc > 1 ) {
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		--argc;
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc-1] && (strcmp(argv[argc-1], "-width") == 0) ) {
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			width = atoi(argv[argc]);
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			--argc;
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc-1] && (strcmp(argv[argc-1], "-height") == 0) ) {
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			height = atoi(argv[argc]);
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			--argc;
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc-1] && (strcmp(argv[argc-1], "-bpp") == 0) ) {
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			bpp = atoi(argv[argc]);
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			--argc;
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc] && (strcmp(argv[argc], "-hw") == 0) ) {
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			videoflags |= SDL_HWSURFACE;
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc] && (strcmp(argv[argc], "-hwpalette") == 0) ) {
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			videoflags |= SDL_HWPALETTE;
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc] && (strcmp(argv[argc], "-flip") == 0) ) {
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			videoflags |= SDL_DOUBLEBUF;
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc] && (strcmp(argv[argc], "-noframe") == 0) ) {
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			videoflags |= SDL_NOFRAME;
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc] && (strcmp(argv[argc], "-resize") == 0) ) {
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			videoflags |= SDL_RESIZABLE;
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) {
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			videoflags |= SDL_FULLSCREEN;
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-flip] [-noframe] [-fullscreen] [-resize]\n",
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall								argv[0]);
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			exit(1);
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Set a video mode */
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	screen = CreateScreen(width, height, bpp, videoflags);
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( screen == NULL ) {
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		exit(2);
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        DrawBackground(screen);
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Wait for a keystroke */
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	done = 0;
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	while ( !done && SDL_WaitEvent(&event) ) {
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		switch (event.type) {
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case SDL_MOUSEBUTTONDOWN:
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				DrawBox(screen, event.button.x, event.button.y, width, height);
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case SDL_KEYDOWN:
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* Ignore ALT-TAB for windows */
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if ( (event.key.keysym.sym == SDLK_LALT) ||
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				     (event.key.keysym.sym == SDLK_TAB) ) {
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					break;
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* Center the mouse on <SPACE> */
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if ( event.key.keysym.sym == SDLK_SPACE ) {
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					SDL_WarpMouse(width/2, height/2);
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					break;
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* Toggle fullscreen mode on <RETURN> */
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if ( event.key.keysym.sym == SDLK_RETURN ) {
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					videoflags ^= SDL_FULLSCREEN;
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					screen = CreateScreen(
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						screen->w, screen->h,
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						screen->format->BitsPerPixel,
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall								videoflags);
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					if ( screen == NULL ) {
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						fprintf(stderr,
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					"Couldn't toggle fullscreen mode\n");
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						done = 1;
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					}
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                        DrawBackground(screen);
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					break;
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* Any other key quits the application... */
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case SDL_QUIT:
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				done = 1;
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case SDL_VIDEOEXPOSE:
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				DrawBackground(screen);
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case SDL_VIDEORESIZE:
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					screen = CreateScreen(
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						event.resize.w, event.resize.h,
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						screen->format->BitsPerPixel,
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall								videoflags);
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					if ( screen == NULL ) {
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						fprintf(stderr,
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					"Couldn't resize video mode\n");
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						done = 1;
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					}
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					DrawBackground(screen);
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			default:
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Quit();
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(0);
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
258