Package playn.core

Examples of playn.core.CanvasImage


        return new Label(createSampler(baseColor));
    }

    protected Icon createSampler (int baseColor) {
        int size = 16;
        CanvasImage cimg = graphics().createImage(size * 17, size);
        Canvas canvas = cimg.canvas();
        int lighter = baseColor;
        for (int ii = 0; ii <= 8; ++ii) {
            canvas.setFillColor(lighter);
            canvas.fillRect(size * (ii + 8), 0, size, size);
            lighter = Colors.brighter(lighter);
View Full Code Here


    @Override protected String title () {
        return "Particles: Fireworks";
    }

    @Override protected void createParticles (Particles parts, final Randoms rando) {
        CanvasImage image = graphics().createImage(2, 2);
        image.canvas().setFillColor(0xFFFFFFFF);
        image.canvas().fillRect(0, 0, 2, 2);

        final Emitter explode1 = createEmitter(parts, rando, image, 0xFFFFCD82, 0.975f);
        final Emitter explode2 = createEmitter(parts, rando, image, 0xFFF06969, 0.95f);
        note(explode1);
        note(explode2);
View Full Code Here

    @Override protected String title () {
        return "Particles: Fountain";
    }

    @Override protected void createParticles (Particles parts, Randoms rando) {
        CanvasImage image = graphics().createImage(7, 7);
        image.canvas().setFillColor(0xFFFFFFFF);
        image.canvas().fillCircle(3, 3, 3);

        Emitter emitter = parts.createEmitter(5000, image);
        emitter.generator = Generator.constant(100);
        emitter.initters.add(Lifespan.constant(5));
        emitter.initters.add(Color.constant(0xFF99CCFF));
View Full Code Here

        layer.addAt(_group, (width()-width)/2, 0);

        // add a bunch of image layers to our root layer
        float y = 0;
        for (int ii = 0; ii < IMG_COUNT; ii++) {
            CanvasImage image = graphics().createImage(width, IMG_HEIGHT);
            StringBuffer text = new StringBuffer();
            for (int tt = 0; tt < 25; tt++) text.append(ii+1);
            StyledText.span(text.toString(), TEXT).render(image.canvas(), 0, 0);
            ImageLayer layer = graphics().createImageLayer(image);
            _group.addAt(layer, 0, y);
            y += layer.scaledHeight();
        }
View Full Code Here

        return "Various Animations";
    }

    @Override protected Group createIface () {
        // demo a repeating animation
        CanvasImage image = graphics().createImage(100, 100);
        image.canvas().setFillColor(0xFFFFCC99).fillCircle(50, 50, 50);
        ImageLayer circle = graphics().createImageLayer(image);

        float width = graphics().width();
        anim.addAt(layer, circle, 50, 100).then().
            repeat(circle).tweenX(circle).to(width-150).in(1000).easeInOut().then().
            tweenX(circle).to(50).in(1000).easeInOut();

        // demo the shake animation
        final ImageLayer click = StyledText.span("Click to Shake", STYLE).toLayer();
        click.addListener(new Pointer.Adapter() {
            @Override public void onPointerStart (Pointer.Event event) {
                if (_shaker != null) _shaker.complete();
                else _shaker = anim.shake(click).bounds(-3, 3, -3, 0).cycleTime(25, 25).in(1000).
                         then().action(_clear).handle();
            }
            protected final Runnable _clear = new Runnable() {
                public void run () { _shaker = null; }};
            protected Animation.Handle _shaker;
        });
        layer.addAt(click, (width-click.width())/2, 275);

        // demo animation groups
        CanvasImage ball = graphics().createImage(40, 40);
        ball.canvas().setFillColor(0xFF99CCFF).fillCircle(20, 20, 20);
        ImageLayer[] balls = new ImageLayer[6];
        for (int ii = 0; ii < balls.length; ii++) {
            layer.addAt(balls[ii] = graphics().createImageLayer(ball), 170+ii*50, 350);
        }
        anim.repeat(layer).add(dropBalls(balls, 0, 1)).then().
            add(dropBalls(balls, 1, 2)).then().
            add(dropBalls(balls, 3, 3));

        // test barrier delay
        CanvasImage sqimg = graphics().createImage(50, 50);
        sqimg.canvas().setFillColor(0xFF99CCFF).fillRect(0, 0, 50, 50);
        final ImageLayer square = graphics().createImageLayer(sqimg);
        square.setOrigin(25, 25);
        layer.addAt(square, 50, 300);
        square.addListener(new Pointer.Adapter() {
            @Override public void onPointerStart (Pointer.Event event) {
View Full Code Here

                Styles itemStyles = Styles.none().add(Style.Mode.SELECTED,
                        Style.BACKGROUND.is(Background.solid(Colors.BLUE).inset(2))).
                    add(Style.BACKGROUND.is(Background.blank().inset(2)));
                Group colorTable = new Group(new TableLayout(4));
                for (int ii = 0; ii < 256; ii++) {
                    CanvasImage colorImg = PlayN.graphics().createImage(16, 16);
                    colorImg.canvas().setFillColor(0xFF000000 | (ii << 16));
                    colorImg.canvas().fillRect(0, 0, 16, 16);
                    colorTable.add(new MenuItem("", Icons.image(colorImg)).addStyles(itemStyles));
                }
                menu.add(colorTable, slider);
                return menu;
            }
View Full Code Here

    }

    @Override public Root setSize (float width, float height) {
        super.setSize(width, height);
        // update the image to the new size, if it's changed
        CanvasImage old = _image.get();
        if (old == null || old.width() != width || old.height() != height) {
            _image.update(graphics().createImage(width, height));
        }
        return this;
    }
View Full Code Here

        }

        @Override protected LayoutData createLayoutData (float hintX, float hintY) {
            return new LayoutData() {
                @Override public Dimension computeSize (float hintX, float hintY) {
                    CanvasImage image = _image.get();
                    return image == null ? new Dimension(0, 0) :
                        new Dimension(image.width(), image.height());
                }
            };
        }
View Full Code Here

     * Renders the given layer to a canvas image of the given width and height and returns the
     * image.
     * @see #capture(Layer, Canvas)
     */
    public static CanvasImage capture (Layer layer, float width, float height) {
        CanvasImage image = PlayN.graphics().createImage(width, height);
        capture(layer, image.canvas(), 1);
        return image;
    }
View Full Code Here

        _borderRadius = borderRadius;
    }

    @Override
    protected Instance instantiate (final IDimension size) {
        CanvasImage image = graphics().createImage(size.width(), size.height());
        if (_borderWidth > 0) {
            image.canvas().setFillColor(_borderColor);
            image.canvas().fillRoundRect(0, 0, size.width(), size.height(), _radius);
            // scale the inner radius based on the ratio of the inner height to the full height;
            // this improves the uniformity of the border substantially
            float iwidth = size.width() - 2*_borderWidth, iheight = size.height() - 2*_borderWidth;
            float iradius = _borderRadius * (iheight / size.height());
            image.canvas().setFillColor(_bgColor);
            image.canvas().fillRoundRect(_borderWidth, _borderWidth, iwidth, iheight, iradius);
        } else {
            image.canvas().setFillColor(_bgColor);
            image.canvas().fillRoundRect(0, 0, size.width(), size.height(), _radius);
        }
        ImageLayer layer = graphics().createImageLayer(image);
        if (alpha != null) layer.setAlpha(alpha);
        return new LayerInstance(size, layer);
    }
View Full Code Here

TOP

Related Classes of playn.core.CanvasImage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.