From cda368b96cad8cafcebf43a385f91e63e7f787de Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 27 Mar 2010 21:32:33 +0000 Subject: [PATCH] Added logic to NOT trigger camera mousemove if keyboard has a key pressed so you can scroll with keys and still move mouse simultaneously --- source/glest_game/game/game.cpp | 36 ++++++++++--------- .../shared_lib/include/platform/sdl/window.h | 2 ++ .../include/platform/win32/window.h | 6 ++-- .../sources/platform/sdl/window.cpp | 13 ++++--- .../sources/platform/win32/window.cpp | 9 +++-- 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 8b2fcb2e..427aa0f2 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -437,24 +437,26 @@ void Game::mouseMove(int x, int y, const MouseState *ms){ } else { //main window - if (y < 10) { - gameCamera.setMoveZ(-scrollSpeed); - } - else if (y > metrics.getVirtualH() - 10) { - gameCamera.setMoveZ(scrollSpeed); - } - else { - gameCamera.setMoveZ(0); - } + if(Window::isKeyDown() == false) { + if (y < 10) { + gameCamera.setMoveZ(-scrollSpeed); + } + else if (y > metrics.getVirtualH() - 10) { + gameCamera.setMoveZ(scrollSpeed); + } + else { + gameCamera.setMoveZ(0); + } - if (x < 10) { - gameCamera.setMoveX(-scrollSpeed); - } - else if (x > metrics.getVirtualW() - 10) { - gameCamera.setMoveX(scrollSpeed); - } - else { - gameCamera.setMoveX(0); + if (x < 10) { + gameCamera.setMoveX(-scrollSpeed); + } + else if (x > metrics.getVirtualW() - 10) { + gameCamera.setMoveX(scrollSpeed); + } + else { + gameCamera.setMoveX(0); + } } if (mainMessageBox.getEnabled()) { diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index 3bc7a436..dc084ec6 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -111,6 +111,7 @@ private: static unsigned int lastMouseEvent; /** for use in mouse hover calculations */ static MouseState mouseState; static Vec2i mousePos; + static bool isKeyPressedDown; static void setLastMouseEvent(unsigned int lastMouseEvent) {Window::lastMouseEvent = lastMouseEvent;} static unsigned int getLastMouseEvent() {return Window::lastMouseEvent;} @@ -127,6 +128,7 @@ protected: public: static bool handleEvent(); static void revertMousePos(); + static bool isKeyDown() { return isKeyPressedDown; } Window(); diff --git a/source/shared_lib/include/platform/win32/window.h b/source/shared_lib/include/platform/win32/window.h index c443252f..e61ba77a 100644 --- a/source/shared_lib/include/platform/win32/window.h +++ b/source/shared_lib/include/platform/win32/window.h @@ -110,7 +110,8 @@ private: static unsigned int lastMouseEvent; /** for use in mouse hover calculations */ static MouseState mouseState; - static Vec2i mousePos; + static Vec2i mousePos; + static bool isKeyPressedDown; static void setLastMouseEvent(unsigned int lastMouseEvent) {Window::lastMouseEvent = lastMouseEvent;} static unsigned int getLastMouseEvent() {return Window::lastMouseEvent;} @@ -119,7 +120,7 @@ private: static void setMouseState(MouseButton b, bool state) {Window::mouseState.set(b, state);} static const Vec2i &getMousePos() {return Window::mousePos;} - static void setMousePos(const Vec2i &mousePos) {Window::mousePos = mousePos;} + static void setMousePos(const Vec2i &mousePos) {Window::mousePos = mousePos;} protected: WindowHandle handle; @@ -137,6 +138,7 @@ protected: public: static bool handleEvent(); static void revertMousePos(); + static bool isKeyDown() { return isKeyPressedDown; } //contructor & destructor Window(); diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 1bfe354e..e29293dd 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -36,7 +36,7 @@ static int oldX=0,oldY=0; unsigned int Window::lastMouseEvent = 0; /** for use in mouse hover calculations */ Vec2i Window::mousePos; MouseState Window::mouseState; - +bool Window::isKeyPressedDown = false; // ========== PUBLIC ========== @@ -59,6 +59,7 @@ Window::~Window() { bool Window::handleEvent() { SDL_Event event; SDL_GetMouseState(&oldX,&oldY); + while(SDL_PollEvent(&event)) { try { //printf("START [%d]\n",event.type); @@ -69,8 +70,8 @@ bool Window::handleEvent() { case SDL_MOUSEMOTION: //printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__); - setLastMouseEvent(Chrono::getCurMillis()); - setMousePos(Vec2i(event.button.x, event.button.y)); + setLastMouseEvent(Chrono::getCurMillis()); + setMousePos(Vec2i(event.button.x, event.button.y)); break; } @@ -106,13 +107,14 @@ bool Window::handleEvent() { setMouseState(mbCenter, event.motion.state & SDL_BUTTON_MMASK); if(global_window) { - global_window->eventMouseMove(event.motion.x, event.motion.y, &getMouseState()); //&ms); + global_window->eventMouseMove(event.motion.x, event.motion.y, &getMouseState()); //&ms); } break; } case SDL_KEYDOWN: //printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__); + Window::isKeyPressedDown = true; /* handle ALT+Return */ if(event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & (KMOD_LALT | KMOD_RALT))) { @@ -125,6 +127,9 @@ bool Window::handleEvent() { break; case SDL_KEYUP: //printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__); + + Window::isKeyPressedDown = false; + if(global_window) { global_window->eventKeyUp(getKey(event.key.keysym)); } diff --git a/source/shared_lib/sources/platform/win32/window.cpp b/source/shared_lib/sources/platform/win32/window.cpp index 80405624..39d1b09e 100644 --- a/source/shared_lib/sources/platform/win32/window.cpp +++ b/source/shared_lib/sources/platform/win32/window.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -38,6 +38,7 @@ unsigned int Window::lastMouseEvent = 0; /** for use in mouse hover calculations static int oldX=0,oldY=0; Vec2i Window::mousePos; MouseState Window::mouseState; +bool Window::isKeyPressedDown = false; // ===================== PUBLIC ======================== @@ -381,6 +382,8 @@ LRESULT CALLBACK Window::eventRouter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } case WM_KEYDOWN: { + + Window::isKeyPressedDown = true; eventWindow->eventKeyDown(static_cast(wParam)); break; @@ -398,7 +401,9 @@ LRESULT CALLBACK Window::eventRouter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } case WM_KEYUP: { - + + Window::isKeyPressedDown = false; + eventWindow->eventKeyUp(static_cast(wParam)); break;