signs can be moved onto the zoom window, fixes #89

This commit is contained in:
jacob1 2014-01-17 23:27:57 -05:00
parent 4e9a5bdaec
commit 0409d93789
5 changed files with 30 additions and 21 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -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;
}
}
}

View File

@ -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;