use of net.sf.latexdraw.models.interfaces.shape.ISquaredShape in project latexdraw by arnobl.
the class Pencil method bindDnDToDrawSquaredShape.
/**
* Binds a DnD interaction to draw squared shapes.
*/
private void bindDnDToDrawSquaredShape() {
nodeBinder(AddShape.class, new DnD(false, true)).on(canvas).map(i -> {
final ISquaredShape sq = (ISquaredShape) createShapeInstance();
final IPoint pt = getAdaptedPoint(i.getSrcLocalPoint());
sq.setPosition(pt.getX() - 1d, pt.getY() - 1d);
sq.setWidth(2d);
return new AddShape(sq, canvas.getDrawing());
}).first((c, i) -> {
Platform.runLater(() -> canvas.requestFocus());
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).then((c, i) -> updateShapeFromCentre((ISquaredShape) c.getShape().get(), getAdaptedPoint(i.getSrcLocalPoint()), getAdaptedPoint(i.getEndLocalPt()).getX())).endOrCancel((c, i) -> canvas.setTempView(null)).when(i -> i.getButton() == MouseButton.PRIMARY).strictStart().bind().activationProperty().bind(activatedProp.and(currentChoice.isEqualTo(EditionChoice.SQUARE).or(currentChoice.isEqualTo(EditionChoice.CIRCLE).or(currentChoice.isEqualTo(EditionChoice.CIRCLE_ARC)))));
}
Aggregations