@SuppressWarnings({"WeakerAccess", "unused"}) protected Paint createPathGradientPaint(GradientPaint fill, Graphics2D graphics) { // currently we ignore an eventually center setting return safeFractions(PathGradientPaint::new, fill); }
@SuppressWarnings("WeakerAccess") protected Paint createRadialGradientPaint(GradientPaint fill, Graphics2D graphics) { Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); final Point2D pCenter = new Point2D.Double(anchor.getCenterX(), anchor.getCenterY()); final float radius = (float)Math.max(anchor.getWidth(), anchor.getHeight()); return safeFractions((f,c)->new RadialGradientPaint(pCenter,radius,f,c), fill); }
@SuppressWarnings("WeakerAccess") protected Paint createLinearGradientPaint(GradientPaint fill, Graphics2D graphics) { // TODO: we need to find the two points for gradient - the problem is, which point at the outline // do you take? My solution would be to apply the gradient rotation to the shape in reverse // and then scan the shape for the largest possible horizontal distance double angle = fill.getGradientAngle(); if (!fill.isRotatedWithShape()) { angle -= shape.getRotation(); } Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(angle), anchor.getCenterX(), anchor.getCenterY()); double diagonal = Math.sqrt(Math.pow(anchor.getWidth(),2) + Math.pow(anchor.getHeight(),2)); final Point2D p1 = at.transform(new Point2D.Double(anchor.getCenterX() - diagonal / 2, anchor.getCenterY()), null); final Point2D p2 = at.transform(new Point2D.Double(anchor.getMaxX(), anchor.getCenterY()), null); // snapToAnchor(p1, anchor); // snapToAnchor(p2, anchor); // gradient paint on the same point throws an exception ... and doesn't make sense return (p1.equals(p2)) ? null : safeFractions((f,c)->new LinearGradientPaint(p1,p2,f,c), fill); }
@SuppressWarnings({"WeakerAccess", "unused"}) protected Paint createPathGradientPaint(GradientPaint fill, Graphics2D graphics) { // currently we ignore an eventually center setting return safeFractions(PathGradientPaint::new, fill); }
@SuppressWarnings("WeakerAccess") protected Paint createRadialGradientPaint(GradientPaint fill, Graphics2D graphics) { Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); final Point2D pCenter = new Point2D.Double(anchor.getCenterX(), anchor.getCenterY()); final float radius = (float)Math.max(anchor.getWidth(), anchor.getHeight()); return safeFractions((f,c)->new RadialGradientPaint(pCenter,radius,f,c), fill); }
@SuppressWarnings("WeakerAccess") protected Paint createLinearGradientPaint(GradientPaint fill, Graphics2D graphics) { // TODO: we need to find the two points for gradient - the problem is, which point at the outline // do you take? My solution would be to apply the gradient rotation to the shape in reverse // and then scan the shape for the largest possible horizontal distance double angle = fill.getGradientAngle(); if (!fill.isRotatedWithShape()) { angle -= shape.getRotation(); } Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(angle), anchor.getCenterX(), anchor.getCenterY()); double diagonal = Math.sqrt(Math.pow(anchor.getWidth(),2) + Math.pow(anchor.getHeight(),2)); final Point2D p1 = at.transform(new Point2D.Double(anchor.getCenterX() - diagonal / 2, anchor.getCenterY()), null); final Point2D p2 = at.transform(new Point2D.Double(anchor.getMaxX(), anchor.getCenterY()), null); // snapToAnchor(p1, anchor); // snapToAnchor(p2, anchor); // gradient paint on the same point throws an exception ... and doesn't make sense return (p1.equals(p2)) ? null : safeFractions((f,c)->new LinearGradientPaint(p1,p2,f,c), fill); }