Search in sources :

Example 1 with PathIterator

use of java.awt.geom.PathIterator in project android_frameworks_base by ParanoidAndroid.

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
     * @param dst The translated path is written here. If this is null, then
     *            the original path is modified.
     */
public void offset(float dx, float dy, Path_Delegate dst) {
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(new AffineTransform(0, 0, dx, 0, 0, dy));
    newPath.append(iterator, false);
    if (dst != null) {
        dst.mPath = newPath;
    } else {
        mPath = newPath;
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator) AffineTransform(java.awt.geom.AffineTransform)

Example 2 with PathIterator

use of java.awt.geom.PathIterator in project silk by jbee.

the class TestMockingBinds method methodsOfMocksByDefaultReturnMocksIfPossible.

@Test
public void methodsOfMocksByDefaultReturnMocksIfPossible() {
    Injector injector = Bootstrap.injector(TestMockingBindsModule.class);
    Shape shape = injector.resolve(dependency(Shape.class));
    PathIterator iter = shape.getPathIterator(null);
    assertNotNull(iter);
    assertTrue(isProxyClass(iter.getClass()));
    assertFalse(iter.isDone());
}
Also used : Shape(java.awt.Shape) PathIterator(java.awt.geom.PathIterator) Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 3 with PathIterator

use of java.awt.geom.PathIterator in project openblocks by mikaelhg.

the class BlockShapeUtil method printPath.

/** Prints out a GeneralPath.  Used for debugging only */
public static void printPath(GeneralPath gp) {
    if (gp == null) {
        System.out.println("(null path)");
        return;
    }
    int type;
    float[] segment = new float[6];
    PathIterator i = gp.getPathIterator(new AffineTransform());
    while (!i.isDone()) {
        type = i.currentSegment(segment);
        if (type == PathIterator.SEG_MOVETO) {
            System.out.println("m: (" + segment[0] + ", " + segment[1] + ")");
        } else if (type == PathIterator.SEG_LINETO) {
            System.out.println("l: (" + segment[0] + ", " + segment[1] + ")");
        } else if (type == PathIterator.SEG_QUADTO) {
            System.out.println("q: (" + segment[0] + ", " + segment[1] + "), (" + segment[2] + ", " + segment[3] + ")");
        } else if (type == PathIterator.SEG_CUBICTO) {
            System.out.println("c: (" + segment[0] + ", " + segment[1] + "), (" + segment[2] + ", " + segment[3] + "), (" + segment[4] + ", " + segment[5] + ")");
        }
        i.next();
    }
}
Also used : PathIterator(java.awt.geom.PathIterator) AffineTransform(java.awt.geom.AffineTransform)

Example 4 with PathIterator

use of java.awt.geom.PathIterator 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 5 with PathIterator

use of java.awt.geom.PathIterator 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

PathIterator (java.awt.geom.PathIterator)56 AffineTransform (java.awt.geom.AffineTransform)16 GeneralPath (java.awt.geom.GeneralPath)14 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)10 ArrayList (java.util.ArrayList)9 Point2D (java.awt.geom.Point2D)7 CachedPathIterator (com.android.layoutlib.bridge.util.CachedPathIteratorFactory.CachedPathIterator)5 Point (java.awt.Point)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Path2D (java.awt.geom.Path2D)3 Paint (java.awt.Paint)2 Rectangle (java.awt.Rectangle)2 TDoubleArrayList (gnu.trove.TDoubleArrayList)1 GradientPaint (java.awt.GradientPaint)1 LinearGradientPaint (java.awt.LinearGradientPaint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 Shape (java.awt.Shape)1 TexturePaint (java.awt.TexturePaint)1 FontRenderContext (java.awt.font.FontRenderContext)1 GlyphVector (java.awt.font.GlyphVector)1