Search in sources :

Example 6 with Context2D

use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.

the class Scene method toDataURL.

// package protected
final String toDataURL(final Layer background) {
    if (LienzoCore.IS_CANVAS_SUPPORTED) {
        final ScratchPad scratch = new ScratchPad(getWidth(), getHeight());
        final Context2D context = scratch.getContext();
        final NFastArrayList<Layer> layers = getChildNodes();
        BoundingBox bbox = getStorageBounds();
        if (null == bbox) {
            final Viewport viewport = getViewport();
            if (null != viewport) {
                bbox = viewport.getStorageBounds();
            }
        }
        if (null != layers) {
            final int size = layers.size();
            if (null != background) {
                background.drawWithTransforms(context, 1, bbox);
            }
            final IPathClipper clip = getPathClipper();
            if ((null != clip) && (clip.isActive())) {
                context.save();
                clip.clip(context);
            }
            for (int i = size - 1; i >= 0; i--) {
                final Layer layer = layers.get(i);
                if ((null != layer) && (layer.isVisible())) {
                    layer.drawWithTransforms(context, 1, bbox);
                }
            }
            if ((null != clip) && (clip.isActive())) {
                context.restore();
            }
        }
        return scratch.toDataURL();
    } else {
        return "data:,";
    }
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 7 with Context2D

use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.

the class MagnetManager method drawMagnetsToBack.

public ImageData drawMagnetsToBack(final Magnets magnets, final NFastStringMap<WiresShape> shapeColors, final NFastStringMap<WiresMagnet> magnetColors, final ScratchPad scratch) {
    scratch.clear();
    final Context2D ctx = scratch.getContext();
    drawShapeToBacking(magnets, shapeColors, ctx);
    magnetColors.clear();
    for (int i = 0; i < magnets.size(); i++) {
        drawMagnet(magnetColors, ctx, magnets.getMagnet(i));
    }
    return ctx.getImageData(0, 0, scratch.getWidth(), scratch.getHeight());
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D)

Example 8 with Context2D

use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.

the class ImageData method copy.

/**
 * ImageData can't be cloned or deep-copied, it's an internal data structure and has some CRAZY crap in it, this is cheeeeeezy, but hey, it works, and it's portable!!!
 */
public final ImageData copy() {
    final Context2D context = new ScratchPad(getWidth(), getHeight()).getContext();
    context.putImageData(this, 0, 0);
    return context.getImageData(0, 0, getWidth(), getHeight());
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad)

Example 9 with Context2D

use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.

the class BackingColorMapUtils method drawShapesToBacking.

public static ImageData drawShapesToBacking(final NFastArrayList<WiresShape> prims, final ScratchPad scratch, final WiresContainer skip, final NFastStringMap<WiresShape> shape_color_map) {
    scratch.clear();
    final Context2D ctx = scratch.getContext();
    shape_color_map.clear();
    drawShapesToBacking(prims, ctx, skip, shape_color_map);
    return ctx.getImageData(0, 0, scratch.getWidth(), scratch.getHeight());
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D)

Example 10 with Context2D

use of com.ait.lienzo.client.core.Context2D in project lienzo-core by ahome-it.

the class LienzoCore method examineNativeLineDashSupported.

private final boolean examineNativeLineDashSupported() {
    if (IS_CANVAS_SUPPORTED) {
        try {
            final ScratchPad scratch = new ScratchPad(20, 10);
            final Context2D context = scratch.getContext();
            context.setStrokeWidth(10);
            context.setLineCap(LineCap.BUTT);
            context.setStrokeColor(ColorName.BLUE);
            context.beginPath();
            context.moveTo(0, 5);
            context.lineTo(20, 5);
            context.stroke();
            context.setStrokeColor(ColorName.RED);
            context.setLineDash(new DashArray(5, 5));
            context.beginPath();
            context.moveTo(0, 5);
            context.lineTo(20, 5);
            context.stroke();
            final ImageData backing = context.getImageData(0, 0, 20, 10);
            if (null != backing) {
                if ((backing.getRedAt(3, 5) == 255) && (backing.getBlueAt(3, 5) == 0) && (backing.getGreenAt(3, 5) == 0)) {
                    if ((backing.getRedAt(8, 5) == 0) && (backing.getBlueAt(8, 5) == 255) && (backing.getGreenAt(8, 5) == 0)) {
                        return true;
                    }
                }
            }
        } catch (final Exception e) {
            // FF 22 dev mode does not like line dashes
            error("Line Dash test failed ", e);
        }
    }
    return false;
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ImageData(com.ait.lienzo.client.core.types.ImageData) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) DashArray(com.ait.lienzo.client.core.types.DashArray) UmbrellaException(com.google.gwt.event.shared.UmbrellaException)

Aggregations

Context2D (com.ait.lienzo.client.core.Context2D)13 ScratchPad (com.ait.lienzo.client.core.util.ScratchPad)8 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)5 ImageData (com.ait.lienzo.client.core.types.ImageData)3 DashArray (com.ait.lienzo.client.core.types.DashArray)1 FillGradient (com.ait.lienzo.client.core.types.FillGradient)1 PathPartEntryJSO (com.ait.lienzo.client.core.types.PathPartEntryJSO)1 PathPartList (com.ait.lienzo.client.core.types.PathPartList)1 Point2D (com.ait.lienzo.client.core.types.Point2D)1 TextMetrics (com.ait.lienzo.client.core.types.TextMetrics)1 Color (com.ait.lienzo.shared.core.types.Color)1 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)1 NFastStringMap (com.ait.tooling.nativetools.client.collection.NFastStringMap)1 UmbrellaException (com.google.gwt.event.shared.UmbrellaException)1