当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_SetRelativeMouseMode函数代码示例

本文整理汇总了C++中SDL_SetRelativeMouseMode函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_SetRelativeMouseMode函数的具体用法?C++ SDL_SetRelativeMouseMode怎么用?C++ SDL_SetRelativeMouseMode使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_SetRelativeMouseMode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: window_grab

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);
}
开发者ID:andrewbird,项目名称:dosemu2,代码行数:29,代码来源:sdl.c

示例2: SDL_SetRelativeMouseMode

void Input::capturePtr(bool response) const
{
    if(response)
        SDL_SetRelativeMouseMode(SDL_TRUE);
    else
        SDL_SetRelativeMouseMode(SDL_FALSE);
}
开发者ID:Kloxx,项目名称:Wip3,代码行数:7,代码来源:Input.cpp

示例3: SDL_SetRelativeMouseMode

void GraphicsManager::toggleMouseGrab() {
	// Same as ScummVM's OSystem_SDL::toggleMouseGrab()
	if (SDL_GetRelativeMouseMode() == SDL_FALSE)
		SDL_SetRelativeMouseMode(SDL_TRUE);
	else
		SDL_SetRelativeMouseMode(SDL_FALSE);
}
开发者ID:strand,项目名称:xoreos,代码行数:7,代码来源:graphics.cpp

示例4: SDL_ShowCursor

//------------------------------------------------------------------------------------------------------
//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);
	}
	
}
开发者ID:djkarstenv,项目名称:Handmade,代码行数:33,代码来源:InputManager.cpp

示例5: SDL_GetKeyboardState

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);
    }
}
开发者ID:paanil,项目名称:jkhmip,代码行数:60,代码来源:CameraController.cpp

示例6: sdl_loop

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();
}
开发者ID:adararnon,项目名称:moonlight-embedded,代码行数:25,代码来源:sdl.c

示例7: SDL_SetRelativeMouseMode

void AXWindow::lockCursor(bool value){
    if(value){
        SDL_SetRelativeMouseMode(SDL_TRUE);
    }else{
        SDL_SetRelativeMouseMode(SDL_FALSE);
    }
}
开发者ID:vexparadox,项目名称:cFMake,代码行数:7,代码来源:AXWindow.cpp

示例8: SDL_SetRelativeMouseMode

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);
    });
}
开发者ID:y8tsai,项目名称:OPENGL-BOW-ARROW-Interactive-Game,代码行数:10,代码来源:Core.cpp

示例9: SDL_SetRelativeMouseMode

void Input::capturePointer(bool capture) const
{
    if(capture)
    {
        SDL_SetRelativeMouseMode(SDL_TRUE);
    }
    else
    {
        SDL_SetRelativeMouseMode(SDL_FALSE);
    }
}
开发者ID:gaultier,项目名称:SDL2_OpenGL3.3_Sample,代码行数:11,代码来源:Input.cpp

示例10: SDL_SetRelativeMouseMode

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);
	}
}
开发者ID:Arroon,项目名称:openage,代码行数:14,代码来源:input_manager.cpp

示例11: mouse_getSetRelativeMouseMode

/**
 * @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;
}
开发者ID:03050903,项目名称:Torque3D,代码行数:55,代码来源:testautomation_mouse.c

示例12: SDL_bool

void ApplicationContextSDL::setWindowGrab(NativeWindowType* win, bool _grab)
{
    SDL_bool grab = SDL_bool(_grab);

    SDL_SetWindowGrab(win, grab);
    SDL_SetRelativeMouseMode(grab);
}
开发者ID:yiliu1203,项目名称:OGRE,代码行数:7,代码来源:OgreApplicationContextSDL.cpp

示例13: IN_GrabMouse

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;
	}
}
开发者ID:raedwulf,项目名称:etlegacy,代码行数:29,代码来源:sdl_input.c

示例14: cleanup

/// 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();
}
开发者ID:Boom-Rang,项目名称:inexor-code,代码行数:36,代码来源:main.cpp

示例15: GrabMouse

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;
}
开发者ID:kostya7,项目名称:ezquake-source,代码行数:26,代码来源:vid_sdl2.c


注:本文中的SDL_SetRelativeMouseMode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。