-// Note that 0 is MODE_WINDOWED
-//cvar_t _vid_default_mode = {"_vid_default_mode","0", true};
-// Note that 3 is MODE_FULLSCREEN_DEFAULT
-//cvar_t _vid_default_mode_win = {"_vid_default_mode_win","3", true};
-
-int window_center_x, window_center_y, window_x, window_y, window_width, window_height;
-RECT window_rect;
-
-// direct draw software compatability stuff
-
-void CenterWindow(HWND hWndCenter, int width, int height, BOOL lefttopjustify)
-{
- int CenterX, CenterY;
-
- CenterX = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
- CenterY = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
- if (CenterX > CenterY*2)
- CenterX >>= 1; // dual screens
- CenterX = (CenterX < 0) ? 0: CenterX;
- CenterY = (CenterY < 0) ? 0: CenterY;
- SetWindowPos (hWndCenter, NULL, CenterX, CenterY, 0, 0,
- SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
-}
-
-qboolean VID_SetWindowedMode (int modenum)
-{
- int lastmodestate, width, height;
- RECT rect;
-
- lastmodestate = modestate;
-
- WindowRect.top = WindowRect.left = 0;
-
- WindowRect.right = modelist[modenum].width;
- WindowRect.bottom = modelist[modenum].height;
-
- DIBWidth = modelist[modenum].width;
- DIBHeight = modelist[modenum].height;
-
- WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
- ExWindowStyle = 0;
-
- rect = WindowRect;
- AdjustWindowRectEx(&rect, WindowStyle, false, 0);
-
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
-
- // Create the DIB window
- mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlaces", "DarkPlacesGL", WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
-
- if (!mainwindow)
- Sys_Error ("Couldn't create DIB window");
-
- // Center and show the DIB window
- CenterWindow(mainwindow, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, false);
-
- ShowWindow (mainwindow, SW_SHOWDEFAULT);
- UpdateWindow (mainwindow);
-
- modestate = MS_WINDOWED;
-
- if (vid.conheight > modelist[modenum].height)
- vid.conheight = modelist[modenum].height;
- if (vid.conwidth > modelist[modenum].width)
- vid.conwidth = modelist[modenum].width;
- vid.width = vid.conwidth;
- vid.height = vid.conheight;
-
- SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
- SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
-
- return true;
-}
-
-
-qboolean VID_SetFullDIBMode (int modenum)
-{
- int lastmodestate, width, height;
- RECT rect;
-
- if (!leavecurrentmode)
- {
- gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
- gdevmode.dmBitsPerPel = modelist[modenum].bpp;
- gdevmode.dmPelsWidth = modelist[modenum].width <<
- modelist[modenum].halfscreen;
- gdevmode.dmPelsHeight = modelist[modenum].height;
- gdevmode.dmSize = sizeof (gdevmode);
-
- if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
- Sys_Error ("Couldn't set fullscreen DIB mode");
- }
-
- lastmodestate = modestate;
- modestate = MS_FULLDIB;
-
- WindowRect.top = WindowRect.left = 0;
-
- WindowRect.right = modelist[modenum].width;
- WindowRect.bottom = modelist[modenum].height;
-
- DIBWidth = modelist[modenum].width;
- DIBHeight = modelist[modenum].height;
-
- WindowStyle = WS_POPUP;
- ExWindowStyle = 0;
-
- rect = WindowRect;
- AdjustWindowRectEx(&rect, WindowStyle, false, 0);
-
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
-
- // Create the DIB window
- mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlaces", "DarkPlacesGL", WindowStyle, rect.left, rect.top, width, height, NULL, NULL, global_hInstance, NULL);
-
- if (!mainwindow)
- Sys_Error ("Couldn't create DIB window");
-
- ShowWindow (mainwindow, SW_SHOWDEFAULT);
- UpdateWindow (mainwindow);
-
- if (vid.conheight > modelist[modenum].height)
- vid.conheight = modelist[modenum].height;
- if (vid.conwidth > modelist[modenum].width)
- vid.conwidth = modelist[modenum].width;
- vid.width = vid.conwidth;
- vid.height = vid.conheight;
-
-// needed because we're not getting WM_MOVE messages fullscreen on NT
- window_x = 0;
- window_y = 0;
-
- SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
- SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
-
- return true;
-}
-
-
-int VID_SetMode (int modenum)
-{
- int original_mode, temp;
- qboolean stat;
- MSG msg;
-
- if ((windowed && (modenum != 0)) || (!windowed && (modenum < 1)) || (!windowed && (modenum >= nummodes)))
- Sys_Error ("Bad video mode\n");
-
-// 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 ();
-
- if (vid_modenum == NO_MODE)
- original_mode = windowed_default;
- else
- original_mode = vid_modenum;
-
- // Set either the fullscreen or windowed mode
- if (modelist[modenum].type == MS_WINDOWED)
- {
-// if (vid_mouse.value && key_dest == key_game)
-// {
-// stat = VID_SetWindowedMode(modenum);
-// usingmouse = true;
-// IN_ActivateMouse ();
-// IN_HideMouse ();
-// }
-// else
-// {
-// usingmouse = false;
-// IN_DeactivateMouse ();
-// IN_ShowMouse ();
-// stat = VID_SetWindowedMode(modenum);
-// }
- stat = VID_SetWindowedMode(modenum);
- }
- else if (modelist[modenum].type == MS_FULLDIB)
- {
- stat = VID_SetFullDIBMode(modenum);
-// usingmouse = true;
-// IN_ActivateMouse ();
-// IN_HideMouse ();
- }
- else
- Sys_Error ("VID_SetMode: Bad mode type in modelist");
-
- window_width = DIBWidth;
- window_height = DIBHeight;
- VID_UpdateWindowStatus ();
-
- CDAudio_Resume ();
- scr_disabled_for_loading = temp;
-
- if (!stat)
- Sys_Error ("Couldn't set video mode");
-
-// now we try to make sure we get the focus on the mode switch, because
-// sometimes in some systems we don't. We grab the foreground, then
-// finish setting up, pump all our messages, and sleep for a little while
-// to let messages finish bouncing around the system, then we put
-// ourselves at the top of the z order, then grab the foreground again,
-// Who knows if it helps, but it probably doesn't hurt
- SetForegroundWindow (mainwindow);
- vid_modenum = modenum;
- Cvar_SetValue ("vid_mode", (float)vid_modenum);
-
- while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
- {
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
-
- Sleep (100);
-
- SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
-
- SetForegroundWindow (mainwindow);
-
-// fix the leftover Alt from any Alt-Tab or the like that switched us away
- ClearAllStates ();
-
- if (!msg_suppress_1)
- Con_SafePrintf ("Video mode %s initialized.\n", VID_GetModeDescription (vid_modenum));