use of io.github.interacto.jfx.interaction.library.DnD in project latexdraw by arnobl.
the class TemplateManager method configureBindings.
@Override
protected void configureBindings() {
buttonBinder().toProduce(() -> new UpdateTemplates(templatePane, svgGen, true)).on(updateTemplates).bind();
nodeBinder().usingInteraction(DnD::new).toProduce(i -> new LoadTemplate(svgGen, drawing, new File((String) i.getSrcObject().orElseThrow().getUserData()), statusController.getProgressBar(), statusController.getLabel(), app)).on(templatePane).first(c -> templatePane.setCursor(Cursor.CLOSED_HAND)).then((i, c) -> {
final Node srcObj = i.getSrcObject().orElseThrow();
final Point3D pt3d = i.getTgtObject().orElseThrow().sceneToLocal(srcObj.localToScene(i.getTgtLocalPoint())).subtract(Canvas.ORIGIN.getX() + srcObj.getLayoutX(), Canvas.ORIGIN.getY() + srcObj.getLayoutY(), 0d);
c.setPosition(ShapeFactory.INST.createPoint(pt3d));
}).when(i -> i.getSrcObject().orElse(null) instanceof ImageView && i.getSrcObject().get().getUserData() instanceof String && i.getTgtObject().orElse(null) instanceof Canvas).endOrCancel(i -> templatePane.setCursor(Cursor.MOVE)).bind();
}
use of io.github.interacto.jfx.interaction.library.DnD in project latexdraw by arnobl.
the class CanvasController method configureBindings.
@Override
protected void configureBindings() {
nodeBinder().usingInteraction(DnD::new).toProduce(MoveCamera::new).on(canvas).first(c -> {
c.setScrollPane(canvas.getScrollPane());
canvas.setCursor(Cursor.MOVE);
}).then((i, c) -> {
final ScrollPane pane = canvas.getScrollPane();
c.setPx(pane.getHvalue() - (i.getTgtLocalPoint().getX() - i.getSrcLocalPoint().getX()) / canvas.getWidth());
c.setPy(pane.getVvalue() - (i.getTgtLocalPoint().getY() - i.getSrcLocalPoint().getY()) / canvas.getHeight());
}).when(i -> i.getButton() == MouseButton.MIDDLE).endOrCancel(i -> canvas.setCursor(Cursor.DEFAULT)).continuousExecution().bind();
nodeBinder().toProduce(() -> new ChangeCursor(Cursor.HAND, canvas)).usingInteraction(MouseEntered::new).on(canvas.getSelectionBorder()).bind();
nodeBinder().toProduce(() -> new ChangeCursor(Cursor.DEFAULT, canvas)).usingInteraction(MouseExited::new).on(canvas.getSelectionBorder()).bind();
}
use of io.github.interacto.jfx.interaction.library.DnD 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