Search in sources :

Example 11 with GeneralPath

use of java.awt.geom.GeneralPath in project processing by processing.

the class Toolkit method createRoundRect.

public static Shape createRoundRect(float x1, float y1, float x2, float y2, float tl, float tr, float br, float bl) {
    GeneralPath path = new GeneralPath();
    if (tr != 0) {
        path.moveTo(x2 - tr, y1);
        path.quadTo(x2, y1, x2, y1 + tr);
    } else {
        path.moveTo(x2, y1);
    }
    if (br != 0) {
        path.lineTo(x2, y2 - br);
        path.quadTo(x2, y2, x2 - br, y2);
    } else {
        path.lineTo(x2, y2);
    }
    if (bl != 0) {
        path.lineTo(x1 + bl, y2);
        path.quadTo(x1, y2, x1, y2 - bl);
    } else {
        path.lineTo(x1, y2);
    }
    if (tl != 0) {
        path.lineTo(x1, y1 + tl);
        path.quadTo(x1, y1, x1 + tl, y1);
    } else {
        path.lineTo(x1, y1);
    }
    path.closePath();
    return path;
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 12 with GeneralPath

use of java.awt.geom.GeneralPath in project scriptographer by scriptographer.

the class GraphicContext method clip.

/**
     * Intersects the current <code>Clip</code> with the interior of the
     * specified <code>Shape</code> and sets the <code>Clip</code> to the
     * resulting intersection.  The specified <code>Shape</code> is
     * transformed with the current <code>Graphics2D</code>
     * <code>Transform</code> before being intersected with the current
     * <code>Clip</code>.  This method is used to make the current
     * <code>Clip</code> smaller.
     * To make the <code>Clip</code> larger, use <code>setClip</code>.
     * The <i>user clip</i> modified by this method is independent of the
     * clipping associated with device bounds and visibility.  If no clip has
     * previously been set, or if the clip has been cleared using
     * {@link java.awt.Graphics#setClip(Shape) setClip} with a
     * <code>null</code> argument, the specified <code>Shape</code> becomes
     * the new user clip.
     * @param s the <code>Shape</code> to be intersected with the current
     *          <code>Clip</code>.  If <code>s</code> is <code>null</code>,
     *          this method clears the current <code>Clip</code>.
     */
public void clip(Shape s) {
    if (s != null)
        s = transform.createTransformedShape(s);
    if (clip != null) {
        Area newClip = new Area(clip);
        newClip.intersect(new Area(s));
        clip = new GeneralPath(newClip);
    } else {
        clip = s;
    }
}
Also used : Area(java.awt.geom.Area) GeneralPath(java.awt.geom.GeneralPath)

Example 13 with GeneralPath

use of java.awt.geom.GeneralPath in project scriptographer by scriptographer.

the class Raster method getAverageColor.

/**
	 * @jshide
	 */
public Color getAverageColor(Shape shape) {
    //		Rectangle2D rect = shape.getBounds2D();
    GeneralPath path;
    int width = getWidth();
    int height = getHeight();
    int startX = 0;
    int startY = 0;
    if (shape != null) {
        Matrix inverse = getInverseMatrix();
        if (inverse == null)
            return null;
        // Create a transformed path. This is faster than
        // path.clone() / path.transform(at);
        PathIterator pi = shape.getPathIterator(inverse.toAffineTransform());
        path = new GeneralPath();
        path.setWindingRule(pi.getWindingRule());
        path.append(pi, false);
        Rectangle2D bounds = path.getBounds2D();
        // Fetch the sub image to iterate over and calculate average colors
        // from
        // Crop to the maximum size.
        Rectangle2D.intersect(bounds, new Rectangle2D.Double(startX, startY, width, height), bounds);
        width = (int) Math.ceil(bounds.getWidth());
        height = (int) Math.ceil(bounds.getHeight());
        // Are we completely outside the raster? If so, return null
        if (width <= 0 || height <= 0)
            return null;
        startX = (int) Math.floor(bounds.getX());
        startY = (int) Math.floor(bounds.getY());
    } else {
        path = null;
    }
    BufferedImage img = getSubImage(startX, startY, width, height);
    //	Raster check = new Raster(img);
    //	check.setPosition(rect.getCenterX(), rect.getCenterY());
    WritableRaster raster = img.getRaster();
    byte[] data = (byte[]) raster.getDataElements(0, 0, null);
    float[] components = new float[data.length];
    for (int i = 0; i < data.length; i++) components[i] = data[i] & 0xff;
    long total = 1;
    for (int y = 0; y < height; y++) {
        for (int x = (y == 0) ? 1 : 0; x < width; x++) {
            if (path == null || path.contains(x + startX, y + startY)) {
                data = (byte[]) raster.getDataElements(x, height - 1 - y, data);
                for (int i = 0; i < data.length; i++) components[i] += data[i] & 0xff;
                total++;
            }
        }
    }
    total *= 255;
    for (int i = 0; i < components.length; i++) components[i] = components[i] / total;
    // Return colors
    if (components.length == 4)
        return new CMYKColor(components);
    else if (components.length == 3)
        return new RGBColor(components);
    else
        return new GrayColor(components);
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator) Rectangle2D(java.awt.geom.Rectangle2D) BufferedImage(java.awt.image.BufferedImage) WritableRaster(java.awt.image.WritableRaster)

Example 14 with GeneralPath

use of java.awt.geom.GeneralPath in project scriptographer by scriptographer.

the class AbstractGraphics2D method drawPolyline.

/**
     * Draws a sequence of connected lines defined by
     * arrays of <i>x</i> and <i>y</i> coordinates.
     * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
     * The figure is not closed if the first point
     * differs from the last point.
     * @param       xPoints an array of <i>x</i> points
     * @param       yPoints an array of <i>y</i> points
     * @param       nPoints the total number of points
     * @see         java.awt.Graphics#drawPolygon(int[], int[], int)
     * @since       JDK1.1
     */
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
    if (nPoints > 0) {
        GeneralPath path = new GeneralPath();
        path.moveTo(xPoints[0], yPoints[0]);
        for (int i = 1; i < nPoints; i++) path.lineTo(xPoints[i], yPoints[i]);
        draw(path);
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Paint(java.awt.Paint)

Example 15 with GeneralPath

use of java.awt.geom.GeneralPath in project platform_frameworks_base by android.

the class Path_Delegate method offset.

/**
     * Offset the path by (dx,dy), returning true on success
     *
     * @param dx  The amount in the X direction to offset the entire path
     * @param dy  The amount in the Y direction to offset the entire path
     */
public void offset(float dx, float dy) {
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(new AffineTransform(0, 0, dx, 0, 0, dy));
    newPath.append(iterator, false);
    mPath = newPath;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)84 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Rectangle2D (java.awt.geom.Rectangle2D)8 Graphics2D (java.awt.Graphics2D)6 Point (java.awt.Point)6 Paint (java.awt.Paint)5 Color (java.awt.Color)4 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 Point2D (java.awt.geom.Point2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 BasicStroke (java.awt.BasicStroke)2 GradientPaint (java.awt.GradientPaint)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)1 PdfGState (com.itextpdf.text.pdf.PdfGState)1 AlphaComposite (java.awt.AlphaComposite)1 Composite (java.awt.Composite)1