Search in sources :

Example 6 with AffineTransform

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

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

the class Region_Delegate method scale.

@LayoutlibDelegate
static /*package*/
void scale(Region thisRegion, float scale, Region dst) {
    Region_Delegate regionDelegate = sManager.getDelegate(thisRegion.mNativeRegion);
    if (regionDelegate == null) {
        return;
    }
    Region_Delegate targetRegionDelegate = sManager.getDelegate(dst.mNativeRegion);
    if (targetRegionDelegate == null) {
        return;
    }
    if (regionDelegate.mArea.isEmpty()) {
        targetRegionDelegate.mArea = new Area();
    } else {
        targetRegionDelegate.mArea = new Area(regionDelegate.mArea);
        AffineTransform mtx = new AffineTransform();
        mtx.scale(scale, scale);
        targetRegionDelegate.mArea.transform(mtx);
    }
}
Also used : Area(java.awt.geom.Area) AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 8 with AffineTransform

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

the class Canvas_Delegate method nativeDrawBitmapMatrix.

@LayoutlibDelegate
static /*package*/
void nativeDrawBitmapMatrix(int nCanvas, int nBitmap, int nMatrix, int nPaint) {
    // get the delegate from the native int.
    Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
    if (canvasDelegate == null) {
        return;
    }
    // get the delegate from the native int, which can be null
    Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nPaint);
    // get the delegate from the native int.
    Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nBitmap);
    if (bitmapDelegate == null) {
        return;
    }
    final BufferedImage image = getImageToDraw(bitmapDelegate, paintDelegate, sBoolOut);
    Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix);
    if (matrixDelegate == null) {
        return;
    }
    final AffineTransform mtx = matrixDelegate.getAffineTransform();
    canvasDelegate.getSnapshot().draw(new GcSnapshot.Drawable() {

        @Override
        public void draw(Graphics2D graphics, Paint_Delegate paint) {
            if (paint != null && paint.isFilterBitmap()) {
                graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            }
            //FIXME add support for canvas, screen and bitmap densities.
            graphics.drawImage(image, mtx, null);
        }
    }, paintDelegate, true, /*compositeOnly*/
    false);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 9 with AffineTransform

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

the class Matrix_Delegate method native_invert.

@LayoutlibDelegate
static /*package*/
boolean native_invert(int native_object, int inverse) {
    Matrix_Delegate d = sManager.getDelegate(native_object);
    if (d == null) {
        return false;
    }
    Matrix_Delegate inv_mtx = sManager.getDelegate(inverse);
    if (inv_mtx == null) {
        return false;
    }
    try {
        AffineTransform affineTransform = d.getAffineTransform();
        AffineTransform inverseTransform = affineTransform.createInverse();
        inv_mtx.mValues[0] = (float) inverseTransform.getScaleX();
        inv_mtx.mValues[1] = (float) inverseTransform.getShearX();
        inv_mtx.mValues[2] = (float) inverseTransform.getTranslateX();
        inv_mtx.mValues[3] = (float) inverseTransform.getScaleX();
        inv_mtx.mValues[4] = (float) inverseTransform.getShearY();
        inv_mtx.mValues[5] = (float) inverseTransform.getTranslateY();
        return true;
    } catch (NoninvertibleTransformException e) {
        return false;
    }
}
Also used : NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 10 with AffineTransform

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

the class GcSnapshot method doRestore.

private GcSnapshot doRestore() {
    if (mPrevious != null) {
        if (mLocalLayer != null) {
            // prepare to blit the layers in which we have draw, in the layer beneath
            // them, starting with the top one (which is the current local layer).
            int i = mLayers.size() - 1;
            int flags;
            do {
                Layer dstLayer = mLayers.get(i - 1);
                restoreLayer(dstLayer);
                flags = dstLayer.getFlags();
                i--;
            } while (i > 0 && (flags & Canvas.CLIP_TO_LAYER_SAVE_FLAG) == 0);
        }
        // didn't save the matrix? set the current matrix on the previous snapshot
        if ((mFlags & Canvas.MATRIX_SAVE_FLAG) == 0) {
            AffineTransform mtx = getTransform();
            for (Layer layer : mPrevious.mLayers) {
                layer.getGraphics().setTransform(mtx);
            }
        }
        // didn't save the clip? set the current clip on the previous snapshot
        if ((mFlags & Canvas.CLIP_SAVE_FLAG) == 0) {
            Shape clip = getClip();
            for (Layer layer : mPrevious.mLayers) {
                layer.setClip(clip);
            }
        }
    }
    for (Layer layer : mLayers) {
        layer.getGraphics().dispose();
    }
    return mPrevious;
}
Also used : Shape(java.awt.Shape) AffineTransform(java.awt.geom.AffineTransform) Paint(android.graphics.Paint)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)335 BufferedImage (java.awt.image.BufferedImage)55 Graphics2D (java.awt.Graphics2D)43 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)38 Point2D (java.awt.geom.Point2D)26 Paint (java.awt.Paint)22 Font (java.awt.Font)21 Shape (java.awt.Shape)21 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 PathIterator (java.awt.geom.PathIterator)16 ArrayList (java.util.ArrayList)16 FontRenderContext (java.awt.font.FontRenderContext)15 Color (java.awt.Color)14 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 Rectangle (java.awt.Rectangle)11 Path2D (java.awt.geom.Path2D)11 Test (org.junit.Test)11