gwin = new Game_window(display_width/2, display_height/2);
int w = display_width/2, h = display_height/2; if (w < 500) w = 500; if (h < 400) h = 400; gwin = new Game_window(w, h);
static void Handle_event(SDL_Event& event);#ifdef XWINstatic Display *display = 0;#endif/* *	Initialize and create main window. */static void Init	(	)	{	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0)		{		cerr << "Unable to initialize SDL: " << SDL_GetError() << '\n';		exit(-1);		}	SDL_SysWMinfo info;		// Get system info.	SDL_VERSION(&info.version);#ifdef XWIN	SDL_GetWMInfo(&info);	display = info.info.x11.display;	int screen_num = DefaultScreen(display);	unsigned int display_width = DisplayWidth(display, screen_num);	unsigned int display_height = DisplayHeight(display, screen_num);					// Make window 1/2 size of screen.	gwin = new Game_window(display_width/2, display_height/2);#else	gwin = new Game_window(640, 480);#endif	}/* *	Handle events until a flag is set. */void Handle_events	(	unsigned char *stop	)	{#ifdef XWIN					// Get connection number.	int xfd = ConnectionNumber(display);#endif	/*	 *	Main event loop.	 */	while (!*stop)		{#ifdef XWIN		fd_set rfds;		// Want a timer.		struct timeval timer;		timer.tv_sec = 0;		timer.tv_usec = 20000;	// Try 1/50 second.		FD_ZERO(&rfds);		FD_SET(xfd, &rfds);					// Wait for timeout or event.		select(xfd + 1, &rfds, 0, 0, &timer);#else					/* May use this for Linux too. */		SDL_Delay(20);		// Try 1/50 second.#endif		SDL_Event event;		while (!*stop && SDL_PollEvent(&event))			Handle_event(event);					// Get current time.		unsigned long ticks = SDL_GetTicks();					// Animate unless modal or dormant.		if (gwin->have_focus() && gwin->get_mode() == 							Game_window::normal)			gwin->get_tqueue()->activate(ticks);		gwin->show();		// Blit to screen if necessary.		}	}/* *	Play game. */static int Play()	{	Handle_events(&quitting_time);	delete gwin;	return (0);	}/* *	Handle an event.  This should work for all platforms. */static void Handle_event	(	SDL_Event& event	)	{					// For detecting double-clicks.	static unsigned long last_b1_click = 0;	unsigned int mask;	char keybuf[10];//cout << "Event " << (int) event.type << " received\n";	switch (event.type)		{	case SDL_MOUSEBUTTONDOWN:		gwin->end_intro();		if (gwin->get_mode() != Game_window::normal)			break;					// Move sprite toward mouse					//  when right button pressed.		if (event.button.button == 3)			gwin->start_actor(event.button.x, event.button.y);		break;	case SDL_MOUSEBUTTONUP:		if (event.button.button == 3)			{			if (gwin->get_mode() != Game_window::normal)				break;			gwin->stop_actor();			}		else if (event.button.button == 1)			{			if (gwin->get_mode() == Game_window::conversation)				{	// In a conversation.				gwin->conversation_choice(					event.button.x, event.button.y);				break;				}			unsigned long curtime = SDL_GetTicks();					// Last click within .5 secs?			if (curtime - last_b1_click < 500)				{				gwin->double_clicked(event.button.x, 							event.button.y);				break;				}			last_b1_click = curtime;					// Identify item(s) clicked on.			gwin->show_items(event.button.x, event.button.y);			}		break;	case SDL_MOUSEMOTION:		// Moving with right button down.		if (gwin->get_mode() != Game_window::normal)			break;		if (event.motion.state != 0)			gwin->start_actor(event.motion.x, event.motion.y);		break;	case SDL_ACTIVEEVENT:		if (event.active.state & SDL_APPINPUTFOCUS)			{			if (event.active.gain)				gwin->get_focus();			else				gwin->lose_focus();			}		if (event.active.state & SDL_APPACTIVE)					// Became active.			if (event.active.gain)				gwin->init_actors();		break;#if 0	case ConfigureNotify:		// Resize.		gwin->resized(event.xconfigure.window,			event.xconfigure.width, event.xconfigure.height);		break;#endif	case SDL_QUIT:		quitting_time = 1;		break;	case SDL_KEYDOWN:			// Keystroke.		Handle_keystroke(event.key.keysym.sym,			event.key.keysym.mod & KMOD_SHIFT);		break;		}	}