|
|
|
|
@ -5,6 +5,60 @@ |
|
|
|
|
#include "undo/InsertUndoAction.h" |
|
|
|
|
#include <cmath> |
|
|
|
|
|
|
|
|
|
void ArrowHandler::snapToGrid(double& x, double& y) |
|
|
|
|
{ |
|
|
|
|
XOJ_CHECK_TYPE(ArrowHandler); |
|
|
|
|
|
|
|
|
|
if (!xournal->getControl()->getSettings()->isSnapGrid()) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Snap points to a grid: |
|
|
|
|
* If x/y coordinates are under a certain tolerance, |
|
|
|
|
* fix the point to the grid intersection value |
|
|
|
|
*/ |
|
|
|
|
double gridSize = 14.17; |
|
|
|
|
double tolerance = gridSize/2.0; |
|
|
|
|
|
|
|
|
|
double xRem = fmod(x,gridSize); |
|
|
|
|
double yRem = fmod(y,gridSize); |
|
|
|
|
|
|
|
|
|
bool snapX = false; |
|
|
|
|
bool snapY = false; |
|
|
|
|
|
|
|
|
|
double tmpX = 0; |
|
|
|
|
double tmpY = 0; |
|
|
|
|
|
|
|
|
|
if (xRem < tolerance) |
|
|
|
|
{ |
|
|
|
|
tmpX = x - xRem; |
|
|
|
|
snapX = true; |
|
|
|
|
} |
|
|
|
|
if (xRem > gridSize - tolerance ) |
|
|
|
|
{ |
|
|
|
|
tmpX = x + (gridSize - xRem); |
|
|
|
|
snapX = true; |
|
|
|
|
} |
|
|
|
|
if (yRem < tolerance) |
|
|
|
|
{ |
|
|
|
|
tmpY = y - yRem; |
|
|
|
|
snapY = true; |
|
|
|
|
} |
|
|
|
|
if (yRem > gridSize - tolerance ) |
|
|
|
|
{ |
|
|
|
|
tmpY = y + (gridSize - yRem); |
|
|
|
|
snapY = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (snapX && snapY) |
|
|
|
|
{ |
|
|
|
|
x = tmpX; |
|
|
|
|
y = tmpY; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ArrowHandler::ArrowHandler(XournalView* xournal, XojPageView* redrawable, PageRef page) |
|
|
|
|
: BaseStrokeHandler(xournal, redrawable, page) |
|
|
|
|
{ |
|
|
|
|
@ -22,6 +76,16 @@ void ArrowHandler::drawShape(Point& c, bool shiftDown) |
|
|
|
|
{ |
|
|
|
|
int count = stroke->getPointCount(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (count < 1) |
|
|
|
|
{ |
|
|
|
|
stroke->addPoint(c); |
|
|
|
|
@ -60,7 +124,7 @@ void ArrowHandler::drawShape(Point& c, bool shiftDown) |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
double epsilon = 0.1; |
|
|
|
|
double epsilon = 0.2; |
|
|
|
|
if (std::abs(angle) < epsilon) |
|
|
|
|
{ |
|
|
|
|
angle = 0; |
|
|
|
|
|