From a3635376cf14291c07dd92a0f9161d6cdd968081 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Sat, 9 Feb 2013 23:20:40 +0000 Subject: [PATCH] no more trouble with middle mouse button camera view --- source/glest_game/game/game.cpp | 7 ++++++- source/shared_lib/include/platform/sdl/window.h | 1 + source/shared_lib/sources/platform/sdl/window.cpp | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 0a2bac5c4..d999aec51 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -3385,7 +3385,12 @@ void Game::mouseMove(int x, int y, const MouseState *ms) { float ymult = 0.2f; float xmult = 0.2f; - gameCamera.transitionVH(-(y - lastMousePos.y) * ymult, (lastMousePos.x - x) * xmult); + Vec2i oldPos=Shared::Platform::Window::getOldMousePos(); + int oldx= (oldPos.x * metrics.getVirtualW() / metrics.getScreenW()); + int oldy= ((metrics.getScreenH()-oldPos.y) * metrics.getVirtualH() / metrics.getScreenH()); + lastMousePos.x=oldx; + lastMousePos.y=oldy; + gameCamera.transitionVH(-(y - oldy) * ymult, (oldx - x) * xmult); } mouseX=lastMousePos.x; mouseY=lastMousePos.y; diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index 8755fa8bc..dbc87d6db 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -132,6 +132,7 @@ protected: public: static bool handleEvent(); static void revertMousePos(); + static Vec2i getOldMousePos(); static bool isKeyDown() { return isKeyPressedDown; } static void setupGraphicsScreen(int depthBits=-1, int stencilBits=-1, bool hardware_acceleration=false, bool fullscreen_anti_aliasing=false); static const bool getIsFullScreen() { return isFullScreen; } diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index ad9431bf8..399c69227 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -359,6 +359,10 @@ void Window::revertMousePos() { SDL_WarpMouse(oldX, oldY); } +Vec2i Window::getOldMousePos() { + return Vec2i(oldX, oldY); +} + string Window::getText() { char* c = 0; SDL_WM_GetCaption(&c, 0);