Search in sources :

Example 41 with PathIterator

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

the class Path_Delegate method transform.

/**
     * Transform the points in this path by matrix, and write the answer
     * into dst. If dst is null, then the the original path is modified.
     *
     * @param matrix The matrix to apply to the path
     * @param dst    The transformed path is written here. If dst is null,
     *               then the the original path is modified
     */
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
    if (matrix.hasPerspective()) {
        assert false;
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
    }
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
    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)

Example 42 with PathIterator

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

the class Path_Delegate method isEmpty.

/**
     * Returns whether the path is empty (contains no lines or curves).
     * @see Path#isEmpty
     */
public boolean isEmpty() {
    if (!mCachedIsEmpty) {
        return false;
    }
    float[] coords = new float[6];
    mCachedIsEmpty = Boolean.TRUE;
    for (PathIterator it = mPath.getPathIterator(null); !it.isDone(); it.next()) {
        int type = it.currentSegment(coords);
        if (type != PathIterator.SEG_MOVETO) {
            // Once we know that the path is not empty, we do not need to check again unless
            // Path#reset is called.
            mCachedIsEmpty = false;
            return false;
        }
    }
    return true;
}
Also used : PathIterator(java.awt.geom.PathIterator)

Example 43 with PathIterator

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

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)

Example 44 with PathIterator

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

the class Path_Delegate method transform.

/**
     * Transform the points in this path by matrix, and write the answer
     * into dst. If dst is null, then the the original path is modified.
     *
     * @param matrix The matrix to apply to the path
     * @param dst    The transformed path is written here. If dst is null,
     *               then the the original path is modified
     */
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
    if (matrix.hasPerspective()) {
        assert false;
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
    }
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
    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)

Example 45 with PathIterator

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

the class Path_Delegate method native_approximate.

@LayoutlibDelegate
static float[] native_approximate(long nPath, float error) {
    Path_Delegate pathDelegate = sManager.getDelegate(nPath);
    if (pathDelegate == null) {
        return null;
    }
    // Get a FlatteningIterator
    PathIterator iterator = pathDelegate.getJavaShape().getPathIterator(null, error);
    float[] segment = new float[6];
    float totalLength = 0;
    ArrayList<Point2D.Float> points = new ArrayList<Point2D.Float>();
    Point2D.Float previousPoint = null;
    while (!iterator.isDone()) {
        int type = iterator.currentSegment(segment);
        Point2D.Float currentPoint = new Point2D.Float(segment[0], segment[1]);
        // MoveTo shouldn't affect the length
        if (previousPoint != null && type != PathIterator.SEG_MOVETO) {
            totalLength += currentPoint.distance(previousPoint);
        }
        previousPoint = currentPoint;
        points.add(currentPoint);
        iterator.next();
    }
    int nPoints = points.size();
    float[] result = new float[nPoints * 3];
    previousPoint = null;
    for (int i = 0; i < nPoints; i++) {
        Point2D.Float point = points.get(i);
        float distance = previousPoint != null ? (float) previousPoint.distance(point) : .0f;
        result[i * 3] = distance / totalLength;
        result[i * 3 + 1] = point.x;
        result[i * 3 + 2] = point.y;
        totalLength += distance;
        previousPoint = point;
    }
    return result;
}
Also used : PathIterator(java.awt.geom.PathIterator) Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

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