Пример #1
0
/*
================
VID_SetMode
================
*/
static int VID_SetMode (int width, int height, int bpp, qboolean fullscreen)
{
	int		temp;
	Uint32	flags = DEFAULT_SDL_FLAGS;
	char		caption[50];

	if (fullscreen)
		flags |= SDL_FULLSCREEN;

	// so Con_Printfs don't mess us up by forcing vid and snd updates
	temp = scr_disabled_for_loading;
	scr_disabled_for_loading = true;

	CDAudio_Pause ();
	BGM_Pause ();

	//
	// swap control (the "before SDL_SetVideoMode" part)
	//
	gl_swap_control = true;
	if (SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, (vid_vsync.value) ? 1 : 0) == -1)
		gl_swap_control = false;

	bpp = SDL_VideoModeOK(width, height, bpp, flags);

	draw_context = SDL_SetVideoMode(width, height, bpp, flags);
	if (!draw_context)
		Sys_Error ("Couldn't set video mode");

	q_snprintf(caption, sizeof(caption), "QuakeSpasm %1.2f.%d", (float)FITZQUAKE_VERSION, QUAKESPASM_VER_PATCH);
	SDL_WM_SetCaption(caption, caption);

	vid.width = draw_context->w;
	vid.height = draw_context->h;
	vid.conwidth = vid.width & 0xFFFFFFF8;
	vid.conheight = vid.conwidth * vid.height / vid.width;
	vid.numpages = 2;

	modestate = draw_context->flags & SDL_FULLSCREEN ? MS_FULLSCREEN : MS_WINDOWED;

	CDAudio_Resume ();
	BGM_Resume ();
	scr_disabled_for_loading = temp;

// fix the leftover Alt from any Alt-Tab or the like that switched us away
	ClearAllStates ();

	Con_SafePrintf ("Video mode %dx%dx%d initialized\n",
				draw_context->w,
				draw_context->h,
				draw_context->format->BitsPerPixel);

	vid.recalc_refdef = 1;

// no pending changes
	vid_changed = false;

	return true;
}
Пример #2
0
static int VID_SetMode (int modenum, unsigned char *palette)
{
	Uint32 flags;
	int	is_fullscreen;

	in_mode_set = true;

	if (screen)
		SDL_FreeSurface(screen);

	flags = (SDL_SWSURFACE|SDL_HWPALETTE);
	if (vid_config_fscr.integer)
		flags |= SDL_FULLSCREEN;

	// Set the mode
	screen = SDL_SetVideoMode(modelist[modenum].width, modelist[modenum].height, modelist[modenum].bpp, flags);
	if (!screen)
		return false;

	// initial success. adjust vid vars.
	vid.height = vid.conheight = modelist[modenum].height;
	vid.width = vid.conwidth = modelist[modenum].width;
	vid.buffer = vid.conbuffer = vid.direct = (pixel_t *) screen->pixels;
	vid.rowbytes = vid.conrowbytes = screen->pitch;
	vid.numpages = 1;
	vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);

	if (!VID_AllocBuffers (vid.width, vid.height))
		return false;

	D_InitCaches (vid_surfcache, vid_surfcachesize);

	// real success. set vid_modenum properly.
	vid_modenum = modenum;
	is_fullscreen = (screen->flags & SDL_FULLSCREEN) ? 1 : 0;
	modestate = (is_fullscreen) ? MS_FULLDIB : MS_WINDOWED;
	Cvar_SetValue ("vid_config_swx", modelist[vid_modenum].width);
	Cvar_SetValue ("vid_config_swy", modelist[vid_modenum].height);
	Cvar_SetValue ("vid_config_fscr", is_fullscreen);

	IN_HideMouse ();

	ClearAllStates();

	VID_SetPalette (palette);

	// setup the window manager stuff
	VID_SetIcon();
	SDL_WM_SetCaption(WM_TITLEBAR_TEXT, WM_ICON_TEXT);

	Con_SafePrintf ("Video Mode: %ux%ux%d\n", vid.width, vid.height, modelist[modenum].bpp);

	in_mode_set = false;
	vid.recalc_refdef = 1;

	return true;
}
Пример #3
0
void VID_zzz (void) {
	extern int nonwideconheight;

	vid.width  = vid.conwidth  = min(vid.conwidth,  glConfig.vidWidth);
	vid.height = vid.conheight = min(vid.conheight, glConfig.vidHeight);

	// we need cap cvars, after resolution changed, here may be conwidth > width, so set cvars right
	Cvar_SetValue(&r_conwidth,  r_conwidth.value);  // must trigger callback which validate value
	Cvar_SetValue(&r_conheight, nonwideconheight); // must trigger callback which validate value

	vid.numpages = 2;

	Draw_AdjustConback ();

#ifdef _WIN32
	//fix the leftover Alt from any Alt-Tab or the like that switched us away
	ClearAllStates ();
#endif

	vid.recalc_refdef = 1;
}
Пример #4
0
LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	int				fActive, fMinimized;
	int				temp;
	LONG			lRet = 0;
	PAINTSTRUCT		ps;
	HDC				hdc;

	switch (uMsg)
	{
		case WM_CREATE:
			break;

		case WM_MOVE:
			window_x = (int) LOWORD(lParam);
			window_y = (int) HIWORD(lParam);
			VID_UpdateWindowStatus ();

			//if ((modestate == MS_WINDOWED) && !in_mode_set && !Minimized)
			//	VID_RememberWindowPos ();

			break;

   	    case WM_CLOSE:
		// this causes Close in the right-click task bar menu not to work, but right
		// now bad things happen if Close is handled in that case (garbage and a
		// crash on Win95)
			//if (!in_mode_set)
			{
				if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit",
							MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
				{
					Host_Quit ();
				}
			}
			break;

		case WM_ACTIVATE:
			fActive = LOWORD(wParam);
			fMinimized = (BOOL) HIWORD(wParam);
			AppActivate(!(fActive == WA_INACTIVE), fMinimized);

		// fix the leftover Alt from any Alt-Tab or the like that switched us away
			ClearAllStates ();

			/*if (!in_mode_set)
			{
				if (windc)
					MGL_activatePalette(windc,true);

				VID_SetPalette(vid_curpal);
			}*/

			break;

		case WM_PAINT:
			hdc = GetDC (mainwindow);	// FIXME
			hdc = BeginPaint(hWnd, &ps);

			//Com_Printf ("WM_PAINT\n");	// TESTING

			/*
			if (!in_mode_set && host_initialized) {
				SCR_InvalidateScreen ();
				SCR_UpdateScreen ();
			}
			*/

			EndPaint(hWnd, &ps);
			break;

		case WM_KEYDOWN:
		case WM_SYSKEYDOWN:
			if (!in_mode_set)
				IN_TranslateKeyEvent (lParam, true);
			break;

		case WM_KEYUP:
		case WM_SYSKEYUP:
			if (!in_mode_set)
				IN_TranslateKeyEvent (lParam, true);
			break;

	// this is complicated because Win32 seems to pack multiple mouse events into
	// one update sometimes, so we always check all states and look for events
		case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
		case WM_XBUTTONDOWN:
		case WM_XBUTTONUP:
		case WM_MOUSEMOVE:
			if (!in_mode_set)
			{
				temp = 0;

				if (wParam & MK_LBUTTON)
					temp |= 1;

				if (wParam & MK_RBUTTON)
					temp |= 2;

				if (wParam & MK_MBUTTON)
					temp |= 4;

				// Win2k/XP let us bind button4 and button5
				if (wParam & MK_XBUTTON1)
					temp |= 8;

				if (wParam & MK_XBUTTON2)
					temp |= 16;

				IN_MouseEvent (temp);
			}
			break;

		// JACK: This is the mouse wheel with the Intellimouse
		// Its delta is either positive or neg, and we generate the proper
		// Event.
		case WM_MOUSEWHEEL: 
			if (in_mwheeltype != MWHEEL_DINPUT)
			{
				in_mwheeltype = MWHEEL_WINDOWMSG;

				if ((short) HIWORD(wParam) > 0) {
					Key_Event(K_MWHEELUP, true);
					Key_Event(K_MWHEELUP, false);
				} else {
					Key_Event(K_MWHEELDOWN, true);
					Key_Event(K_MWHEELDOWN, false);
				}
			}
			break;

		default:
            /* pass all unhandled messages to DefWindowProc */
            lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
	        break;

	}

    /* return 0 if handled message, 1 if not */
    return lRet;
}
Пример #5
0
/* main window procedure */
LONG WINAPI MainWndProc (HWND    hWnd, UINT    uMsg, WPARAM  wParam, LPARAM  lParam) {
	extern void VID_UpdateWindowStatus (void);

    LONG lRet = 1;
	int fActive, fMinimized, temp;
	extern unsigned int uiWheelMessage;

	// VVD: didn't restore gamma after ALT+TAB on some ATI video cards (or drivers?...)
	// HACK!!! FIXME {
	extern int	restore_gamma;
	static time_t time_old;
	static float old_gamma;
	if (restore_gamma == 2) {
		if (time(NULL) - time_old > 0) {
			Cvar_SetValue(&v_gamma, old_gamma);
			restore_gamma = 0;
		}
	}
	// }

	if (uMsg == uiWheelMessage) {
		uMsg = WM_MOUSEWHEEL;
		wParam <<= 16;
	}

    switch (uMsg) {
#ifdef USINGRAWINPUT
		case WM_INPUT:
			// raw input handling
			IN_RawInput_MouseRead((HANDLE)lParam);
			break;
#endif

		case WM_KILLFOCUS:
            break;

    	case WM_SIZE:
			break;

		case WM_CREATE:

			mainwindow = hWnd;
			break;

   	    case WM_DESTROY:
			// let sound and input know about this?
			mainwindow = NULL;

//			PostQuitMessage (0);
			break;

		case WM_MOVE:
			{
				int		xPos, yPos;
				RECT r;
				int		style;

				if ( !r_fullscreen.integer )
				{
					xPos = (short) LOWORD(lParam);    // horizontal position 
					yPos = (short) HIWORD(lParam);    // vertical position 

					r.left   = 0;
					r.top    = 0;
					r.right  = 1;
					r.bottom = 1;
    
					style = GetWindowLong( hWnd, GWL_STYLE );
					AdjustWindowRect( &r, style, FALSE );
    
					Cvar_SetValue( &vid_xpos, xPos + r.left );
					Cvar_SetValue( &vid_ypos, yPos + r.top );
					vid_xpos.modified = false;
					vid_ypos.modified = false;
				}

				VID_UpdateWindowStatus();
			}
			break;

   	    case WM_CLOSE:
			if (MessageBox (mainwindow, "Are you sure you want to quit?", "ezQuake : Confirm Exit",
						MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
			{
				Host_Quit ();
			}

	        break;

		case WM_ACTIVATE:
			fActive = LOWORD(wParam);
			fMinimized = (BOOL) HIWORD(wParam);
			AppActivate(!(fActive == WA_INACTIVE), fMinimized);

			// VVD: didn't restore gamma after ALT+TAB on some ATI video cards (or drivers?...)
			// HACK!!! FIXME {
			if (restore_gamma == 1) {
				time_old = time(NULL);
				restore_gamma = 2;
				old_gamma = v_gamma.value;
				Cvar_SetValue(&v_gamma, old_gamma + 0.01);
			}
			// }
			// fix the leftover Alt from any Alt-Tab or the like that switched us away
			ClearAllStates ();

			break;

		case WM_SYSKEYDOWN:
			if ( wParam == 13 )
			{
				if ( glw_state.vid_canalttab )
				{
					Cvar_LatchedSetValue( &r_fullscreen, !r_fullscreen.integer );
					Cbuf_AddText( "vid_restart\n" );
				}
				return 0;
			}
			// fall through
		case WM_KEYDOWN:
#ifdef WITH_KEYMAP
			IN_TranslateKeyEvent (lParam, wParam, true);
#else // WITH_KEYMAP
			Key_Event (IN_MapKey(lParam), true);
#endif // WITH_KEYMAP else
			break;

		case WM_KEYUP:
		case WM_SYSKEYUP:
#ifdef WITH_KEYMAP
			IN_TranslateKeyEvent (lParam, wParam, false);
#else // WITH_KEYMAP
			Key_Event (IN_MapKey(lParam), false);
#endif // WITH_KEYMAP else
			break;

		case WM_SYSCHAR:
			// keep Alt-Space from happening
			break;
		// this is complicated because Win32 seems to pack multiple mouse events into
		// one update sometimes, so we always check all states and look for events
		case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
		case WM_XBUTTONDOWN:
		case WM_XBUTTONUP:
#ifdef MM_CODE
		case WM_LBUTTONDBLCLK:
		case WM_RBUTTONDBLCLK:
		case WM_MBUTTONDBLCLK:
		case WM_XBUTTONDBLCLK:
#endif // MM_CODE
			temp = 0;

			if (wParam & MK_LBUTTON)
				temp |= 1;

			if (wParam & MK_RBUTTON)
				temp |= 2;

			if (wParam & MK_MBUTTON)
				temp |= 4;

			if (wParam & MK_XBUTTON1)
				temp |= 8;

			if (wParam & MK_XBUTTON2)
				temp |= 16;

			IN_MouseEvent (temp);

			break;

		// JACK: This is the mouse wheel with the Intellimouse
		// Its delta is either positive or neg, and we generate the proper Event.
		case WM_MOUSEWHEEL:
			if (in_mwheeltype != MWHEEL_DINPUT)
			{
				in_mwheeltype = MWHEEL_WINDOWMSG;

				if ((short) HIWORD(wParam) > 0) {
					Key_Event(K_MWHEELUP, true);
					Key_Event(K_MWHEELUP, false);
				} else {
					Key_Event(K_MWHEELDOWN, true);
					Key_Event(K_MWHEELDOWN, false);
				}

				// when an application processes the WM_MOUSEWHEEL message, it must return zero
				lRet = 0;
			}
			break;

		case WM_MWHOOK:
			MW_Hook_Message (lParam);
			break;

		case MM_MCINOTIFY:
			lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
			break;

		default:
			/* pass all unhandled messages to DefWindowProc */
			lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
			break;
	}

	/* return 1 if handled message, 0 if not */
	return lRet;
}
Пример #6
0
ATHStackSystem::ATHStackSystem()
{
	ClearAllStates();
}