Search in sources :

Example 6 with CanvasImage

use of playn.core.CanvasImage in project playn by threerings.

the class TextTest method makeTextImage.

protected Image makeTextImage() {
    TextFormat format = new TextFormat(graphics().createFont(font.value(), style.value(), 24), true);
    float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : graphics().width() * wrap.value() / 100;
    TextBlock block = new TextBlock(graphics().layoutText(sample, format, new TextWrap(wrapWidth)));
    float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height());
    float pad = TextBlock.pad();
    CanvasImage image = graphics().createImage(awidth + 2 * pad, aheight + 2 * pad);
    image.canvas().translate(pad, pad);
    image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight);
    render(image.canvas(), block, align.value(), lineBounds.value());
    return image;
}
Also used : CanvasImage(playn.core.CanvasImage) TextFormat(playn.core.TextFormat) TextBlock(playn.core.util.TextBlock) TextWrap(playn.core.TextWrap)

Example 7 with CanvasImage

use of playn.core.CanvasImage in project playn by threerings.

the class AlphaLayerTest method init.

@Override
public void init() {
    final GroupLayer rootLayer = graphics().rootLayer();
    final float fullWidth = 6 * width, fullHeight = 3 * height;
    // add a half white, half blue background
    SurfaceImage bg = graphics().createSurface(fullWidth, fullHeight);
    bg.surface().setFillColor(Color.rgb(255, 255, 255));
    bg.surface().fillRect(0, 0, fullWidth, fullHeight);
    bg.surface().setFillColor(Color.rgb(0, 0, 255));
    bg.surface().fillRect(0, 2 * height, fullWidth, height);
    rootLayer.add(graphics().createImageLayer(bg));
    addDescrip("all layers contained in group layer with a=0.5\n" + "thus, fully composited a=0.25", offset, fullHeight + 5, fullWidth);
    // add a 50% transparent group layer
    final GroupLayer groupLayer = graphics().createGroupLayer();
    groupLayer.setAlpha(0.5f);
    rootLayer.add(groupLayer);
    assets().getImage("images/alphalayertest.png").addCallback(new Callback<Image>() {

        @Override
        public void onSuccess(Image image) {
            // add the layers over the white background
            float x = offset;
            groupLayer.addAt(graphics().createImageLayer(image).setAlpha(0.5f), x, offset);
            addDescrip("image\nimg layer a=0.5", x, offset + height, width);
            x += width;
            SurfaceImage surf1 = graphics().createSurface(image.width(), image.height());
            surf1.surface().setAlpha(0.5f).drawImage(image, 0, 0);
            groupLayer.addAt(graphics().createImageLayer(surf1), x, offset);
            addDescrip("surface a=0.5\nimg layer a=1", x, offset + height, width);
            x += width;
            SurfaceImage surf2 = graphics().createSurface(image.width(), image.height());
            surf2.surface().drawImage(image, 0, 0);
            groupLayer.addAt(graphics().createImageLayer(surf2).setAlpha(0.5f), x, offset);
            addDescrip("surface a=1\nimg layer a=0.5", x, offset + height, width);
            x += width;
            CanvasImage canvas1 = graphics().createImage(image.width(), image.height());
            canvas1.canvas().drawImage(image, 0, 0);
            groupLayer.addAt(graphics().createImageLayer(canvas1).setAlpha(0.5f), x, offset);
            addDescrip("canvas a=1\nimg layer a=0.5", x, offset + height, width);
            x += width;
            CanvasImage canvas2 = graphics().createImage(image.width(), image.height());
            canvas2.canvas().setAlpha(0.5f).drawImage(image, 0, 0);
            groupLayer.addAt(graphics().createImageLayer(canvas2), x, offset);
            addDescrip("canvas a=0.5\nimg layer a=1", x, offset + height, width);
            x += width;
            // add the same layers over the blue background
            x = offset;
            groupLayer.addAt(graphics().createImageLayer(image).setAlpha(0.5f), x, offset + 2 * height);
            x += width;
            SurfaceImage surf1b = graphics().createSurface(image.width(), image.height());
            surf1b.surface().setAlpha(0.5f).drawImage(image, 0, 0);
            groupLayer.addAt(graphics().createImageLayer(surf1b), x, offset + 2 * height);
            x += width;
            SurfaceImage surf2b = graphics().createSurface(image.width(), image.height());
            surf2b.surface().drawImage(image, 0, 0);
            groupLayer.addAt(graphics().createImageLayer(surf2b).setAlpha(0.5f), x, offset + 2 * height);
            x += width;
            CanvasImage canvas1b = graphics().createImage(image.width(), image.height());
            canvas1b.canvas().drawImage(image, 0, 0);
            groupLayer.addAt(graphics().createImageLayer(canvas1b).setAlpha(0.5f), x, offset + 2 * height);
            x += width;
            CanvasImage canvas2b = graphics().createImage(image.width(), image.height());
            canvas2b.canvas().setAlpha(0.5f).drawImage(image, 0, 0);
            groupLayer.addAt(graphics().createImageLayer(canvas2b), x, offset + 2 * height);
            // add some copies of the image at 1, 0.5, 0.25 and 0.125 alpha
            x = offset + width;
            for (float alpha : new float[] { 1, 1 / 2f, 1 / 4f, 1 / 8f }) {
                float y = fullHeight + 50;
                rootLayer.addAt(graphics().createImageLayer(image).setAlpha(alpha), x, y);
                addDescrip("image a=" + alpha, x, y + height / 2, width / 2);
                x += width;
            }
        }

        @Override
        public void onFailure(Throwable err) {
            log().error("Error loading image", err);
        }
    });
    // add ground truth of 25% opaque image
    assets().getImage("images/alphalayertest_expected.png").addCallback(new Callback<Image>() {

        @Override
        public void onSuccess(Image image) {
            rootLayer.addAt(graphics().createImageLayer(image), 5 * width, 0);
            addDescrip("ground truth", 5 * width, offset + height, width);
        }

        @Override
        public void onFailure(Throwable err) {
            log().error("Error loading image", err);
        }
    });
}
Also used : CanvasImage(playn.core.CanvasImage) CanvasImage(playn.core.CanvasImage) SurfaceImage(playn.core.SurfaceImage) Image(playn.core.Image) GroupLayer(playn.core.GroupLayer) SurfaceImage(playn.core.SurfaceImage)

Example 8 with CanvasImage

use of playn.core.CanvasImage in project playn by threerings.

the class CanvasStressTest method init.

@Override
public void init() {
    CanvasImage canvasImage = graphics().createImage(graphics().width(), graphics().height());
    canvas = canvasImage.canvas();
    graphics().rootLayer().add(graphics().createImageLayer(canvasImage));
}
Also used : CanvasImage(playn.core.CanvasImage)

Example 9 with CanvasImage

use of playn.core.CanvasImage in project playn by threerings.

the class CanvasTest method createCanvasImage.

private CanvasImage createCanvasImage(int width, int height, final Drawer drawer) {
    final CanvasImage image = graphics().createImage(width, height);
    drawer.draw(image.canvas());
    return image;
}
Also used : CanvasImage(playn.core.CanvasImage)

Example 10 with CanvasImage

use of playn.core.CanvasImage in project playn by threerings.

the class CanvasTest method addTestCanvas.

private void addTestCanvas(String descrip, int width, int height, String imagePath, final ImageDrawer drawer) {
    final CanvasImage target = graphics().createImage(width, height);
    assets().getImage(imagePath).addCallback(new Callback<Image>() {

        public void onSuccess(Image image) {
            drawer.draw(target.canvas(), image);
        }

        public void onFailure(Throwable err) {
            System.err.println("Oops! " + err);
        }
    });
    addTestLayer(descrip, width, height, graphics().createImageLayer(target));
}
Also used : CanvasImage(playn.core.CanvasImage) CanvasImage(playn.core.CanvasImage) Image(playn.core.Image)

Aggregations

CanvasImage (playn.core.CanvasImage)22 ImageLayer (playn.core.ImageLayer)7 TextLayout (playn.core.TextLayout)6 GroupLayer (playn.core.GroupLayer)5 Image (playn.core.Image)5 TextFormat (playn.core.TextFormat)5 Surface (playn.core.Surface)4 SurfaceImage (playn.core.SurfaceImage)4 ImmediateLayer (playn.core.ImmediateLayer)3 Canvas (playn.core.Canvas)2 TextWrap (playn.core.TextWrap)2 TextBlock (playn.core.util.TextBlock)2 Mouse (playn.core.Mouse)1 WheelEvent (playn.core.Mouse.WheelEvent)1 Path (playn.core.Path)1 Pointer (playn.core.Pointer)1 IndexedTrisShader (playn.core.gl.IndexedTrisShader)1