use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class Pencil method setInitialPtsShape.
/**
* Companion function to the bindMultiClic2AddShape binding.
* It initialises the first two points of the given shape.
*/
private Shape setInitialPtsShape(final Shape sh, final Point3D firstPt) {
if (sh instanceof ModifiablePointsShape) {
final ModifiablePointsShape modShape = (ModifiablePointsShape) sh;
final Point pt = getAdaptedPoint(firstPt);
modShape.setPoint(pt.getX(), pt.getY(), 0);
modShape.setPoint(pt.getX() + 1d, pt.getY() + 1d, 1);
}
return sh;
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class Pencil method bindMultiClic2AddShape.
/**
* Binds a multi-click interaction to creates multi-point shapes.
*/
private void bindMultiClic2AddShape() {
final Function<PointsData, AddShape> creation = i -> new AddShape(setInitialPtsShape(editing.createShapeInstance(), i.getPointsData().get(0).getSrcLocalPoint()), canvas.getDrawing());
// Binding for polygons
nodeBinder().usingInteraction(() -> new MultiClick(3)).toProduce(creation).on(canvas).then((i, c) -> {
final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createPolygonFrom((Polygon) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
}).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.POLYGON).bind();
// Binding for polyline
nodeBinder().usingInteraction(MultiClick::new).toProduce(creation).on(canvas).then((i, c) -> {
final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createPolylineFrom((Polyline) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
}).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.LINES).bind();
// Binding for bézier curves
nodeBinder().usingInteraction(MultiClick::new).toProduce(creation).on(canvas).then((i, c) -> {
final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createBezierCurveFrom((BezierCurve) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
((ControlPointShape) c.getShape()).balance();
canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
}).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.BEZIER_CURVE).bind();
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class CtrlPointShapeBase method setPoint.
@Override
public boolean setPoint(final double x, final double y, final int position) {
final Point pt = getPtAt(position);
if (pt == null || !MathUtils.INST.isValidPt(x, y)) {
return false;
}
final double tx = x - pt.getX();
final double ty = y - pt.getY();
getFirstCtrlPtAt(position).translate(tx, ty);
getSecondCtrlPtAt(position).translate(tx, ty);
super.setPoint(x, y, position);
return true;
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class CtrlPointShapeBase method balance.
@Override
public void balance() {
final int size = getNbPoints();
// Works only with more than 2 points.
if (size < 3) {
return;
}
Point ptPrev;
Point ptNext;
// Balancing all the points except the first and the last one.
for (int i = 1; i < size - 1; i++) {
ptPrev = points.get(i - 1);
ptNext = points.get(i + 1);
setControlPoints(i, getBalancedPoints(points.get(i), ptPrev, ptNext));
}
// Balancing the first and the last points.
ptPrev = points.get(size - 1);
ptNext = points.get(1);
setControlPoints(0, getBalancedPoints(points.get(0), ptPrev, ptNext));
ptPrev = points.get(size - 2);
ptNext = points.get(0);
setControlPoints(size - 1, getBalancedPoints(points.get(size - 1), ptPrev, ptNext));
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class RectangularShapeBase method mirrorHorizontal.
@Override
public void mirrorHorizontal(final double x) {
super.mirrorHorizontal(x);
if (getWidth() < 0d) {
final Point tmp = ShapeFactory.INST.createPoint(points.get(0));
points.get(0).setPoint(points.get(1));
points.get(1).setPoint(tmp);
tmp.setPoint(points.get(2));
points.get(2).setPoint(points.get(3));
points.get(3).setPoint(tmp);
}
}
Aggregations