本文整理汇总了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);
}
示例2: SDL_SetRelativeMouseMode
void Input::capturePtr(bool response) const
{
if(response)
SDL_SetRelativeMouseMode(SDL_TRUE);
else
SDL_SetRelativeMouseMode(SDL_FALSE);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例7: SDL_SetRelativeMouseMode
void AXWindow::lockCursor(bool value){
if(value){
SDL_SetRelativeMouseMode(SDL_TRUE);
}else{
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}
示例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);
});
}
示例9: SDL_SetRelativeMouseMode
void Input::capturePointer(bool capture) const
{
if(capture)
{
SDL_SetRelativeMouseMode(SDL_TRUE);
}
else
{
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}
示例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);
}
}
示例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;
}
示例12: SDL_bool
void ApplicationContextSDL::setWindowGrab(NativeWindowType* win, bool _grab)
{
SDL_bool grab = SDL_bool(_grab);
SDL_SetWindowGrab(win, grab);
SDL_SetRelativeMouseMode(grab);
}
示例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;
}
}
示例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();
}
示例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;
}