From 9b2b544b84853bd937fd4dc5ea411deb3a656776 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 25 Jun 2010 00:45:46 +0000 Subject: [PATCH] - fixed mouse cursor position problrm at game startup --- source/glest_game/game/game.cpp | 11 +++++++++++ source/glest_game/main/program.cpp | 5 +++++ source/glest_game/main/program.h | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 112be0e77..306eb5d61 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -551,10 +551,21 @@ void Game::render() { // Ensure the camera starts in the right position if(isFirstRender == true) { isFirstRender = false; + +/* Map *map= world.getMap(); const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex()); gameCamera.init(map->getW(), map->getH()); gameCamera.setPos(Vec2f(v.x, v.y)); + + //const Vec2i &mapPos = Map::toSurfCoords(v); + Renderer &renderer= Renderer::getInstance(); + Vec3f screenPos = renderer.computeScreenPosition(gameCamera.getPos()); + SDL_WarpMouse(v.x, v.y); +*/ + + gameCamera.resetPosition(); + this->restoreToStartXY(); } renderFps++; diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 49f84e712..e0be9468f 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -269,6 +269,11 @@ void Program::setState(ProgramState *programState, bool cleanupOldState) try { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + int X = 0; + int Y = 0; + SDL_GetMouseState(&X,&Y); + programState->setStartXY(X,Y); + showCursor(true); sleep(0); diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 7acee1689..3ba003113 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -45,6 +45,9 @@ class ProgramState{ protected: Program *program; + int startX; + int startY; + public: ProgramState(Program *program) {this->program= program;} virtual ~ProgramState(){}; @@ -70,6 +73,8 @@ public: virtual void keyDown(char key){}; virtual void keyUp(char key){}; virtual void keyPress(char c){}; + virtual void setStartXY(int X,int Y) { startX=X; startY=Y; } + virtual void restoreToStartXY() { SDL_WarpMouse(startX, startY); } }; // ===============================