Browse Source

Fix cursor warping to center on older SDL versions
Reverted the order of the SDL_WarpMouseInWindow and SDL_GetMouseState
to its original sequence.
This avoids cursor warping to the center of screen on older SDL versions
It causes an additional SDL_MOUSEMOTION event when ungrabbing, but does
not cause any issues.

paccer 1 year ago
parent
commit
a10eb1351a

+ 1 - 1
demo/sdl_opengl2/nuklear_sdl_gl2.h

@@ -240,8 +240,8 @@ nk_sdl_handle_grab(void)
     if (ctx->input.mouse.grab) {
     if (ctx->input.mouse.grab) {
         SDL_SetRelativeMouseMode(SDL_TRUE);
         SDL_SetRelativeMouseMode(SDL_TRUE);
     } else if (ctx->input.mouse.ungrab) {
     } else if (ctx->input.mouse.ungrab) {
-        SDL_WarpMouseInWindow(sdl.win, (int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
         SDL_SetRelativeMouseMode(SDL_FALSE);
         SDL_SetRelativeMouseMode(SDL_FALSE);
+        SDL_WarpMouseInWindow(sdl.win, (int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
     } else if (ctx->input.mouse.grabbed) {
     } else if (ctx->input.mouse.grabbed) {
         ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
         ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
         ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
         ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;

+ 1 - 1
demo/sdl_opengl3/nuklear_sdl_gl3.h

@@ -349,8 +349,8 @@ nk_sdl_handle_grab(void)
     if (ctx->input.mouse.grab) {
     if (ctx->input.mouse.grab) {
         SDL_SetRelativeMouseMode(SDL_TRUE);
         SDL_SetRelativeMouseMode(SDL_TRUE);
     } else if (ctx->input.mouse.ungrab) {
     } else if (ctx->input.mouse.ungrab) {
-        SDL_WarpMouseInWindow(sdl.win, (int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
         SDL_SetRelativeMouseMode(SDL_FALSE);
         SDL_SetRelativeMouseMode(SDL_FALSE);
+        SDL_WarpMouseInWindow(sdl.win, (int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
     } else if (ctx->input.mouse.grabbed) {
     } else if (ctx->input.mouse.grabbed) {
         ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
         ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
         ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
         ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;

+ 1 - 1
demo/sdl_opengles2/nuklear_sdl_gles2.h

@@ -349,8 +349,8 @@ nk_sdl_handle_grab(void)
     if (ctx->input.mouse.grab) {
     if (ctx->input.mouse.grab) {
         SDL_SetRelativeMouseMode(SDL_TRUE);
         SDL_SetRelativeMouseMode(SDL_TRUE);
     } else if (ctx->input.mouse.ungrab) {
     } else if (ctx->input.mouse.ungrab) {
-        SDL_WarpMouseInWindow(sdl.win, (int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
         SDL_SetRelativeMouseMode(SDL_FALSE);
         SDL_SetRelativeMouseMode(SDL_FALSE);
+        SDL_WarpMouseInWindow(sdl.win, (int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
     } else if (ctx->input.mouse.grabbed) {
     } else if (ctx->input.mouse.grabbed) {
         ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
         ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
         ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
         ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;

+ 1 - 1
demo/sdl_renderer/nuklear_sdl_renderer.h

@@ -271,8 +271,8 @@ nk_sdl_handle_grab(void)
     if (ctx->input.mouse.grab) {
     if (ctx->input.mouse.grab) {
         SDL_SetRelativeMouseMode(SDL_TRUE);
         SDL_SetRelativeMouseMode(SDL_TRUE);
     } else if (ctx->input.mouse.ungrab) {
     } else if (ctx->input.mouse.ungrab) {
-        SDL_WarpMouseInWindow(sdl.win, (int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
         SDL_SetRelativeMouseMode(SDL_FALSE);
         SDL_SetRelativeMouseMode(SDL_FALSE);
+        SDL_WarpMouseInWindow(sdl.win, (int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
     } else if (ctx->input.mouse.grabbed) {
     } else if (ctx->input.mouse.grabbed) {
         ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
         ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
         ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
         ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;