diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index a420288d6..15f1adb35 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -379,17 +379,7 @@ ui::Point GameController::PointTranslate(ui::Point point) if(point.X < 0) point.X = 0; - bool zoomEnabled = gameModel->GetZoomEnabled(); - if(!zoomEnabled) - return point; - //If we try to draw inside the zoom window, normalise the coordinates - int zoomFactor = gameModel->GetZoomFactor(); - ui::Point zoomWindowPosition = gameModel->GetZoomWindowPosition(); - ui::Point zoomWindowSize = ui::Point(gameModel->GetZoomSize()*zoomFactor, gameModel->GetZoomSize()*zoomFactor); - - if(point.X >= zoomWindowPosition.X && point.X >= zoomWindowPosition.Y && point.X <= zoomWindowPosition.X+zoomWindowSize.X && point.Y <= zoomWindowPosition.Y+zoomWindowSize.Y) - return ((point-zoomWindowPosition)/gameModel->GetZoomFactor())+gameModel->GetZoomPosition(); - return point; + return gameModel->AdjustZoomCoords(point); } ui::Point GameController::NormaliseBlockCoord(ui::Point point) diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index 8e5b0a325..19bebdcdc 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -326,7 +326,7 @@ void GameModel::BuildMenus() //Add special sign and prop tools menuList[SC_TOOL]->AddTool(new WindTool(0, "WIND", "Creates air movement.", 64, 64, 64, "DEFAULT_UI_WIND")); menuList[SC_TOOL]->AddTool(new PropertyTool()); - menuList[SC_TOOL]->AddTool(new SignTool()); + menuList[SC_TOOL]->AddTool(new SignTool(this)); menuList[SC_TOOL]->AddTool(new SampleTool(this)); //Add decoration tools to menu @@ -694,6 +694,20 @@ ui::Point GameModel::GetZoomPosition() return ren->zoomScopePosition; } +ui::Point GameModel::AdjustZoomCoords(ui::Point position) +{ + if (!GetZoomEnabled()) + return position; + + int zoomFactor = GetZoomFactor(); + ui::Point zoomWindowPosition = GetZoomWindowPosition(); + ui::Point zoomWindowSize = ui::Point(GetZoomSize()*zoomFactor, GetZoomSize()*zoomFactor); + + if (position.X >= zoomWindowPosition.X && position.X >= zoomWindowPosition.Y && position.X <= zoomWindowPosition.X+zoomWindowSize.X && position.Y <= zoomWindowPosition.Y+zoomWindowSize.Y) + return ((position-zoomWindowPosition)/GetZoomFactor())+GetZoomPosition(); + return position; +} + void GameModel::SetZoomWindowPosition(ui::Point position) { ren->zoomWindowPosition = position; diff --git a/src/gui/game/GameModel.h b/src/gui/game/GameModel.h index f77fe2672..8bdf1d1f9 100644 --- a/src/gui/game/GameModel.h +++ b/src/gui/game/GameModel.h @@ -182,6 +182,7 @@ public: int GetZoomFactor(); void SetZoomPosition(ui::Point position); ui::Point GetZoomPosition(); + ui::Point AdjustZoomCoords(ui::Point position); void SetZoomWindowPosition(ui::Point position); ui::Point GetZoomWindowPosition(); void SetStamp(GameSave * newStamp); diff --git a/src/gui/game/SignTool.cpp b/src/gui/game/SignTool.cpp index fdc1fb5c0..133b2d95c 100644 --- a/src/gui/game/SignTool.cpp +++ b/src/gui/game/SignTool.cpp @@ -7,6 +7,7 @@ #include "gui/interface/Label.h" #include "gui/interface/Textbox.h" #include "gui/interface/DropDown.h" +#include "gui/game/GameModel.h" class SignWindow: public ui::Window { @@ -222,12 +223,13 @@ void SignWindow::DoMouseMove(int x, int y, int dx, int dy) { ui::Window::DoMouseMove(x, y, dx, dy); else { - if(x < XRES && y < YRES) + ui::Point pos = tool->gameModel->AdjustZoomCoords(ui::Point(x, y)); + if(pos.X < XRES && pos.Y < YRES) { - movingSign->x = x; - movingSign->y = y; - signPosition.X = x; - signPosition.Y = y; + movingSign->x = pos.X; + movingSign->y = pos.Y; + signPosition.X = pos.X; + signPosition.Y = pos.Y; } } } diff --git a/src/gui/game/Tool.h b/src/gui/game/Tool.h index 641611ffe..76988da19 100644 --- a/src/gui/game/Tool.h +++ b/src/gui/game/Tool.h @@ -42,11 +42,15 @@ public: int colRed, colBlue, colGreen; }; +class GameModel; + class SignTool: public Tool { public: - SignTool(): - Tool(0, "SIGN", "Sign. Displays text. Click on a sign to edit it or anywhere else to place a new one.", 0, 0, 0, "DEFAULT_UI_SIGN", SignTool::GetIcon) + GameModel * gameModel; + SignTool(GameModel *model): + Tool(0, "SIGN", "Sign. Displays text. Click on a sign to edit it or anywhere else to place a new one.", 0, 0, 0, "DEFAULT_UI_SIGN", SignTool::GetIcon), + gameModel(model) { } static VideoBuffer * GetIcon(int toolID, int width, int height); @@ -58,8 +62,6 @@ public: virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } }; -class GameModel; - class SampleTool: public Tool { GameModel * gameModel;