From eb1121cb52d46d3e519f4cd359deb5d9697e9c49 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 21 Nov 2015 18:07:56 +0100 Subject: [PATCH] Fix hub pointer motion. Use mouse motion events to find out where the mouse is. This doesn't require scaling with the window size anymore, unlike SDL_GetMouseState(). Also, don't use SDL_WarpMouseInWindow() anymore, it doesn't seem to work correctly anymore. Instead, just update our idea of the mouse pointer's position. --- src/CEngine.cpp | 20 ++++++++++---------- src/CEngine.h | 2 +- src/hub.cpp | 18 ++++++++---------- src/init.cpp | 1 - 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/CEngine.cpp b/src/CEngine.cpp index 6f0cc75..d1723aa 100644 --- a/src/CEngine.cpp +++ b/src/CEngine.cpp @@ -155,14 +155,6 @@ void Engine::addKeyEvent() void Engine::getInput() { - SDL_GetMouseState(&mouseX, &mouseY); - - // Scale from window coordinates to graphics coordinates - int w, h; - SDL_GetWindowSize(graphics.window, &w, &h); - mouseX = mouseX * 640 / w; - mouseY = mouseY * 480 / h; - while (SDL_PollEvent(&event)) { switch (event.type) @@ -184,6 +176,11 @@ void Engine::getInput() if (event.button.button == SDL_BUTTON_RIGHT) mouseRight = 0; break; + case SDL_MOUSEMOTION: + mouseX = event.motion.x; + mouseY = event.motion.y; + break; + case SDL_KEYDOWN: if (waitForButton) @@ -325,9 +322,12 @@ int Engine::getMouseY() const return mouseY; } -void Engine::setMouse(int x, int y) +void Engine::moveMouse(int dx, int dy) { - SDL_WarpMouseInWindow(graphics.window, x, y); + mouseX += dx; + mouseY += dy; + Math::limitInt(&mouseX, 0, 640); + Math::limitInt(&mouseY, 0, 480); } bool Engine::userAccepts() diff --git a/src/CEngine.h b/src/CEngine.h index d0a8c74..e8ab558 100644 --- a/src/CEngine.h +++ b/src/CEngine.h @@ -104,7 +104,7 @@ class Engine { int getMouseX() const; int getMouseY() const; - void setMouse(int x, int y); + void moveMouse(int dx, int dy); bool userAccepts(); void clearCheatVars(); diff --git a/src/hub.cpp b/src/hub.cpp index 348c421..165c918 100644 --- a/src/hub.cpp +++ b/src/hub.cpp @@ -599,9 +599,6 @@ int doHub() Uint32 frameLimit = SDL_GetTicks() + 16; Uint32 now = SDL_GetTicks(); - int mouseXDelta = 0; - int mouseYDelta = 0; - while (rtn == -1) { graphics.updateScreen(); @@ -627,31 +624,32 @@ int doHub() engine.getInput(); config.populate(); + int mouseXDelta = 0; + int mouseYDelta = 0; + if (config.isControl(CONTROL::RIGHT)) { - mouseXDelta = 5; + mouseXDelta += 5; } if (config.isControl(CONTROL::LEFT)) { - mouseXDelta = -5; + mouseXDelta -= 5; } if (config.isControl(CONTROL::DOWN)) { - mouseYDelta = 5; + mouseYDelta += 5; } if (config.isControl(CONTROL::UP) || config.isControl(CONTROL::JUMP)) { - mouseYDelta = -5; + mouseYDelta -= 5; } if ((mouseXDelta != 0) || (mouseYDelta != 0)) { - engine.setMouse(engine.getMouseX() + (int)mouseXDelta, engine.getMouseY() + (int)mouseYDelta); - mouseXDelta = 0; - mouseYDelta = 0; + engine.moveMouse(mouseXDelta, mouseYDelta); } hubPoint = (HubLevel*)hubList.getHead(); diff --git a/src/init.cpp b/src/init.cpp index c3b9abc..b461e7b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -369,7 +369,6 @@ void initSystem() } SDL_ShowCursor(SDL_DISABLE); - SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE); graphics.registerEngine(&engine); graphics.mapColors(); -- 2.39.5