Search in sources :

Example 1 with Point2D

use of javafx.geometry.Point2D in project JFoenix by jfoenixadmin.

the class JFXSliderSkinOLD method initializeMouseEvents.

private void initializeMouseEvents() {
    getSkinnable().setOnMousePressed(me -> {
        if (!thumb.isPressed()) {
            trackClicked = true;
            if (isHorizontal) {
                getBehavior().trackPress(me, (me.getX() / trackLength));
            } else {
                getBehavior().trackPress(me, (me.getY() / trackLength));
            }
            trackClicked = false;
        }
        timeline.setRate(1);
        timeline.play();
    });
    getSkinnable().setOnMouseReleased(me -> {
        timeline.setRate(-1);
        timeline.play();
    });
    getSkinnable().setOnMouseDragged(me -> {
        if (!thumb.isPressed()) {
            if (isHorizontal) {
                getBehavior().trackPress(me, (me.getX() / trackLength));
            } else {
                getBehavior().trackPress(me, (me.getY() / trackLength));
            }
        }
    });
    thumb.setOnMousePressed(me -> {
        getBehavior().thumbPressed(me, 0.0f);
        dragStart = thumb.localToParent(me.getX(), me.getY());
        preDragThumbPos = (getSkinnable().getValue() - getSkinnable().getMin()) / (getSkinnable().getMax() - getSkinnable().getMin());
    });
    thumb.setOnMouseReleased(me -> {
        getBehavior().thumbReleased(me);
    });
    thumb.setOnMouseDragged(me -> {
        Point2D cur = thumb.localToParent(me.getX(), me.getY());
        double dragPos = (isHorizontal) ? cur.getX() - dragStart.getX() : -(cur.getY() - dragStart.getY());
        getBehavior().thumbDragged(me, preDragThumbPos + dragPos / trackLength);
    });
    thumb.layoutXProperty().addListener((o, oldVal, newVal) -> {
        if (isHorizontal) {
            animatedThumb.setLayoutX(newVal.doubleValue() - 2 * thumbRadius - 1);
            long value = Math.round(getSkinnable().getValue());
            sliderValue.setText("" + value);
            if (coloredTrack.getStartX() < newVal.doubleValue()) {
                coloredTrack.setEndX(newVal.doubleValue());
            } else {
                coloredTrack.setEndX(coloredTrack.getStartX());
            }
            internalChange = true;
            if (value == 0) {
                thumb.setFill(trackColor);
                thumb.setStroke(trackColor);
                coloredTrack.setVisible(false);
            } else {
                thumb.setFill(thumbColor);
                thumb.setStroke(thumbColor);
                coloredTrack.setVisible(true);
            }
            internalChange = false;
        }
    });
    thumb.layoutYProperty().addListener((o, oldVal, newVal) -> {
        if (!isHorizontal) {
            animatedThumb.setLayoutY(newVal.doubleValue() - 2 * thumbRadius - 1);
            long value = Math.round(getSkinnable().getValue());
            sliderValue.setText("" + value);
            if (coloredTrack.getStartY() > newVal.doubleValue()) {
                coloredTrack.setEndY(newVal.doubleValue() + thumbRadius);
            } else {
                coloredTrack.setEndY(coloredTrack.getStartY());
            }
            internalChange = true;
            if (value == 0) {
                thumb.setFill(trackColor);
                thumb.setStroke(trackColor);
                coloredTrack.setVisible(false);
            } else {
                thumb.setFill(thumbColor);
                thumb.setStroke(thumbColor);
                coloredTrack.setVisible(true);
            }
            internalChange = false;
        }
    });
}
Also used : Point2D(javafx.geometry.Point2D)

Example 2 with Point2D

use of javafx.geometry.Point2D in project JFoenix by jfoenixadmin.

the class JFXColorPickerUI method getColor.

private Color getColor(double dx, double dy) {
    double distance = Math.sqrt((dx * dx) + (dy * dy));
    double rverysmall = 0.65 * ((double) pickerSize / 2);
    Color pixelColor = Color.BLUE;
    if (distance <= rverysmall * 1.1) {
        double angle = -Math.PI / 2.;
        double angle1 = angle + 2 * Math.PI / 3.;
        double angle2 = angle1 + 2 * Math.PI / 3.;
        double x1 = rverysmall * Math.sin(angle1);
        double y1 = rverysmall * Math.cos(angle1);
        double x2 = rverysmall * Math.sin(angle2);
        double y2 = rverysmall * Math.cos(angle2);
        dx += 0.01;
        double[] circle = circleFrom3Points(new Point2D(x1, y1), new Point2D(x2, y2), new Point2D(dx, dy));
        double xArc = circle[0];
        double yArc = 0;
        double arcR = circle[2];
        double Arco = Math.atan2(dx - xArc, dy - yArc);
        double Arco1 = Math.atan2(x1 - xArc, y1 - yArc);
        double Arco2 = Math.atan2(x2 - xArc, y2 - yArc);
        double finalX = xArc > 0 ? xArc - arcR : xArc + arcR;
        double saturation = map(finalX, -rverysmall, rverysmall, 255, 0);
        double lightness = 255;
        double diffAngle = Arco2 - Arco1;
        double diffArco = Arco - Arco1;
        if (dx < x1) {
            diffAngle = diffAngle < 0 ? 2 * Math.PI + diffAngle : diffAngle;
            diffAngle = Math.abs(2 * Math.PI - diffAngle);
            diffArco = diffArco < 0 ? 2 * Math.PI + diffArco : diffArco;
            diffArco = Math.abs(2 * Math.PI - diffArco);
        }
        lightness = map(diffArco, 0, diffAngle, 0, 255);
        if (distance > rverysmall) {
            saturation = 255 - saturation;
            if (lightness < 0 && dy < 0) {
                lightness = 255;
            }
        }
        lightness = clamp(lightness, 0, 255);
        if ((saturation < 10 && dx < x1) || (saturation > 240 && dx > x1)) {
            saturation = 255 - saturation;
        }
        saturation = clamp(saturation, 0, 255);
        pixelColor = HSL2RGB(currentHue, saturation, lightness);
    }
    return pixelColor;
}
Also used : Point2D(javafx.geometry.Point2D) Color(javafx.scene.paint.Color)

Example 3 with Point2D

use of javafx.geometry.Point2D in project JFoenix by jfoenixadmin.

the class JFXColorPickerUI method getPointFromSL.

private Point2D getPointFromSL(int saturation, int lightness, double radius) {
    double dy = map(saturation, 0, 255, -radius, radius);
    double angle = 0.;
    double angle1 = angle + 2 * Math.PI / 3.;
    double angle2 = angle1 + 2 * Math.PI / 3.;
    double x1 = radius * Math.sin(angle1);
    double y1 = radius * Math.cos(angle1);
    double x2 = radius * Math.sin(angle2);
    double y2 = radius * Math.cos(angle2);
    double dx = 0;
    double[] circle = circleFrom3Points(new Point2D(x1, y1), new Point2D(dx, dy), new Point2D(x2, y2));
    double xArc = circle[0];
    double yArc = circle[1];
    double arcR = circle[2];
    double Arco1 = Math.atan2(x1 - xArc, y1 - yArc);
    double Arco2 = Math.atan2(x2 - xArc, y2 - yArc);
    double ArcoFinal = map(lightness, 0, 255, Arco2, Arco1);
    double finalX = xArc + arcR * Math.sin(ArcoFinal);
    double finalY = yArc + arcR * Math.cos(ArcoFinal);
    if (dy < y1) {
        ArcoFinal = map(lightness, 0, 255, Arco1, Arco2 + 2 * Math.PI);
        finalX = -xArc - arcR * Math.sin(ArcoFinal);
        finalY = yArc + arcR * Math.cos(ArcoFinal);
    }
    return new Point2D(finalX, finalY);
}
Also used : Point2D(javafx.geometry.Point2D)

Example 4 with Point2D

use of javafx.geometry.Point2D in project fxexperience2 by EricCanull.

the class ColorPickerPopover method show.

public void show(Control ownerControl) {
    Point2D point = ownerControl.localToScene(ownerControl.getWidth() / 2, ownerControl.getHeight());
    double x = point.getX() + ownerControl.getScene().getX() + ownerControl.getScene().getWindow().getX();
    double y = point.getY() + ownerControl.getScene().getY() + ownerControl.getScene().getWindow().getY();
    popup.show(ownerControl, x - getPopoverPointX(), y - getPopoverPointY());
}
Also used : Point2D(javafx.geometry.Point2D)

Example 5 with Point2D

use of javafx.geometry.Point2D in project FXyzLib by Birdasaur.

the class SurfacePlotMesh method createPlotMesh.

private TriangleMesh createPlotMesh(Function<Point2D, Number> function2D, double rangeX, double rangeY, int divisionsX, int divisionsY, double scale) {
    listVertices.clear();
    listTextures.clear();
    listFaces.clear();
    int numDivX = divisionsX + 1;
    float pointY;
    areaMesh.setWidth(rangeX);
    areaMesh.setHeight(rangeY);
    // Create points
    for (int y = 0; y <= divisionsY; y++) {
        float dy = (float) (-rangeY / 2d + ((float) y / (float) divisionsY) * rangeY);
        for (int x = 0; x <= divisionsX; x++) {
            float dx = (float) (-rangeX / 2d + ((float) x / (float) divisionsX) * rangeX);
            pointY = (float) scale * function2D.apply(new Point2D(dx, dy)).floatValue();
            listVertices.add(new Point3D(dx, pointY, dy));
        }
    }
    // Create texture coordinates
    createTexCoords(divisionsX, divisionsY);
    // Create textures indices
    for (int y = 0; y < divisionsY; y++) {
        for (int x = 0; x < divisionsX; x++) {
            int p00 = y * numDivX + x;
            int p01 = p00 + 1;
            int p10 = p00 + numDivX;
            int p11 = p10 + 1;
            listTextures.add(new Face3(p00, p10, p11));
            listTextures.add(new Face3(p11, p01, p00));
        }
    }
    // Create faces indices
    for (int y = 0; y < divisionsY; y++) {
        for (int x = 0; x < divisionsX; x++) {
            int p00 = y * numDivX + x;
            int p01 = p00 + 1;
            int p10 = p00 + numDivX;
            int p11 = p10 + 1;
            listFaces.add(new Face3(p00, p10, p11));
            listFaces.add(new Face3(p11, p01, p00));
        }
    }
    return createMesh();
}
Also used : Point2D(javafx.geometry.Point2D) Point3D(org.fxyz.geometry.Point3D) Face3(org.fxyz.geometry.Face3)

Aggregations

Point2D (javafx.geometry.Point2D)29 Point3D (org.fxyz.geometry.Point3D)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Collectors (java.util.stream.Collectors)7 IntStream (java.util.stream.IntStream)7 TriangleMesh (javafx.scene.shape.TriangleMesh)7 Face3 (org.fxyz.geometry.Face3)7 HashMap (java.util.HashMap)6 DoubleStream (java.util.stream.DoubleStream)6 IntegerProperty (javafx.beans.property.IntegerProperty)6 ObjectProperty (javafx.beans.property.ObjectProperty)6 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)6 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)6 DepthTest (javafx.scene.DepthTest)6 CullFace (javafx.scene.shape.CullFace)6 DrawMode (javafx.scene.shape.DrawMode)6 FloatCollector (org.fxyz.utils.FloatCollector)6 DoubleProperty (javafx.beans.property.DoubleProperty)5 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)5