Permalink
Browse files

cancel drawing when the mouse moves in / out of the zoom window, fixes

  • Loading branch information...
jacob1 committed Jan 10, 2015
1 parent c325543 commit 1a2e3a11fcbf880e479806d188bf2b265451d91d
@@ -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)
@@ -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);
@@ -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())
@@ -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();
@@ -158,6 +158,7 @@ GameView::GameView():
toolIndex(0),
zoomEnabled(false),
zoomCursorFixed(false),
mouseInZoom(false),
drawPoint1(0, 0),
drawPoint2(0, 0),
drawMode(DrawPoints),
@@ -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)
@@ -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)
@@ -43,6 +43,7 @@ class GameView: public ui::Window
bool isMouseDown;
bool zoomEnabled;
bool zoomCursorFixed;
bool mouseInZoom;
bool drawSnap;
bool shiftBehaviour;
bool ctrlBehaviour;

0 comments on commit 1a2e3a1

Please sign in to comment.