]> git.mxchange.org Git - quix0rs-blobwars.git/commitdiff
Fix hub pointer motion.
authorGuus Sliepen <guus@debian.org>
Sat, 21 Nov 2015 17:07:56 +0000 (18:07 +0100)
committerGuus Sliepen <guus@debian.org>
Sat, 21 Nov 2015 17:12:53 +0000 (18:12 +0100)
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
src/CEngine.h
src/hub.cpp
src/init.cpp

index 6f0cc752a598da6d8d4dbc13d38e229a2b5ea75e..d1723aab14f883800b8fd099e87f9228be753456 100644 (file)
@@ -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()
index d0a8c7492312446331f8a647d9fddef1a6a49900..e8ab5583f78e84eb5c130fdcdfc7d92cf0be5197 100644 (file)
@@ -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();
index 348c421efcccc7b29a122ca30258eed5ca741897..165c91897beed4a6728a1876a503aee804c064cb 100644 (file)
@@ -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();
index c3b9abcae481e10edcba03de166b517d4cb1a1af..b461e7bfad1de9906fbd893b3839544b5bd723e3 100644 (file)
@@ -369,7 +369,6 @@ void initSystem()
        }
 
        SDL_ShowCursor(SDL_DISABLE);
-       SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE);
 
        graphics.registerEngine(&engine);
        graphics.mapColors();