From 464f909216b95d2a35bc332f0fc83e278e7b8864 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 7 Aug 2005 00:22:31 +0000 Subject: [PATCH] Use real SDL mouse grab instead of cursor warping (should fix running game on Enlightenment 17). --- Source/OpenGL_Windows.cpp | 50 ++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 15073ce..5c8f491 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -223,8 +223,6 @@ Boolean gDone = false, gfFrontProcess = true; Game * pgame = 0; -static bool gMouseGrabbed = true; - // -------------------------------------------------------------------------- void ReportError (char * strError) @@ -432,11 +430,16 @@ static inline int clamp_sdl_mouse_button(Uint8 button) return -1; } -static void sdlEventProc(const SDL_Event &e) +static void sdlEventProc(const SDL_Event &e, Game &game) { int val; switch(e.type) { + case SDL_MOUSEMOTION: + game.deltah += e.motion.xrel; + game.deltav += e.motion.yrel; + return; + case SDL_MOUSEBUTTONDOWN: { val = clamp_sdl_mouse_button(e.button.button); @@ -479,7 +482,15 @@ static void sdlEventProc(const SDL_Event &e) if (e.key.keysym.sym == SDLK_g) { if (e.key.keysym.mod & KMOD_CTRL) - gMouseGrabbed = !gMouseGrabbed; + { + SDL_GrabMode mode = SDL_GRAB_ON; + if ((SDL_GetVideoSurface()->flags & SDL_FULLSCREEN) == 0) + { + mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); + mode = (mode==SDL_GRAB_ON) ? SDL_GRAB_OFF:SDL_GRAB_ON; + } + SDL_WM_GrabInput(mode); + } } else if (e.key.keysym.sym == SDLK_RETURN) @@ -1049,6 +1060,23 @@ Boolean SetUp (Game & game) static void DoMouse(Game & game) { +#if USE_SDL + if(mainmenu||(abs(game.deltah)<10*realmultiplier*1000&&abs(game.deltav)<10*realmultiplier*1000)) + { + game.deltah *= usermousesensitivity; + game.deltav *= usermousesensitivity; + game.mousecoordh += game.deltah; + game.mousecoordv += game.deltav; + if (game.mousecoordh < 0) + game.mousecoordh = 0; + else if (game.mousecoordh >= kContextWidth) + game.mousecoordh = kContextWidth - 1; + if (game.mousecoordv < 0) + game.mousecoordv = 0; + else if (game.mousecoordv >= kContextHeight) + game.mousecoordv = kContextHeight - 1; + } +#else static Point lastMouse = {-1,-1}; Point globalMouse; @@ -1080,7 +1108,7 @@ static void DoMouse(Game & game) game.mousecoordv=globalMouse.v; } - if((!mainmenu)&&(gMouseGrabbed)) + if(!mainmenu) { if(lastMouse.h>gMidPoint.h+100||lastMouse.hgMidPoint.v+100||lastMouse.v