// // I_InitMouseDriver // // Instantiates the proper concrete MouseInput object based on the // mouse_driver cvar and stores a pointer to the object in mouse_input. // void I_InitMouseDriver() { I_ShutdownMouseDriver(); // ignore SDL mouse input for now... The mouse driver will change this if needed I_SetSDLIgnoreMouseEvents(); if (nomouse) return; // try to initialize the user's preferred mouse driver MouseDriverInfo_t* info = I_FindMouseDriverInfo(mouse_driver_id); if (info) { if (info->create != NULL) mouse_input = info->create(); if (mouse_input != NULL) Printf(PRINT_HIGH, "I_InitMouseDriver: Initializing %s input.\n", info->name); else Printf(PRINT_HIGH, "I_InitMouseDriver: Unable to initalize %s input.\n", info->name); } // fall back on SDLMouse if the preferred driver failed to initialize if (mouse_input == NULL) { mouse_input = SDLMouse::create(); if (mouse_input != NULL) Printf(PRINT_HIGH, "I_InitMouseDriver: Initializing SDL Mouse input as a fallback.\n"); else Printf(PRINT_HIGH, "I_InitMouseDriver: Unable to initialize SDL Mouse input as a fallback.\n"); } I_FlushInput(); I_ResumeMouse(); }
// // UpdateGrab (From chocolate-doom) // static void UpdateGrab(void) { bool grab = MouseShouldBeGrabbed(); if (grab && !mousegrabbed) { SetCursorState(false); SDL_WM_GrabInput(SDL_GRAB_ON); // Warp the mouse back to the middle of the screen if(screen) SDL_WarpMouse(screen->width/ 2, screen->height / 2); I_FlushInput(); } else if (!grab && mousegrabbed) { SetCursorState(true); SDL_WM_GrabInput(SDL_GRAB_OFF); } #if defined WIN32 && !defined _XBOX if (Args.CheckParm ("-gdi")) { if (grab) FixGDIMouseInput(); else RestoreGDIMouseSettings(); } #endif mousegrabbed = grab; }
// // I_UpdateFocus // // Update the value of window_focused each tic and in response to SDL // window manager events. // // We try to make ourselves be well-behaved: the grab on the mouse // is removed if we lose focus (such as a popup window appearing), // and we dont move the mouse around if we aren't focused either. // static void I_UpdateFocus() { bool new_window_focused = I_CheckFocusState(); if (new_window_focused && !window_focused) { I_FlushInput(); } else if (!new_window_focused && window_focused) { } window_focused = new_window_focused; }
// // I_UpdateInputGrabbing // // Determines if SDL should grab the mouse based on the game window having // focus and the status of the menu and console. // static void I_UpdateInputGrabbing() { #ifndef GCONSOLE bool can_grab = false; bool grabbed = SDL_WM_GrabInput(SDL_GRAB_QUERY); if (!window_focused) can_grab = false; else if (vid_fullscreen) can_grab = true; else if (nomouse) can_grab = false; else if (configuring_controls) can_grab = true; else if (menuactive || ConsoleState == c_down || paused) can_grab = false; else if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) && !demoplayback) can_grab = true; // force I_ResumeMouse or I_PauseMouse if toggling between fullscreen/windowed static float prev_vid_fullscreen = vid_fullscreen; if (vid_fullscreen != prev_vid_fullscreen) grabbed = !can_grab; prev_vid_fullscreen = vid_fullscreen; // check if the window focus changed (or menu/console status changed) if (can_grab && !grabbed) { SDL_WM_GrabInput(SDL_GRAB_ON); I_ResumeMouse(); I_FlushInput(); } else if (grabbed && !can_grab) { SDL_WM_GrabInput(SDL_GRAB_OFF); I_PauseMouse(); } #endif }
// // I_SetVideoMode // // Main function to set the video mode at the hardware level. // void I_SetVideoMode(int width, int height, int surface_bpp, bool fullscreen, bool vsync) { // ensure the requested mode is valid IVideoMode desired_mode(width, height, surface_bpp, fullscreen); IVideoMode mode = I_ValidateVideoMode(&desired_mode); assert(mode.isValid()); IWindow* window = I_GetWindow(); window->setMode(mode.getWidth(), mode.getHeight(), mode.getBitsPerPixel(), mode.isFullScreen(), vsync); I_ForceUpdateGrab(); // [SL] 2011-11-30 - Prevent the player's view angle from moving I_FlushInput(); // Set up the primary and emulated surfaces primary_surface = window->getPrimarySurface(); int surface_width = primary_surface->getWidth(), surface_height = primary_surface->getHeight(); I_FreeSurface(converted_surface); converted_surface = NULL; I_FreeSurface(matted_surface); matted_surface = NULL; I_FreeSurface(emulated_surface); emulated_surface = NULL; // Handle a requested 8bpp surface when the video capabilities only support 32bpp if (surface_bpp != mode.getBitsPerPixel()) { const PixelFormat* format = surface_bpp == 8 ? I_Get8bppPixelFormat() : I_Get32bppPixelFormat(); converted_surface = new IWindowSurface(surface_width, surface_height, format); primary_surface = converted_surface; } // clear window's surface to all black; primary_surface->lock(); primary_surface->clear(); primary_surface->unlock(); // [SL] Determine the size of the matted surface. // A matted surface will be used if pillar-boxing or letter-boxing are used, or // if vid_320x200/vid_640x400 are being used in a wide-screen video mode, or // if vid_overscan is used to create a matte around the entire screen. // // Only vid_overscan creates a matted surface if the video mode is 320x200 or 640x400. // if (vid_overscan < 1.0f) { surface_width *= vid_overscan; surface_height *= vid_overscan; } if (!I_IsProtectedResolution(I_GetVideoWidth(), I_GetVideoHeight())) { if (vid_320x200 || vid_640x400) surface_width = surface_height * 4 / 3; else if (V_UsePillarBox()) surface_width = surface_height * 4 / 3; else if (V_UseLetterBox()) surface_height = surface_width * 9 / 16; } // Ensure matted surface dimensions are sane and sanitized. surface_width = clamp<uint16_t>(surface_width, 320, MAXWIDTH); surface_height = clamp<uint16_t>(surface_height, 200, MAXHEIGHT); // Anything wider than 16:9 starts to look more distorted and provides even more advantage, so for now // if the monitor aspect ratio is wider than 16:9, clamp it to that (TODO: Aspect ratio selection) if (surface_width / surface_height > 16 / 9) surface_width = (surface_height * 16) / 9; // Is matting being used? Create matted_surface based on the primary_surface. if (surface_width != primary_surface->getWidth() || surface_height != primary_surface->getHeight()) { matted_surface = new IWindowSurface(primary_surface, surface_width, surface_height); primary_surface = matted_surface; } // Create emulated_surface for emulating low resolution modes. if (vid_320x200) { emulated_surface = new IWindowSurface(320, 200, primary_surface->getPixelFormat()); emulated_surface->clear(); } else if (vid_640x400) { emulated_surface = new IWindowSurface(640, 400, primary_surface->getPixelFormat()); emulated_surface->clear(); } screen = primary_surface->getDefaultCanvas(); assert(I_VideoInitialized()); if (*window->getVideoMode() != desired_mode) DPrintf("I_SetVideoMode: could not set video mode to %s. Using %s instead.\n", I_GetVideoModeString(&desired_mode).c_str(), I_GetVideoModeString(window->getVideoMode()).c_str()); else DPrintf("I_SetVideoMode: set video mode to %s\n", I_GetVideoModeString(window->getVideoMode()).c_str()); const argb_t* palette = V_GetGamePalette()->colors; if (matted_surface) matted_surface->setPalette(palette); if (emulated_surface) emulated_surface->setPalette(palette); if (converted_surface) converted_surface->setPalette(palette); // handle the -noblit parameter when playing a LMP demo if (noblit) window->disableRefresh(); else window->enableRefresh(); }