Skip to content

Commit

Permalink
cancel drawing when the mouse moves in / out of the zoom window, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Jan 10, 2015
1 parent c325543 commit 1a2e3a1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/gui/game/GameController.cpp
Expand Up @@ -379,6 +379,20 @@ void GameController::AdjustZoomSize(int direction, bool logarithmic)
gameModel->SetZoomFactor(newZoomFactor);
}

bool GameController::MouseInZoom(ui::Point position)
{
if(position.X >= XRES)
position.X = XRES-1;
if(position.Y >= YRES)
position.Y = YRES-1;
if(position.Y < 0)
position.Y = 0;
if(position.X < 0)
position.X = 0;

return gameModel->MouseInZoom(position);
}

ui::Point GameController::PointTranslate(ui::Point point)
{
if(point.X >= XRES)
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameController.h
Expand Up @@ -141,6 +141,7 @@ class GameController: public ClientListener
void FrameStep();
void TranslateSave(ui::Point point);
void TransformSave(matrix2d transform);
bool MouseInZoom(ui::Point position);
ui::Point PointTranslate(ui::Point point);
ui::Point NormaliseBlockCoord(ui::Point point);
std::string ElementResolve(int type, int ctype);
Expand Down
14 changes: 14 additions & 0 deletions src/gui/game/GameModel.cpp
Expand Up @@ -691,6 +691,20 @@ ui::Point GameModel::GetZoomPosition()
return ren->zoomScopePosition;
}

bool GameModel::MouseInZoom(ui::Point position)
{
if (!GetZoomEnabled())
return false;

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 true;
return false;
}

ui::Point GameModel::AdjustZoomCoords(ui::Point position)
{
if (!GetZoomEnabled())
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameModel.h
Expand Up @@ -181,6 +181,7 @@ class GameModel
int GetZoomFactor();
void SetZoomPosition(ui::Point position);
ui::Point GetZoomPosition();
bool MouseInZoom(ui::Point position);
ui::Point AdjustZoomCoords(ui::Point position);
void SetZoomWindowPosition(ui::Point position);
ui::Point GetZoomWindowPosition();
Expand Down
18 changes: 14 additions & 4 deletions src/gui/game/GameView.cpp
Expand Up @@ -158,6 +158,7 @@ GameView::GameView():
toolIndex(0),
zoomEnabled(false),
zoomCursorFixed(false),
mouseInZoom(false),
drawPoint1(0, 0),
drawPoint2(0, 0),
drawMode(DrawPoints),
Expand Down Expand Up @@ -1040,6 +1041,7 @@ void GameView::setToolButtonOffset(int offset)

void GameView::OnMouseMove(int x, int y, int dx, int dy)
{
bool newMouseInZoom = c->MouseInZoom(ui::Point(x, y));
mousePosition = c->PointTranslate(ui::Point(x, y));
currentMouse = ui::Point(x, y);
if (selectMode != SelectNone)
Expand All @@ -1048,13 +1050,21 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
selectPoint1 = c->PointTranslate(ui::Point(x, y));
if (selectPoint1.X != -1)
selectPoint2 = c->PointTranslate(ui::Point(x, y));
return;
}
if (isMouseDown && drawMode == DrawPoints)
else if (isMouseDown)
{
pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x-dx, y-dy))));
pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x, y))));
if (newMouseInZoom == mouseInZoom)
{
if (drawMode == DrawPoints)
{
pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x-dx, y-dy))));
pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x, y))));
}
}
else if (drawMode == DrawPoints || drawMode == DrawFill)
isMouseDown = false;
}
mouseInZoom = newMouseInZoom;
}

void GameView::OnMouseDown(int x, int y, unsigned button)
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameView.h
Expand Up @@ -43,6 +43,7 @@ class GameView: public ui::Window
bool isMouseDown;
bool zoomEnabled;
bool zoomCursorFixed;
bool mouseInZoom;
bool drawSnap;
bool shiftBehaviour;
bool ctrlBehaviour;
Expand Down

0 comments on commit 1a2e3a1

Please sign in to comment.