Search in sources :

Example 6 with CubicCurveTo

use of javafx.scene.shape.CubicCurveTo in project latexdraw by arnobl.

the class TestViewShape method duplicatePath.

protected static List<PathElement> duplicatePath(final List<PathElement> path) {
    return path.stream().map(elt -> {
        PathElement dupelt;
        if (elt instanceof MoveTo) {
            final MoveTo moveTo = (MoveTo) elt;
            dupelt = ViewFactory.INSTANCE.createMoveTo(moveTo.getX(), moveTo.getY());
        } else if (elt instanceof LineTo) {
            final LineTo lineTo = (LineTo) elt;
            dupelt = ViewFactory.INSTANCE.createLineTo(lineTo.getX(), lineTo.getY());
        } else if (elt instanceof ClosePath) {
            dupelt = ViewFactory.INSTANCE.createClosePath();
        } else if (elt instanceof CubicCurveTo) {
            final CubicCurveTo cct = (CubicCurveTo) elt;
            dupelt = ViewFactory.INSTANCE.createCubicCurveTo(cct.getControlX1(), cct.getControlY1(), cct.getControlX2(), cct.getControlY2(), cct.getX(), cct.getY());
        } else {
            throw new IllegalArgumentException();
        }
        dupelt.setAbsolute(elt.isAbsolute());
        return dupelt;
    }).collect(Collectors.toList());
}
Also used : ClosePath(javafx.scene.shape.ClosePath) CubicCurveTo(javafx.scene.shape.CubicCurveTo) LineTo(javafx.scene.shape.LineTo) PathElement(javafx.scene.shape.PathElement) Assert.assertTrue(org.junit.Assert.assertTrue) Collectors(java.util.stream.Collectors) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ISingleShape(net.sf.latexdraw.models.interfaces.shape.ISingleShape) CommandsRegistry(org.malai.command.CommandsRegistry) List(java.util.List) HelperTest(net.sf.latexdraw.HelperTest) After(org.junit.After) MoveTo(javafx.scene.shape.MoveTo) BadaboomCollector(net.sf.latexdraw.badaboom.BadaboomCollector) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) UndoCollector(org.malai.undo.UndoCollector) ClosePath(javafx.scene.shape.ClosePath) PathElement(javafx.scene.shape.PathElement) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 7 with CubicCurveTo

use of javafx.scene.shape.CubicCurveTo in project fxexperience2 by EricCanull.

the class SplineEditor method layoutPlotChildren.

@Override
protected void layoutPlotChildren() {
    double cp1x = getXAxis().getDisplayPosition(controlPoint1x.get());
    double cp1y = getYAxis().getDisplayPosition(controlPoint1y.get());
    double cp2x = getXAxis().getDisplayPosition(controlPoint2x.get());
    double cp2y = getYAxis().getDisplayPosition(controlPoint2y.get());
    double minx = getXAxis().getZeroPosition();
    double miny = getYAxis().getZeroPosition();
    double maxx = getXAxis().getDisplayPosition(1);
    double maxy = getYAxis().getDisplayPosition(1);
    controlPoint1Circle.setLayoutX(cp1x);
    controlPoint1Circle.setLayoutY(cp1y);
    controlPoint2Circle.setLayoutX(cp2x);
    controlPoint2Circle.setLayoutY(cp2y);
    cp1Line.setStartX(minx);
    cp1Line.setStartY(miny);
    cp1Line.setEndX(cp1x);
    cp1Line.setEndY(cp1y);
    cp2Line.setStartX(maxx);
    cp2Line.setStartY(maxy);
    cp2Line.setEndX(cp2x);
    cp2Line.setEndY(cp2y);
    dottedLinesPath.getElements().setAll(new MoveTo(minx - 0.5, cp1y - 0.5), new LineTo(cp1x - 0.5, cp1y - 0.5), new LineTo(cp1x - 0.5, miny - 0.5), new MoveTo(minx - 0.5, cp2y - 0.5), new LineTo(cp2x - 0.5, cp2y - 0.5), new LineTo(cp2x - 0.5, miny - 0.5));
    splinePath.getElements().setAll(new MoveTo(minx, miny), new CubicCurveTo(cp1x, cp1y, cp2x, cp2y, maxx, maxy));
}
Also used : MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 8 with CubicCurveTo

use of javafx.scene.shape.CubicCurveTo in project latexdraw by arnobl.

the class ViewArrowableTraitPath method clipPath.

@Override
protected void clipPath(final Path path) {
    final Path clip = ViewFactory.INSTANCE.clonePath(path);
    clip.setFill(path.getFill());
    clip.setStrokeWidth(path.getStrokeWidth());
    if (!clip.getElements().isEmpty()) {
        // Defensive programming
        final Optional<IPoint> pt1 = getArrowReducedPoint(arrows.get(0).arrow);
        final Optional<IPoint> pt2 = getArrowReducedPoint(arrows.get(arrows.size() - 1).arrow);
        if (pt1.isPresent() && clip.getElements().get(0) instanceof MoveTo) {
            // Defensive programming
            // Changing the first point to the one at the beginning of the arrow.
            final MoveTo moveTo = (MoveTo) clip.getElements().get(0);
            moveTo.setX(pt1.get().getX());
            moveTo.setY(pt1.get().getY());
        }
        pt2.ifPresent(pt -> {
            if (clip.getElements().get(clip.getElements().size() - 1) instanceof LineTo) {
                final LineTo lineTo = (LineTo) clip.getElements().get(clip.getElements().size() - 1);
                lineTo.setX(pt.getX());
                lineTo.setY(pt.getY());
            } else if (clip.getElements().get(clip.getElements().size() - 1) instanceof CubicCurveTo) {
                final CubicCurveTo ccTo = (CubicCurveTo) clip.getElements().get(clip.getElements().size() - 1);
                ccTo.setX(pt.getX());
                ccTo.setY(pt.getY());
            }
        });
    }
    clip.setStrokeWidth(path.getStrokeWidth());
    clip.setStrokeLineCap(path.getStrokeLineCap());
    path.setClip(clip);
}
Also used : Path(javafx.scene.shape.Path) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 9 with CubicCurveTo

use of javafx.scene.shape.CubicCurveTo in project latexdraw by arnobl.

the class ViewBezierCurve method addCurveTo.

private CubicCurveTo addCurveTo(final IPoint pt, final IPoint ctrl1, final IPoint ctrl2) {
    final CubicCurveTo curveto = ViewFactory.INSTANCE.createCubicCurveTo(0d, 0d, 0d, 0d, 0d, 0d);
    curveto.xProperty().bind(pt.xProperty());
    curveto.yProperty().bind(pt.yProperty());
    curveto.controlX1Property().bind(ctrl1.xProperty());
    curveto.controlY1Property().bind(ctrl1.yProperty());
    curveto.controlX2Property().bind(ctrl2.xProperty());
    curveto.controlY2Property().bind(ctrl2.yProperty());
    border.getElements().add(curveto);
    return curveto;
}
Also used : CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 10 with CubicCurveTo

use of javafx.scene.shape.CubicCurveTo in project Board-Instrumentation-Framework by intel.

the class SimpleGaugeSkin method resize.

private void resize() {
    size = getSkinnable().getWidth() < getSkinnable().getHeight() ? getSkinnable().getWidth() : getSkinnable().getHeight();
    if (size > 0) {
        pane.setMaxSize(size, size);
        pane.relocate((getSkinnable().getWidth() - size) * 0.5, (getSkinnable().getHeight() - size) * 0.5);
        sectionsCanvas.setWidth(size);
        sectionsCanvas.setHeight(size);
        drawSections();
        sectionsCanvas.setCache(true);
        sectionsCanvas.setCacheHint(CacheHint.QUALITY);
        measuredRangeCanvas.setWidth(size);
        measuredRangeCanvas.setHeight(size);
        drawMeasuredRange();
        double currentValue = (needleRotate.getAngle() + getSkinnable().getStartAngle() - 180) / angleStep + getSkinnable().getMinValue();
        value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", currentValue) + getSkinnable().getUnit());
        value.setVisible(getSkinnable().isValueVisible());
        title.setText(getSkinnable().getTitle());
        title.setVisible(getSkinnable().isTitleVisible());
        needle.getElements().clear();
        needle.getElements().add(new MoveTo(0.275 * size, 0.5 * size));
        needle.getElements().add(new CubicCurveTo(0.275 * size, 0.62426575 * size, 0.37573425 * size, 0.725 * size, 0.5 * size, 0.725 * size));
        needle.getElements().add(new CubicCurveTo(0.62426575 * size, 0.725 * size, 0.725 * size, 0.62426575 * size, 0.725 * size, 0.5 * size));
        needle.getElements().add(new CubicCurveTo(0.725 * size, 0.3891265 * size, 0.6448105 * size, 0.296985 * size, 0.5392625 * size, 0.2784125 * size));
        needle.getElements().add(new LineTo(0.5 * size, 0.0225 * size));
        needle.getElements().add(new LineTo(0.4607375 * size, 0.2784125 * size));
        needle.getElements().add(new CubicCurveTo(0.3551895 * size, 0.296985 * size, 0.275 * size, 0.3891265 * size, 0.275 * size, 0.5 * size));
        needle.getElements().add(new ClosePath());
        needle.setStrokeWidth(size * 0.025);
        needle.relocate(needle.getLayoutBounds().getMinX(), needle.getLayoutBounds().getMinY());
        needleRotate.setPivotX(size * 0.5);
        needleRotate.setPivotY(size * 0.5);
        resizeText();
    }
}
Also used : ClosePath(javafx.scene.shape.ClosePath) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Aggregations

CubicCurveTo (javafx.scene.shape.CubicCurveTo)14 MoveTo (javafx.scene.shape.MoveTo)13 ClosePath (javafx.scene.shape.ClosePath)9 LineTo (javafx.scene.shape.LineTo)8 Path (javafx.scene.shape.Path)4 PathElement (javafx.scene.shape.PathElement)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 QuadCurveTo (javafx.scene.shape.QuadCurveTo)2 IntStream (java.util.stream.IntStream)1 DoubleProperty (javafx.beans.property.DoubleProperty)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 Point2D (javafx.geometry.Point2D)1 Color (javafx.scene.paint.Color)1 ArcTo (javafx.scene.shape.ArcTo)1 HLineTo (javafx.scene.shape.HLineTo)1 Rectangle (javafx.scene.shape.Rectangle)1 SVGPath (javafx.scene.shape.SVGPath)1 Shape (javafx.scene.shape.Shape)1