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

This commit is contained in:
jacob1 2015-01-10 13:35:23 -05:00
parent c325543402
commit 1a2e3a11fc
6 changed files with 45 additions and 4 deletions

View File

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

View File

@ -141,6 +141,7 @@ public:
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);

View File

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

View File

@ -181,6 +181,7 @@ public:
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();

View File

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

View File

@ -43,6 +43,7 @@ private:
bool isMouseDown;
bool zoomEnabled;
bool zoomCursorFixed;
bool mouseInZoom;
bool drawSnap;
bool shiftBehaviour;
bool ctrlBehaviour;