use of net.sf.latexdraw.model.api.shape.Freehand in project latexdraw by arnobl.
the class Pencil method bindDnDToDrawFreeHandShape.
/**
* Binds a DnD interaction to create shape.
*/
private void bindDnDToDrawFreeHandShape() {
nodeBinder().usingInteraction(() -> new DnD(false, true)).toProduce(i -> {
final Shape sh = editing.createShapeInstance();
final Point pt = getAdaptedPoint(i.getSrcLocalPoint());
sh.getPoints().get(0).setPoint(pt.getX(), pt.getY());
return new AddShape(sh, canvas.getDrawing());
}).on(canvas).first((i, c) -> canvas.requestFocus()).then((i, c) -> {
final Point last = c.getShape().getPtAt(-1);
final Point endPt = getAdaptedPoint(i.getTgtLocalPoint());
if (!MathUtils.INST.equalsDouble(last.getX(), endPt.getX(), 0.0001) && !MathUtils.INST.equalsDouble(last.getY(), endPt.getY(), 0.0001)) {
c.setShape(ShapeFactory.INST.createFreeHandFrom((Freehand) c.getShape(), endPt));
}
canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
}).endOrCancel(i -> canvas.setTempView(null)).when(i -> i.getButton() == MouseButton.PRIMARY && editing.getCurrentChoice() == EditionChoice.FREE_HAND).strictStart().bind();
}
Aggregations