static void window_grab(int on, int kbd) { if (on) { if (kbd) { SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1"); v_printf("SDL: keyboard grab activated\n"); } else { SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "0"); } SDL_SetWindowGrab(window, SDL_TRUE); v_printf("SDL: mouse grab activated\n"); SDL_ShowCursor(SDL_DISABLE); SDL_SetRelativeMouseMode(SDL_TRUE); mouse_enable_native_cursor(1); kbd_grab_active = kbd; } else { v_printf("SDL: grab released\n"); SDL_SetWindowGrab(window, SDL_FALSE); if (m_cursor_visible) SDL_ShowCursor(SDL_ENABLE); SDL_SetRelativeMouseMode(SDL_FALSE); mouse_enable_native_cursor(0); kbd_grab_active = 0; sync_mouse_coords(); } grab_active = on; /* update title with grab info */ SDL_change_config(CHG_TITLE, NULL); }
void Input::capturePtr(bool response) const { if(response) SDL_SetRelativeMouseMode(SDL_TRUE); else SDL_SetRelativeMouseMode(SDL_FALSE); }
void GraphicsManager::toggleMouseGrab() { // Same as ScummVM's OSystem_SDL::toggleMouseGrab() if (SDL_GetRelativeMouseMode() == SDL_FALSE) SDL_SetRelativeMouseMode(SDL_TRUE); else SDL_SetRelativeMouseMode(SDL_FALSE); }
//------------------------------------------------------------------------------------------------------ //setter function that enables, disables, shows or hides the mouse cursor //------------------------------------------------------------------------------------------------------ void InputManager::SetMouseCursorState(CursorState cursorEnabled, CursorState cursorVisible) { //if mouse cursor is enabled then check if it's visible //and display the cursor accordingly, and keep the mouse //cursor within the window border as long as it's enabled if (cursorEnabled) { if (cursorVisible) { SDL_ShowCursor(1); SDL_SetRelativeMouseMode(SDL_FALSE); } else { SDL_ShowCursor(0); SDL_SetRelativeMouseMode(SDL_FALSE); } } //if mouse cursor is disabled then hide it and free it from the window border else { SDL_ShowCursor(0); SDL_SetRelativeMouseMode(SDL_TRUE); } }
void CameraController::Update(float dt) { if (node == 0) return; const Uint8 *keys = SDL_GetKeyboardState(0); const float speed = 6.0f; const float sensitivity = 0.25f; // Camera movement Vector3 pos = node->GetPosition(); Vector3 right, up, look; node->GetBasisVectors(right, up, look); Vector3 dir(0.0f, 0.0f, 0.0f); if (keys[SDL_SCANCODE_W]) dir += look; if (keys[SDL_SCANCODE_S]) dir -= look; if (keys[SDL_SCANCODE_A]) dir -= right; if (keys[SDL_SCANCODE_D]) dir += right; if (keys[SDL_SCANCODE_SPACE]) dir += Vector3(0.0f, 1.0f, 0.0f); if (keys[SDL_SCANCODE_LCTRL]) dir -= Vector3(0.0f, 1.0f, 0.0f); float speedup = 1.0f; if (keys[SDL_SCANCODE_LSHIFT]) speedup = 2.0f; dir.SafeNormalize(); pos += dir * (speed * speedup * dt); node->SetPosition(pos); // Camera rotation int relMouseX, relMouseY; if (SDL_GetRelativeMouseState(&relMouseX, &relMouseY) & SDL_BUTTON(SDL_BUTTON_LEFT)) { SDL_SetRelativeMouseMode(SDL_TRUE); cameraAngles.y += relMouseX * sensitivity; cameraAngles.x += relMouseY * sensitivity; cameraAngles.y = Math::WrapAngleDegrees(cameraAngles.y); cameraAngles.x = Math::Clamp(cameraAngles.x, -90.0f, 90.0f); Matrix3 rot = Matrix3::RotationYXZ(cameraAngles); node->SetRotation(rot); } else { SDL_SetRelativeMouseMode(SDL_FALSE); } }
void sdl_loop() { SDL_Event event; while(!done && SDL_WaitEvent(&event)) { switch (sdlinput_handle_event(&event)) { case SDL_QUIT_APPLICATION: done = true; break; case SDL_TOGGLE_FULLSCREEN: fullscreen_flags ^= SDL_WINDOW_FULLSCREEN; SDL_SetWindowFullscreen(sdl_window, fullscreen_flags); case SDL_MOUSE_GRAB: SDL_SetRelativeMouseMode(SDL_TRUE); break; case SDL_MOUSE_UNGRAB: SDL_SetRelativeMouseMode(SDL_FALSE); break; default: if (event.type == SDL_QUIT) done = true; } } SDL_DestroyWindow(sdl_window); SDL_Quit(); }
void AXWindow::lockCursor(bool value){ if(value){ SDL_SetRelativeMouseMode(SDL_TRUE); }else{ SDL_SetRelativeMouseMode(SDL_FALSE); } }
void Core::SetupKeybinds() { Globals::EvtMgr.Register("Core::StopRun", [&](SDL_Event evt) { this->Stop(); }); Globals::EvtMgr.Register("Core::Pause", [&](SDL_Event evt) { SDL_SetRelativeMouseMode(SDL_FALSE); system("PAUSE"); SDL_SetRelativeMouseMode(SDL_TRUE); }); }
void Input::capturePointer(bool capture) const { if(capture) { SDL_SetRelativeMouseMode(SDL_TRUE); } else { SDL_SetRelativeMouseMode(SDL_FALSE); } }
void InputManager::set_relative(bool mode) { if (this->relative_mode == mode) { return; } // change mode this->relative_mode = mode; if (this->relative_mode) { SDL_SetRelativeMouseMode(SDL_TRUE); } else { SDL_SetRelativeMouseMode(SDL_FALSE); } }
/** * @brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode * * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetRelativeMouseMode * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetRelativeMouseMode */ int mouse_getSetRelativeMouseMode(void *arg) { int result; int i; SDL_bool initialState; SDL_bool currentState; /* Capture original state so we can revert back to it later */ initialState = SDL_GetRelativeMouseMode(); SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); /* Repeat twice to check D->D transition */ for (i=0; i<2; i++) { /* Disable - should always be supported */ result = SDL_SetRelativeMouseMode(SDL_FALSE); SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)"); SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); currentState = SDL_GetRelativeMouseMode(); SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState); } /* Repeat twice to check D->E->E transition */ for (i=0; i<2; i++) { /* Enable - may not be supported */ result = SDL_SetRelativeMouseMode(SDL_TRUE); SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)"); if (result != -1) { SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); currentState = SDL_GetRelativeMouseMode(); SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState); } } /* Disable to check E->D transition */ result = SDL_SetRelativeMouseMode(SDL_FALSE); SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)"); SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); currentState = SDL_GetRelativeMouseMode(); SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState); /* Revert to original state - ignore result */ result = SDL_SetRelativeMouseMode(initialState); return TEST_COMPLETED; }
void ApplicationContextSDL::setWindowGrab(NativeWindowType* win, bool _grab) { SDL_bool grab = SDL_bool(_grab); SDL_SetWindowGrab(win, grab); SDL_SetRelativeMouseMode(grab); }
static void IN_GrabMouse(qboolean grab, qboolean relative) { static qboolean mouse_grabbed = qfalse, mouse_relative = qfalse; int relative_result = 0; if (relative == !mouse_relative) { SDL_ShowCursor(!relative); if ((relative_result = SDL_SetRelativeMouseMode((SDL_bool)relative)) != 0) { // FIXME: this happens on some systems (IR4) if (relative_result == -1) { Com_Error(ERR_FATAL, "Setting relative mouse location fails (system not supported)\n"); } else { Com_Error(ERR_FATAL, "Setting relative mouse location fails: %s\n", SDL_GetError()); } } mouse_relative = relative; } if (grab == !mouse_grabbed) { SDL_SetWindowGrab(mainScreen, (SDL_bool)grab); mouse_grabbed = grab; } }
/// cleans up game memory and SDL at exit void cleanup() { extern void clear_command(); extern void clear_console(); extern void clear_mdls(); extern void clear_sound(); recorder::stop(); cleanupserver(); /// "Use this function to set a window's input grab mode." /// https://wiki.libsdl.org/SDL_SetWindowGrab if(screen) SDL_SetWindowGrab(screen, SDL_FALSE); /// "Use this function to set relative mouse mode." /// https://wiki.libsdl.org/SDL_SetRelativeMouseMode SDL_SetRelativeMouseMode(SDL_FALSE); /// "Use this function to toggle whether or not the cursor is shown." /// https://wiki.libsdl.org/SDL_ShowCursor SDL_ShowCursor(SDL_TRUE); cleargamma(); /// free octree memory freeocta(worldroot); clear_command(); clear_console(); clear_mdls(); clear_sound(); closelogfile(); /// "Use this function to clean up all initialized subsystems. You should call it upon all exit conditions." /// https://wiki.libsdl.org/SDL_Quit SDL_Quit(); }
static void GrabMouse(qbool grab, qbool raw) { if ((grab && mouse_active && raw == in_raw.integer) || (!grab && !mouse_active) || !mouseinitialized || !sdl_window) return; if (!r_fullscreen.integer && in_grab_windowed_mouse.integer == 0) { if (!mouse_active) return; grab = 0; } // set initial position if (!raw && grab) { SDL_WarpMouseInWindow(sdl_window, glConfig.vidWidth / 2, glConfig.vidHeight / 2); old_x = glConfig.vidWidth / 2; old_y = glConfig.vidHeight / 2; } SDL_SetWindowGrab(sdl_window, grab ? SDL_TRUE : SDL_FALSE); SDL_SetRelativeMouseMode((raw && grab) ? SDL_TRUE : SDL_FALSE); SDL_GetRelativeMouseState(NULL, NULL); SDL_ShowCursor(grab ? SDL_DISABLE : SDL_ENABLE); SDL_SetCursor(NULL); /* Force rewrite of it */ mouse_active = grab; }
void SDL_MouseQuit(void) { SDL_Cursor *cursor, *next; SDL_Mouse *mouse = SDL_GetMouse(); if (mouse->CaptureMouse) { SDL_CaptureMouse(SDL_FALSE); } SDL_SetRelativeMouseMode(SDL_FALSE); SDL_ShowCursor(1); cursor = mouse->cursors; while (cursor) { next = cursor->next; SDL_FreeCursor(cursor); cursor = next; } if (mouse->def_cursor && mouse->FreeCursor) { mouse->FreeCursor(mouse->def_cursor); } if (mouse->clickstate) { SDL_free(mouse->clickstate); } SDL_zerop(mouse); }
int Server::initSDL() { SDL_Init(SDL_INIT_EVERYTHING); Uint32 windowFlags; //if (Settings::getWindowState() == FULLSCREEN) windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_FULLSCREEN; windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI; //else if (Settings::getWindowState() == BORDERLESS) windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS; displayWindow = SDL_CreateWindow("Rune Server", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, windowFlags); displayContext = SDL_GL_CreateContext(displayWindow); SDL_GL_MakeCurrent(displayWindow, displayContext); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32); initOpenGL(); //resizeWindow(800, 600); SDL_SetRelativeMouseMode(SDL_FALSE); return 0; }
void SceneView::captureMouse(bool capture) { if(m_is_mouse_captured == capture) return; m_is_mouse_captured = capture; SDL_ShowCursor(m_is_mouse_captured ? 0 : 1); SDL_SetRelativeMouseMode(capture ? SDL_TRUE : SDL_FALSE); }
/* =============== IN_DeactivateMouse =============== */ static void IN_DeactivateMouse( void ) { if( !SDL_WasInit( SDL_INIT_VIDEO ) ) return; // Always show the cursor when the mouse is disabled, // but not when fullscreen if( !Cvar_VariableIntegerValue("r_fullscreen") ) SDL_ShowCursor( 1 ); if( !mouseAvailable ) return; if( mouseActive ) { IN_GobbleMotionEvents( ); SDL_SetWindowGrab( SDL_window, 0 ); SDL_SetRelativeMouseMode( SDL_FALSE ); // Don't warp the mouse unless the cursor is within the window if( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_MOUSE_FOCUS ) SDL_WarpMouseInWindow( SDL_window, cls.glconfig.vidWidth / 2, cls.glconfig.vidHeight / 2 ); mouseActive = qfalse; } }
void InputWrapper::updateMouseSettings() { mGrabPointer = mWantGrab && mMouseInWindow && mWindowHasFocus; SDL_SetWindowGrab(mSDLWindow, mGrabPointer && mAllowGrab ? SDL_TRUE : SDL_FALSE); SDL_ShowCursor(mWantMouseVisible || !mWindowHasFocus); bool relative = mWantRelative && mMouseInWindow && mWindowHasFocus; if(mMouseRelative == relative) return; mMouseRelative = relative; mWrapPointer = false; //eep, wrap the pointer manually if the input driver doesn't support //relative positioning natively int success = SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE); if(relative && success != 0) mWrapPointer = true; //now remove all mouse events using the old setting from the queue SDL_PumpEvents(); SDL_FlushEvent(SDL_MOUSEMOTION); }
void InputSystem::init() { SDL_SetRelativeMouseMode(SDL_TRUE); key_binds["P"] = KeyBind("P", "Reset"); key_binds["Space"] = KeyBind("Space", "Jump"); key_binds["F"] = KeyBind("F", "Fire"); axis_binds["W"] = AxisBind("W", "MoveForward", -1.0f); axis_binds["S"] = AxisBind("S", "MoveForward", 1.0f); axis_binds["A"] = AxisBind("A", "MoveRight", -1.0f); axis_binds["D"] = AxisBind("D", "MoveRight", 1.0f); axis_binds["Q"] = AxisBind("Q", "Turn", -1.0f); axis_binds["E"] = AxisBind("E", "Turn", 1.0f); axis_binds["Left"] = AxisBind("Left", "CameraX", 1.0f); axis_binds["Right"] = AxisBind("Right", "CameraX", -1.0f); axis_binds["Up"] = AxisBind("Up", "CameraY", 1.0f); axis_binds["Down"] = AxisBind("Down", "CameraY", -1.0f); axis_binds["MouseX"] = AxisBind("MouseX", "TurnAt", 1.0f); }
void SDL_MouseQuit(void) { SDL_Cursor *cursor, *next; SDL_Mouse *mouse = SDL_GetMouse(); if (mouse->CaptureMouse) { SDL_CaptureMouse(SDL_FALSE); } SDL_SetRelativeMouseMode(SDL_FALSE); SDL_ShowCursor(1); cursor = mouse->cursors; while (cursor) { next = cursor->next; SDL_FreeCursor(cursor); cursor = next; } if (mouse->def_cursor && mouse->FreeCursor) { mouse->FreeCursor(mouse->def_cursor); } if (mouse->clickstate) { SDL_free(mouse->clickstate); } SDL_zerop(mouse); SDL_DelHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE, SDL_MouseNormalSpeedScaleChanged, mouse); SDL_DelHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE, SDL_MouseRelativeSpeedScaleChanged, mouse); }
void SSCursor::Startup() { // Set the mouse cursor glm::ivec2 winSize = g_GUI.GetWindowSize( "RootWindow" ); g_GUI.AddWindow( "CursorWindow", GUI::Rectangle( 0, 0, winSize.x, winSize.y ), "RootWindow" ); g_GUI.OpenWindow( "CursorWindow" ); m_StandardDef = GUI::SpriteDefinition( "cursor/CursorBlank.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_AttackDef = GUI::SpriteDefinition( "cursor/CursorBlank.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE, m_AttackColour ); m_PingDef = GUI::SpriteDefinition( "cursor/CursorBlank.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE, m_PingColour ); m_PanDefs[ CAMERA_PAN_DIRECTION_UP ] = GUI::SpriteDefinition( "cursor/Cursor_Up.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_PanDefs[ CAMERA_PAN_DIRECTION_DOWN ] = GUI::SpriteDefinition( "cursor/Cursor_Down.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_PanDefs[ CAMERA_PAN_DIRECTION_LEFT ] = GUI::SpriteDefinition( "cursor/Cursor_Left.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_PanDefs[ CAMERA_PAN_DIRECTION_RIGHT ] = GUI::SpriteDefinition( "cursor/Cursor_Right.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_PanDefs[ CAMERA_PAN_DIRECTION_UP_LEFT ] = GUI::SpriteDefinition( "cursor/Cursor_UpLeft.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_PanDefs[ CAMERA_PAN_DIRECTION_UP_RIGHT ] = GUI::SpriteDefinition( "cursor/Cursor_UpRight.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_PanDefs[ CAMERA_PAN_DIRECTION_DOWN_LEFT ] = GUI::SpriteDefinition( "cursor/Cursor_DownLeft.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_PanDefs[ CAMERA_PAN_DIRECTION_DOWN_RIGHT ] = GUI::SpriteDefinition( "cursor/Cursor_DownRight.png", 0, 0, CURSOR_SPRITE_SIZE, CURSOR_SPRITE_SIZE ); m_MouseCursor = g_GUI.AddSprite( "MouseCursor", m_StandardDef, "CursorWindow" ); SDL_ShowCursor( 0 ); CallbackConfig* gfxConfig = g_ConfigManager.GetConfig( "graphics.cfg" ); SDL_SetRelativeMouseMode( gfxConfig->GetBool( "lockmouse", true ) == true ? SDL_TRUE : SDL_FALSE ); }
/* =============== IN_ActivateMouse =============== */ static void IN_ActivateMouse() { if (!mouseAvailable || !SDL_WasInit(SDL_INIT_VIDEO)) { return; } if (!mouseActive) { SDL_ShowCursor(0); SDL_SetRelativeMouseMode(SDL_TRUE); SDL_SetWindowGrab(window, SDL_TRUE); IN_GobbleMotionEvents(); } // in_nograb makes no sense in fullscreen mode if (!cls.glconfig.isFullscreen) { if (in_nograb->modified || !mouseActive) { if (in_nograb->integer) { SDL_SetWindowGrab(window, SDL_FALSE); } else { SDL_SetWindowGrab(window, SDL_TRUE); } in_nograb->modified = false; } } mouseActive = true; }
void GLimp_GrabInput( int flags ) { bool grab = flags & GRAB_ENABLE; if( grab && ( flags & GRAB_REENABLE ) ) grab = false; if( flags & GRAB_SETSTATE ) grabbed = grab; if( in_nograb.GetBool() ) grab = false; if( !window ) { common->Warning( "GLimp_GrabInput called without window" ); return; } #if SDL_VERSION_ATLEAST(2, 0, 0) // DG: disabling the cursor is now done once in GLimp_Init() because it should always be disabled // DG: check for GRAB_ENABLE instead of GRAB_HIDECURSOR because we always wanna hide it SDL_SetRelativeMouseMode( flags & GRAB_ENABLE ? SDL_TRUE : SDL_FALSE ); SDL_SetWindowGrab( window, grab ? SDL_TRUE : SDL_FALSE ); #else // DG end SDL_WM_GrabInput( grab ? SDL_GRAB_ON : SDL_GRAB_OFF ); #endif }
/** * Init Screen bitmap and buffers/tables needed for ST to PC screen conversion */ void Screen_Init(void) { int i; /* Clear frame buffer structures and set current pointer */ memset(FrameBuffers, 0, NUM_FRAMEBUFFERS * sizeof(FRAMEBUFFER)); /* Allocate previous screen check workspace. We are going to double-buffer a double-buffered screen. Oh. */ for (i = 0; i < NUM_FRAMEBUFFERS; i++) { FrameBuffers[i].pNEXTScreen = malloc(((1024)/8)*768); FrameBuffers[i].pNEXTScreenCopy = malloc(((1024)/8)*768); if (!FrameBuffers[i].pNEXTScreen || !FrameBuffers[i].pNEXTScreenCopy) { fprintf(stderr, "Failed to allocate frame buffer memory.\n"); exit(-1); } } pFrameBuffer = &FrameBuffers[0]; /* Set initial window resolution */ bInFullScreen = ConfigureParams.Screen.bFullScreen; Screen_SetResolution(); if (bGrabMouse) { SDL_SetRelativeMouseMode(SDL_TRUE); SDL_SetWindowGrab(sdlWindow, SDL_TRUE); } Video_SetScreenRasters(); /* Set rasters ready for first screen */ Screen_CreatePalette(); /* Configure some SDL stuff: */ SDL_ShowCursor(SDL_DISABLE); }
/* =============== IN_ActivateMouse =============== */ static void IN_ActivateMouse( void ) { if (!mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) ) return; if( !mouseActive ) { SDL_SetRelativeMouseMode( SDL_TRUE ); SDL_SetWindowGrab( SDL_window, 1 ); IN_GobbleMotionEvents( ); } // in_nograb makes no sense in fullscreen mode if( !Cvar_VariableIntegerValue("r_fullscreen") ) { if( in_nograb->modified || !mouseActive ) { if( in_nograb->integer ) SDL_SetWindowGrab( SDL_window, 0 ); else SDL_SetWindowGrab( SDL_window, 1 ); in_nograb->modified = qfalse; } } mouseActive = qtrue; }
static void IN_DeactivateMouse(void) { if (!SDL_WasInit(SDL_INIT_VIDEO)) { return; } SDL_SetRelativeMouseMode( SDL_FALSE ); // Always show the cursor when the mouse is disabled, // but not when fullscreen if (!Cvar_VariableIntegerValue("r_fullscreen")) SDL_ShowCursor(1); if (!mouseAvailable) { return; } if (mouseActive) { IN_GobbleMotionEvents(); SDL_SetWindowGrab( SDLvidscreen, SDL_FALSE ); mouseActive = qfalse; } }
void InputWrapper::updateMouseSettings() { mGrabPointer = mWantGrab && mMouseInWindow && mWindowHasFocus; SDL_SetWindowGrab(mSDLWindow, mGrabPointer && mAllowGrab ? SDL_TRUE : SDL_FALSE); SDL_ShowCursor(mWantMouseVisible || !mWindowHasFocus); bool relative = mWantRelative && mMouseInWindow && mWindowHasFocus; if(mMouseRelative == relative) return; mMouseRelative = relative; mWrapPointer = false; // eep, wrap the pointer manually if the input driver doesn't support // relative positioning natively // also use wrapping if no-grab was specified in options (SDL_SetRelativeMouseMode // appears to eat the mouse cursor when pausing in a debugger) bool success = mAllowGrab && SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE) == 0; if(relative && !success) mWrapPointer = true; //now remove all mouse events using the old setting from the queue SDL_PumpEvents(); SDL_FlushEvent(SDL_MOUSEMOTION); }
void fatal(const char *s, ...) // failure exit { static int errors = 0; errors++; if(errors <= 2) // print up to one extra recursive error { defvformatstring(msg,s,s); logoutf("%s", msg); if(errors <= 1) // avoid recursion { if(SDL_WasInit(SDL_INIT_VIDEO)) { if(screen) SDL_SetWindowGrab(screen, SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE); SDL_ShowCursor(SDL_TRUE); cleargamma(); } #ifdef WIN32 MessageBox(NULL, msg, "Cube 2: Sauerbraten fatal error", MB_OK|MB_SYSTEMMODAL); #endif SDL_Quit(); } } exit(EXIT_FAILURE); }