Skip to content

Instantly share code, notes, and snippets.

@dlemmermann
Created January 3, 2022 12:25
Show Gist options
  • Save dlemmermann/5f4f45aa150c23f2e218b48a18d22121 to your computer and use it in GitHub Desktop.
Save dlemmermann/5f4f45aa150c23f2e218b48a18d22121 to your computer and use it in GitHub Desktop.
ComplexClip
private void applyClip() {
ReadOnlyObjectProperty<Bounds> boundsProperty = layoutBoundsProperty();
Rectangle rect = new Rectangle();
rect.setManaged(false);
rect.layoutXProperty().bind(Bindings.createDoubleBinding(() -> boundsProperty.get().getMinX(), boundsProperty));
rect.layoutYProperty().bind(Bindings.createDoubleBinding(() -> boundsProperty.get().getMinY(), boundsProperty));
rect.widthProperty().bind(Bindings.createDoubleBinding(() -> boundsProperty.get().getWidth(), boundsProperty));
rect.heightProperty().bind(Bindings.createDoubleBinding(() -> boundsProperty.get().getHeight(), boundsProperty));
rect.setFill(Color.BLACK);
Shape clip1 = rect;
Shape clip2 = rect;
Shape clip3 = rect;
Shape clip4 = rect;
for (int i = 0; i < getPoints().size(); i++) {
PointEntry pointEntry = pointEntries.size() > i ? pointEntries.get(i) : null;
if (pointEntry != null) {
Ellipse ellipse = pointEntry.ellipse;
Ellipse clipEllipse = new Ellipse();
clipEllipse.setStrokeWidth(ellipse.getStrokeWidth());
clipEllipse.setRadiusX(ellipse.getRadiusX() * ellipse.getScaleX());
clipEllipse.setRadiusY(ellipse.getRadiusY() * ellipse.getScaleY());
clipEllipse.setCenterX(ellipse.getCenterX());
clipEllipse.setCenterY(ellipse.getCenterY());
clipEllipse.setFill(Color.BLACK);
clip1 = Shape.subtract(clip1, clipEllipse);
clip2 = Shape.subtract(clip2, clipEllipse);
clip3 = Shape.subtract(clip3, clipEllipse);
clip4 = Shape.subtract(clip4, clipEllipse);
}
}
path.setClip(clip1);
pathShadow.setClip(clip2);
animatedPath.setClip(clip3);
animatedPathShadow.setClip(clip4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment