javafx.scene.shape.Polygon Java Examples

The following examples show how to use javafx.scene.shape.Polygon. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TranslateSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (0, 0, 20, 20);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(29);
    polygon.setLayoutY(21);
    polygon.setRotate(135);
    

    Rectangle r2 = new Rectangle (50, 50, 20, 20);
    r2.setArcHeight(4);
    r2.setArcWidth(4);
    r2.setFill(Color.web("#ed4b00"));
    r2.setOpacity(0.5);
    javafx.scene.Group g = new javafx.scene.Group(r2,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example #2
Source File: PolygonLayoutBoundsBug.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	final Polygon p = new Polygon(10, 30, 20, 20, 20, 40);
	p.setFill(Color.RED);
	p.setStroke(Color.BLACK);

	final Rectangle r = new Rectangle();
	r.setFill(new Color(0, 0, 1, 0.5));
	r.setX(p.getLayoutBounds().getMinX());
	r.setY(p.getLayoutBounds().getMinY());
	r.setWidth(p.getLayoutBounds().getWidth());
	r.setHeight(p.getLayoutBounds().getHeight());

	Group g = new Group(r, p);
	g.getTransforms().add(new Scale(10, 10));
	Scene scene = new Scene(g, 500, 500);
	primaryStage.setScene(scene);
	primaryStage.sizeToScene();
	primaryStage.show();
}
 
Example #3
Source File: PolygonSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    Polygon polygon = new Polygon(new double[]{
        45 , 10 ,
        10 , 80 ,
        80 , 80 ,
    });
    polygon.setStroke(Color.web("#b9c0c5"));
    polygon.setStrokeWidth(5);
    polygon.getStrokeDashArray().addAll(15d,15d);
    polygon.setFill(null);
    javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
    effect.setOffsetX(1);
    effect.setOffsetY(1);
    effect.setRadius(3);
    effect.setColor(Color.rgb(0,0,0,0.6));
    polygon.setEffect(effect);
    return polygon;
}
 
Example #4
Source File: TranslateSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (0, 0, 20, 20);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(29);
    polygon.setLayoutY(21);
    polygon.setRotate(135);
    

    Rectangle r2 = new Rectangle (50, 50, 20, 20);
    r2.setArcHeight(4);
    r2.setArcWidth(4);
    r2.setFill(Color.web("#ed4b00"));
    r2.setOpacity(0.5);
    javafx.scene.Group g = new javafx.scene.Group(r2,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example #5
Source File: Helper.java    From OEE-Designer with MIT License 6 votes vote down vote up
public static final boolean isInPolygon(final double X, final double Y, final Polygon POLYGON) {
	List<Double> points = POLYGON.getPoints();
	int noOfPointsInPolygon = POLYGON.getPoints().size() / 2;
	double[] pointsX = new double[noOfPointsInPolygon];
	double[] pointsY = new double[noOfPointsInPolygon];
	int pointCounter = 0;
	for (int i = 0; i < points.size(); i++) {
		if (i % 2 == 0) {
			pointsX[i] = points.get(pointCounter);
		} else {
			pointsY[i] = points.get(pointCounter);
			pointCounter++;
		}
	}
	return isInPolygon(X, Y, noOfPointsInPolygon, pointsX, pointsY);
}
 
Example #6
Source File: ScaleSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (50, 50, 14, 14);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(68);
    polygon.setLayoutY(25);
    polygon.setRotate(45);

    Rectangle r3 = new Rectangle (25, 25, 64, 64);
    r3.setArcHeight(15);
    r3.setArcWidth(15);
    r3.setFill(Color.web("#f49b00"));
    javafx.scene.Group g = new javafx.scene.Group(r3,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example #7
Source File: TriangleCell.java    From fxgraph with Do What The F*ck You Want To Public License 6 votes vote down vote up
@Override
public Region getGraphic(Graph graph) {
	final double width = 50;
	final double height = 50;

	final Polygon view = new Polygon(width / 2, 0, width, height, 0, height);

	view.setStroke(Color.RED);
	view.setFill(Color.RED);

	final Pane pane = new Pane(view);
	pane.setPrefSize(50, 50);
	final Scale scale = new Scale(1, 1);
	view.getTransforms().add(scale);
	scale.xProperty().bind(pane.widthProperty().divide(50));
	scale.yProperty().bind(pane.heightProperty().divide(50));
	CellGestures.makeResizable(pane);

	return pane;
}
 
Example #8
Source File: Pin.java    From BlockMap with MIT License 6 votes vote down vote up
@Override
protected Node initBottomGui() {
	Polygon shape = new Polygon();
	shape.getPoints().setAll(chunkPositions.stream().flatMap(v -> Stream.of(v.x(), v.y())).map(d -> (d + 1) * 16.0).collect(Collectors.toList()));
	shape.setFill(new ImagePattern(image, 0, 0, 16, 16, false));
	getTopGui().hoverProperty().addListener(e -> {
		if (getTopGui().isHover())
			shape.setOpacity(0.6);
		else
			shape.setOpacity(0.2);
	});
	shape.setOpacity(0.2);
	shape.setMouseTransparent(true);
	shape.setCache(true);
	shape.setCacheHint(CacheHint.SCALE);
	shape.setViewOrder(1);
	return shape;
}
 
Example #9
Source File: Helper.java    From charts with Apache License 2.0 6 votes vote down vote up
public static final boolean isInPolygon(final double X, final double Y, final Polygon POLYGON) {
    List<Double> points              = POLYGON.getPoints();
    int          noOfPointsInPolygon = POLYGON.getPoints().size() / 2;
    double[]     pointsX             = new double[noOfPointsInPolygon];
    double[]     pointsY             = new double[noOfPointsInPolygon];
    int          pointCounter        = 0;
    for (int i = 0 ; i < points.size() ; i++) {
        if (i % 2 == 0) {
            pointsX[i] = points.get(pointCounter);
        } else {
            pointsY[i] = points.get(pointCounter);
            pointCounter++;
        }
    }
    return isInPolygon(X, Y, noOfPointsInPolygon, pointsX, pointsY);
}
 
Example #10
Source File: RotateSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (0, 0, 64, 64);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(65);
    polygon.setLayoutY(5);
    polygon.setRotate(165);
    

    Rectangle r2 = new Rectangle (0, 0, 64, 64);
    r2.setArcHeight(15);
    r2.setArcWidth(15);
    r2.setFill(Color.web("#ed4b00"));
    r2.setRotate(60);
    r2.setOpacity(0.5);
    javafx.scene.Group g = new javafx.scene.Group(r2,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example #11
Source File: ShearSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (22, 0, 64, 64);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00",0.5));
    r1.getTransforms().add(new Shear(-0.35, 0));

    Polygon polygon = createArrow();
    polygon.setLayoutX(-5);
    polygon.setLayoutY(-2);
    polygon.setRotate(90);
    

    Rectangle r2 = new Rectangle (0, 0, 64, 64);
    r2.setArcHeight(4);
    r2.setArcWidth(4);
    r2.setFill(Color.web("#ed4b00", 0.25));
    javafx.scene.Group g = new javafx.scene.Group(r2,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example #12
Source File: Exercise_18_36.java    From Intro-to-Java-Programming with MIT License 6 votes vote down vote up
private void displayTriangles(int order, Point2D p1,
		Point2D p2, Point2D p3) {
	if (order == 0) {
		// Draw a triangle to connect three points
		Polygon triangle = new Polygon();
		triangle.getPoints().addAll(p1.getX(), p1.getY(), p2.getX(),
			p2.getY(), p3.getX(), p3.getY());
		triangle.setStroke(Color.BLACK);
		triangle.setFill(Color.BLACK);

		this.getChildren().add(triangle);
	}
	else {
		//Get the midpoint on each edge in the triangle
		Point2D p12= p1.midpoint(p2);
		Point2D p23= p2.midpoint(p3);
		Point2D p31= p3.midpoint(p1);

		// Recursively display three triangles
		displayTriangles(order - 1, p1, p12, p31);
		displayTriangles(order - 1, p12, p2, p23);
		displayTriangles(order - 1, p31, p23, p3);
	}
}
 
Example #13
Source File: RotateSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (0, 0, 64, 64);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(65);
    polygon.setLayoutY(5);
    polygon.setRotate(165);
    

    Rectangle r2 = new Rectangle (0, 0, 64, 64);
    r2.setArcHeight(15);
    r2.setArcWidth(15);
    r2.setFill(Color.web("#ed4b00"));
    r2.setRotate(60);
    r2.setOpacity(0.5);
    javafx.scene.Group g = new javafx.scene.Group(r2,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example #14
Source File: Exercise_18_19.java    From Intro-to-Java-Programming with MIT License 6 votes vote down vote up
private void displayTriangles(int order, Point2D p1,
		Point2D p2, Point2D p3) {
	if (order == 0) {
		// Draw a triangle to connect three points
		Polygon triangle = new Polygon();
		triangle.getPoints().addAll(p1.getX(), p1.getY(), p2.getX(),
			p2.getY(), p3.getX(), p3.getY());
		triangle.setStroke(Color.BLACK);
		triangle.setFill(Color.WHITE);

		this.getChildren().add(triangle);
	}
	else {
		//Get the midpoint on each edge in the triangle
		Point2D p12= p1.midpoint(p2);
		Point2D p23= p2.midpoint(p3);
		Point2D p31= p3.midpoint(p1);

		// Recursively display three triangles
		displayTriangles(order - 1, p1, p12, p31);
		displayTriangles(order - 1, p12, p2, p23);
		displayTriangles(order - 1, p31, p23, p3);
	}
}
 
Example #15
Source File: CreationMenuOnClickHandler.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private Node createArrow(final boolean left) {
	// shape
	final Polygon arrow = new Polygon();
	arrow.getPoints().addAll(left ? LEFT_ARROW_POINTS : RIGHT_ARROW_POINTS);
	// style
	arrow.setStrokeWidth(ARROW_STROKE_WIDTH);
	arrow.setStroke(ARROW_STROKE);
	arrow.setFill(ARROW_FILL);
	// effect
	effectOnHover(arrow, new DropShadow(DROP_SHADOW_RADIUS, getHighlightColor()));
	// action
	arrow.setOnMouseClicked(new EventHandler<MouseEvent>() {
		@Override
		public void handle(MouseEvent event) {
			traverse(left);
		}
	});
	return arrow;
}
 
Example #16
Source File: ScaleSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (50, 50, 14, 14);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(68);
    polygon.setLayoutY(25);
    polygon.setRotate(45);

    Rectangle r3 = new Rectangle (25, 25, 64, 64);
    r3.setArcHeight(15);
    r3.setArcWidth(15);
    r3.setFill(Color.web("#f49b00"));
    javafx.scene.Group g = new javafx.scene.Group(r3,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example #17
Source File: PolygonSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    Polygon polygon = new Polygon(new double[]{
        45 , 10 ,
        10 , 80 ,
        80 , 80 ,
    });
    polygon.setStroke(Color.web("#b9c0c5"));
    polygon.setStrokeWidth(5);
    polygon.getStrokeDashArray().addAll(15d,15d);
    polygon.setFill(null);
    javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
    effect.setOffsetX(1);
    effect.setOffsetY(1);
    effect.setRadius(3);
    effect.setColor(Color.rgb(0,0,0,0.6));
    polygon.setEffect(effect);
    return polygon;
}
 
Example #18
Source File: ShearSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (22, 0, 64, 64);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00",0.5));
    r1.getTransforms().add(new Shear(-0.35, 0));

    Polygon polygon = createArrow();
    polygon.setLayoutX(-5);
    polygon.setLayoutY(-2);
    polygon.setRotate(90);
    

    Rectangle r2 = new Rectangle (0, 0, 64, 64);
    r2.setArcHeight(4);
    r2.setArcWidth(4);
    r2.setFill(Color.web("#ed4b00", 0.25));
    javafx.scene.Group g = new javafx.scene.Group(r2,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example #19
Source File: PointingHeroIcon.java    From clarity-analyzer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public PointingHeroIcon(ObservableEntity oe) {
    super(oe);

    shape = new Polygon(
        0, -200, -120, 200, 120, 200
    );

    shape.fillProperty().bind(getPlayerColor());

    ObjectBinding<Vector> angRotVector = oe.getPropertyBinding(Vector.class, "CBodyComponent.m_angRotation", null);
    DoubleBinding angRot = Bindings.createDoubleBinding(() -> (double) angRotVector.get().getElement(1), angRotVector);

    IntegerBinding angDiff = Bindings.selectInteger(oe.getPropertyBinding(Integer.class, "m_anglediff", 0));

    shape.translateXProperty().bind(getMapX());
    shape.translateYProperty().bind(getMapY());
    shape.rotateProperty().bind(getBaseAngle().add(angRot).add(angDiff));
}
 
Example #20
Source File: JFXTreeViewPath.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private JFXButton createLastButton(TreeItem temp, TreeItem parent) {
    return new JFXButton(temp.getValue().toString()) {
        private boolean noParent = parent == null;
        {
            setPadding(new Insets(getOffset(), getOffset(), getOffset(), (noParent? 1 : 2) * getOffset()));
            setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
        }

        @Override
        protected void layoutChildren() {
            super.layoutChildren();
            double width = getWidth();
            Polygon polygon = new Polygon();
            final double height = getHeight();
            polygon.getPoints().addAll(new Double[] {
                0.0, 0.0,
                width, 0.0,
                width, height,
                0.0, height,
                noParent ? 0 : getOffset(), noParent ? 0 : height / 2});
            setClip(polygon);
        }
    };
}
 
Example #21
Source File: JFXTreeViewPath.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
public JFXButton createFirstButton(TreeItem temp) {
    return new JFXButton(temp.getValue().toString()) {
        {
            setPadding(new Insets(getOffset(), 1.5 * getOffset(), getOffset(), getOffset()));
            setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
        }

        @Override
        protected void layoutChildren() {
            super.layoutChildren();
            double width = getWidth();
            Polygon polygon = new Polygon();
            final double height = getHeight();
            polygon.getPoints().addAll(new Double[] {
                0.0, 0.0,
                width - getOffset(), 0.0,
                width, height / 2,
                width - getOffset(), height,
                0.0, height});
            setClip(polygon);
        }
    };
}
 
Example #22
Source File: JFXTreeViewPath.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private JFXButton createNextButton(TreeItem temp) {
    return new JFXButton(temp.getValue().toString()) {
        {
            setPadding(new Insets(getOffset(), 1.5 * getOffset(), getOffset(), 2 * getOffset()));
            setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
        }

        @Override
        protected void layoutChildren() {
            super.layoutChildren();
            double width = getWidth();
            Polygon polygon = new Polygon();
            final double height = getHeight();
            polygon.getPoints().addAll(new Double[] {
                0.0, 0.0,
                width - getOffset(), 0.0,
                width, height / 2,
                width - getOffset(), height,
                0.0, height,
                getOffset(), height / 2});
            setClip(polygon);

        }
    };
}
 
Example #23
Source File: DotArrowShapeDecorations.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private static void setSide(Shape shape, String side) {
	if (shape instanceof Polygon) {
		setSide((Polygon) shape, side);
	} else if (shape instanceof Arc) {
		setSide((Arc) shape, side);
	}
}
 
Example #24
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns an {@link IGeometry} that describes the geometric outline of the
 * given {@link Shape}, i.e. excluding the stroke.
 * <p>
 * The conversion is supported for the following {@link Shape}s:
 * <ul>
 * <li>{@link Arc}
 * <li>{@link Circle}
 * <li>{@link CubicCurve}
 * <li>{@link Ellipse}
 * <li>{@link Line}
 * <li>{@link Path}
 * <li>{@link Polygon}
 * <li>{@link Polyline}
 * <li>{@link QuadCurve}
 * <li>{@link Rectangle}
 * </ul>
 * The following {@link Shape}s cannot be converted, yet:
 * <ul>
 * <li>{@link Text}
 * <li>{@link SVGPath}
 * </ul>
 *
 * @param visual
 *            The {@link Shape} for which an {@link IGeometry} is
 *            determined.
 * @return The newly created {@link IGeometry} that best describes the
 *         geometric outline of the given {@link Shape}.
 * @throws IllegalStateException
 *             if the given {@link Shape} is not supported.
 */
public static IGeometry toGeometry(Shape visual) {
	if (visual instanceof Arc) {
		return toArc((Arc) visual);
	} else if (visual instanceof Circle) {
		return toEllipse((Circle) visual);
	} else if (visual instanceof CubicCurve) {
		return toCubicCurve((CubicCurve) visual);
	} else if (visual instanceof Ellipse) {
		return toEllipse((Ellipse) visual);
	} else if (visual instanceof Line) {
		return toLine((Line) visual);
	} else if (visual instanceof Path) {
		return toPath((Path) visual);
	} else if (visual instanceof Polygon) {
		return toPolygon((Polygon) visual);
	} else if (visual instanceof Polyline) {
		return toPolyline((Polyline) visual);
	} else if (visual instanceof QuadCurve) {
		QuadCurve quad = (QuadCurve) visual;
		return toQuadraticCurve(quad);
	} else if (visual instanceof Rectangle) {
		Rectangle rect = (Rectangle) visual;
		if (rect.getArcWidth() == 0 && rect.getArcHeight() == 0) {
			// corners are not rounded => normal rectangle is sufficient
			return toRectangle(rect);
		}
		return toRoundedRectangle((Rectangle) visual);
	} else {
		// Text and SVGPath shapes are currently not supported
		throw new IllegalStateException(
				"Cannot compute geometric outline for Shape of type <"
						+ visual.getClass() + ">.");
	}
}
 
Example #25
Source File: DotArrowShapeDecorations.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private static void setSide(Polygon polygon, String side) {
	// setting the side of a polygon based shape to left/right means to use
	// 0.0 instead of the negative/positive y coordinates
	ObservableList<Double> points = polygon.getPoints();
	for (int i = 1; i < points.size(); i += 2) {
		double yCoordinate = points.get(i);
		if (yCoordinate < 0 && side.equals("l") //$NON-NLS-1$
				|| yCoordinate > 0 && side.equals("r")) { //$NON-NLS-1$
			points.remove(i);
			points.add(i, 0.0);
		}
	}
}
 
Example #26
Source File: Civ6MenuItem.java    From FXTutorials with MIT License 5 votes vote down vote up
public Civ6MenuItem(String name) {
    Polygon bg = new Polygon(
            0, 0,
            200, 0,
            215, 15,
            200, 30,
            0, 30
    );
    bg.setStroke(Color.color(1, 1, 1, 0.75));
    bg.setEffect(new GaussianBlur());

    bg.fillProperty().bind(
            Bindings.when(pressedProperty())
                    .then(Color.color(0, 0, 0, 0.75))
                    .otherwise(Color.color(0, 0, 0, 0.25))
    );

    text = new Text(name);
    text.setTranslateX(5);
    text.setTranslateY(20);
    text.setFont(Font.loadFont(Civ6MenuApp.class.getResource("res/Penumbra-HalfSerif-Std_35114.ttf").toExternalForm(), 14));
    text.setFill(Color.WHITE);

    text.effectProperty().bind(
            Bindings.when(hoverProperty())
                    .then(shadow)
                    .otherwise(blur)
    );

    getChildren().addAll(bg, text);
}
 
Example #27
Source File: NodeUtils.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the layout-bounds of the given {@link Node}, which might be
 * adjusted to ensure that it exactly fits the visualization.
 *
 * @param node
 *            The {@link Node} to retrieve the (corrected) layout-bounds of.
 * @return A {@link Rectangle} representing the (corrected) layout-bounds.
 */
public static Rectangle getShapeBounds(Node node) {
	Bounds layoutBounds = node.getLayoutBounds();
	// XXX: Polygons don't paint exactly to their layout bounds but remain
	// 0.5 pixels short in case they have a stroke and stroke type is
	// CENTERED or OUTSIDE (see
	// https://bugs.openjdk.java.net/browse/JDK-8145499).
	double offset = 0;
	if (node instanceof Polygon && ((Polygon) node).getStroke() != null
			&& ((Polygon) node).getStrokeType() != StrokeType.INSIDE) {
		offset = 0.5;
	}
	return FX2Geometry.toRectangle(layoutBounds).shrink(offset, offset,
			offset, offset);
}
 
Example #28
Source File: Helper.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public static final boolean isInPolygon(final double X, final double Y, final Polygon POLYGON) {
    List<Double> points              = POLYGON.getPoints();
    int          noOfPointsInPolygon = POLYGON.getPoints().size() / 2;
    double[]     pointsX             = new double[noOfPointsInPolygon];
    double[]     pointsY             = new double[noOfPointsInPolygon];
    int          pointCounter        = 0;

    for (int i = 0, size = points.size() ; i < size - 1 ; i += 2) {
        pointsX[pointCounter] = points.get(i);
        pointsY[pointCounter] = points.get(i + 1);
        pointCounter++;
    }
    return isInPolygon(X, Y, noOfPointsInPolygon, pointsX, pointsY);
}
 
Example #29
Source File: EditorPane.java    From Recaf with MIT License 5 votes vote down vote up
@Override
public Node apply(int lineNo) {
	Polygon poly = new Polygon(shape);
	poly.getStyleClass().add("cursor-pointer");
	poly.setFill(Color.RED);
	if(hasError(lineNo)) {
		String msg = getLineComment(lineNo);
		if(msg != null) {
			Tooltip.install(poly, new Tooltip(msg));
		}
	} else {
		poly.setVisible(false);
	}
	return poly;
}
 
Example #30
Source File: MenuItem.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public MenuItem(String name, int width) {
    	int n = name.length();
//        Polygon bg = new Polygon(
//                0, 0,
//                220, 0,
//                245, 25,
//                220, 50,
//                0, 50
//        );
        Polygon bg = new Polygon(
                0, 0,
                width - 20 , 0,
                width, 25,
                width - 20, 50,
                0, 50
        );

        bg.setStroke(Color.color(1, 1, 1, 0.1));//75));
        //bg.setEffect(new GaussianBlur());
        bg.fillProperty().bind(
                Bindings.when(pressedProperty())
                        .then(Color.color(1, 1, 1, 0.35))//Color.color(139D/255D, 69D/255D, 19D/255D, 0.35))
                        .otherwise(Color.color(1, 1, 1, 0.15))
        );

        text = new Text(name);
        text.setTranslateX((18 - n) * 6.5);
        text.setTranslateY(34);
        text.setFont(Font.loadFont(MenuApp.class.getResource("/fonts/Penumbra-HalfSerif-Std_35114.ttf").toExternalForm(), 22));
        text.setFill(Color.LIGHTGOLDENRODYELLOW);//.CORAL);//.WHITE);
        text.effectProperty().bind(
                Bindings.when(hoverProperty())
                        .then(shadow)
                        .otherwise(blur)
        );

        getChildren().addAll(bg, text);
    }