diff --git a/src/control/tools/BaseStrokeHandler.cpp b/src/control/tools/BaseStrokeHandler.cpp index a040e6a7..e7e0ba56 100644 --- a/src/control/tools/BaseStrokeHandler.cpp +++ b/src/control/tools/BaseStrokeHandler.cpp @@ -27,10 +27,11 @@ void BaseStrokeHandler::snapToGrid(double& x, double& y) * fix the point to the grid intersection value */ double gridSize = 14.17; + double t = xournal->getControl()->getSettings()->getSnapGridTolerance(); double tolerance = (gridSize/2) - (1/t); - - double xRem = fmod(x,gridSize); + + double xRem = fmod(x,gridSize); double yRem = fmod(y,gridSize); bool snapX = false; diff --git a/src/control/tools/CircleHandler.cpp b/src/control/tools/CircleHandler.cpp index 73baeb8a..edb26879 100644 --- a/src/control/tools/CircleHandler.cpp +++ b/src/control/tools/CircleHandler.cpp @@ -20,6 +20,16 @@ CircleHandler::~CircleHandler() void CircleHandler::drawShape(Point& c, bool shiftDown) { + /** + * Snap first point to grid (if enabled) + */ + if (!shiftDown && xournal->getControl()->getSettings()->isSnapGrid()) + { + Point firstPoint = stroke->getPoint(0); + snapToGrid(firstPoint.x,firstPoint.y); + stroke->setFirstPoint(firstPoint.x,firstPoint.y); + } + int count = stroke->getPointCount(); if (count < 2) @@ -29,6 +39,10 @@ void CircleHandler::drawShape(Point& c, bool shiftDown) else { Point p = stroke->getPoint(0); + if (xournal->getControl()->getSettings()->isSnapGrid()) + { + snapToGrid(c.x,c.y); + } // set resolution proportional to radius double diameter = sqrt(pow(c.x - p.x, 2.0) + pow(c.y - p.y, 2.0)); int npts = (int) (diameter * 2.0); diff --git a/src/control/tools/CoordinateSystemHandler.cpp b/src/control/tools/CoordinateSystemHandler.cpp index 0c0d1815..ff689b10 100644 --- a/src/control/tools/CoordinateSystemHandler.cpp +++ b/src/control/tools/CoordinateSystemHandler.cpp @@ -27,6 +27,15 @@ CoordinateSystemHandler::~CoordinateSystemHandler() */ void CoordinateSystemHandler::drawShape(Point& currentPoint, bool shiftDown) { + /** + * Snap first point to grid (if enabled) + */ + if (!shiftDown && xournal->getControl()->getSettings()->isSnapGrid()) + { + Point firstPoint = stroke->getPoint(0); + snapToGrid(firstPoint.x,firstPoint.y); + stroke->setFirstPoint(firstPoint.x,firstPoint.y); + } int count = stroke->getPointCount(); if (count < 1) @@ -45,7 +54,11 @@ void CoordinateSystemHandler::drawShape(Point& currentPoint, bool shiftDown) stroke->deletePoint(2); stroke->deletePoint(1); } - + if (xournal->getControl()->getSettings()->isSnapGrid()) + { + snapToGrid(startingPoint.x,startingPoint.y); + snapToGrid(currentPoint.x,currentPoint.y); + } // Draw the other two points if (shiftDown || !xournal->getControl()->getSettings()->isSnapRotation()) { diff --git a/src/control/tools/RectangleHandler.cpp b/src/control/tools/RectangleHandler.cpp index 502a82c2..da3af4f8 100644 --- a/src/control/tools/RectangleHandler.cpp +++ b/src/control/tools/RectangleHandler.cpp @@ -77,7 +77,7 @@ void RectangleHandler::drawShape(Point& c, bool shiftDown) { snapToGrid(c.x,c.y); } - stroke->addPoint(Point(p.x, c.y)); // was p.y + stroke->addPoint(Point(p.x, c.y)); stroke->addPoint(c); stroke->addPoint(Point(c.x, p.y)); stroke->addPoint(p);