Example usage for com.google.gwt.canvas.client Canvas getCanvasElement

List of usage examples for com.google.gwt.canvas.client Canvas getCanvasElement

Introduction

In this page you can find the example usage for com.google.gwt.canvas.client Canvas getCanvasElement.

Prototype

public CanvasElement getCanvasElement() 

Source Link

Document

Returns the attached Canvas Element.

Usage

From source file:com.badlogic.gdx.backends.gwt.GwtGraphics.java

License:Apache License

public GwtGraphics(Panel root, GwtApplicationConfiguration config) {
    Canvas canvasWidget = Canvas.createIfSupported();
    if (canvasWidget == null)
        throw new GdxRuntimeException("Canvas not supported");
    canvas = canvasWidget.getCanvasElement();
    root.add(canvasWidget);//from w  ww  .  j a v  a 2  s .co  m
    canvas.setWidth(config.width);
    canvas.setHeight(config.height);
    this.config = config;

    WebGLContextAttributes attributes = WebGLContextAttributes.create();
    attributes.setAntialias(config.antialiasing);
    attributes.setStencil(config.stencil);
    attributes.setAlpha(config.alpha);
    attributes.setPremultipliedAlpha(config.premultipliedAlpha);
    attributes.setPreserveDrawingBuffer(config.preserveDrawingBuffer);

    context = WebGLRenderingContext.getContext(canvas, attributes);
    context.viewport(0, 0, config.width, config.height);
    this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GwtGL20(context);

    String versionString = gl.glGetString(GL20.GL_VERSION);
    String vendorString = gl.glGetString(GL20.GL_VENDOR);
    String rendererString = gl.glGetString(GL20.GL_RENDERER);
    glVersion = new GLVersion(Application.ApplicationType.WebGL, versionString, vendorString, rendererString);
}

From source file:com.himamis.retex.renderer.web.graphics.Graphics2DW.java

License:Open Source License

@Override
public void drawImage(Image image, int x, int y) {
    ImageW impl = (ImageW) image;/*ww  w.j ava 2 s  . c  om*/
    Canvas imageCanvas = impl.getCanvas();
    CanvasElement canvasElement = imageCanvas.getCanvasElement();
    context.drawImage(canvasElement, x, y);
}

From source file:com.lambourg.webgallery.client.widgets.TitleBarIcon.java

License:GNU General Public License

private void draw() {
    Context2d ctx;/*from   w ww.  j av a  2s.  co  m*/
    Canvas buffer = Canvas.createIfSupported();
    Image img;
    int size = Style.toPixelRatio(Style.titleIconSize);

    this.canvas.setCoordinateSpaceWidth(size);
    this.canvas.setCoordinateSpaceHeight(size + Style.toPixelRatio(1));
    buffer.setCoordinateSpaceWidth(size);
    buffer.setCoordinateSpaceHeight(size);

    if (this.active) {
        img = this.imgActive;
    } else {
        img = this.imgNormal;
    }

    //  We need to draw the icon itself in a separate buffer, and only
    //  after apply the shadow.
    //  The reason is that in order to draw the icon using the color we
    //  want, we need to use composite operations, and this is not
    //  compatible with the shadow effect we want.
    ctx = buffer.getContext2d();
    if (this.over) {
        ctx.setFillStyle("#fff");
    } else {
        ctx.setFillStyle("#ddd");
    }
    ctx.fillRect(0, 0, size, size);
    ctx.setGlobalCompositeOperation(Composite.DESTINATION_ATOP);
    ctx.drawImage(ImageElement.as(img.getElement()), 0, 0, size, size);
    ctx.restore();

    ctx = this.canvas.getContext2d();
    ctx.setShadowBlur(0.0);
    ctx.setShadowColor("#333");
    ctx.setShadowOffsetY(Style.toPixelRatio(1));

    ctx.drawImage(buffer.getCanvasElement(), 0, 0, size, size);
}

From source file:com.shc.webgl4j.client.WebGL10.java

License:Open Source License

/**
 * Creates a WebGL 1.0 context upon a canvas object using the default context attributes. This method alerts the
 * user if there is no WebGL support and also redirects the browser to <a href="http://get.webgl.org/">get.webgl.org
 * </a>./*from   www.  j av a  2  s  .  c o m*/
 *
 * @param canvas The canvas object to creeate the context upon.
 *
 * @return The created WebGL context object.
 */
public static WebGLContext createContext(Canvas canvas) {
    return createContext(canvas.getCanvasElement());
}

From source file:com.shc.webgl4j.client.WebGL10.java

License:Open Source License

/**
 * Creates a WebGL 1.0 context upon a canvas object using the specified context attributes. This method alerts the
 * user if there is no WebGL support and also redirects the browser to <a href="http://get.webgl.org/">get.webgl.org
 * </a>.//from   w w w .  j  a v  a  2s.  c  o m
 *
 * @param canvas     The canvas object to creeate the context upon.
 * @param attributes The context attributes to request the context with.
 *
 * @return The created WebGL context object.
 */
public static WebGLContext createContext(Canvas canvas, WebGLContext.Attributes attributes) {
    return createContext(canvas.getCanvasElement(), attributes);
}

From source file:com.shc.webgl4j.client.WebGL20.java

License:Open Source License

public static WebGLContext createContext(Canvas canvas) {
    return createContext(canvas.getCanvasElement());
}

From source file:com.shc.webgl4j.client.WebGL20.java

License:Open Source License

public static WebGLContext createContext(Canvas canvas, WebGLContext.Attributes attributes) {
    return createContext(canvas.getCanvasElement(), attributes);
}

From source file:de.ga_ap.cirrus.newcloud.client.TheCloud.java

License:Open Source License

public TheCloud(final Element cloudContainer) {

    final NodeList<Element> aElements = cloudContainer.getElementsByTagName("A");
    final int height = cloudContainer.getOffsetHeight();
    final int width = cloudContainer.getOffsetWidth();

    final Canvas canvas = Canvas.createIfSupported();
    canvas.setCoordinateSpaceHeight(height);
    canvas.setCoordinateSpaceWidth(width);
    final Context2d context2d = canvas.getContext2d();

    final double radius = canvas.getCanvasElement().getHeight() / 3;
    final int refreshrate = 30;

    final List<CloudItem> itemList = new ArrayList<CloudItem>(aElements.getLength());
    for (int i = 0; i < aElements.getLength(); i++) {
        final Element el = aElements.getItem(i);
        final CloudItem ci = new CloudItem();
        ci.text = el.getInnerText();/*from   w  ww  .  ja v a  2s.  c o m*/
        itemList.add(ci);
    }
    cloudContainer.setInnerText("");

    final int itemListSize = itemList.size();
    for (int i = 1; i <= itemListSize; i++) {
        final CloudItem ci = itemList.get(i - 1);
        ci.theta = Math.acos(-1.0 + (2.0 * (double) i - 1.0) / itemListSize);
        ci.phi = Math.sqrt(itemListSize * Math.PI) * ci.theta;

        ci.z = radius * Math.cos(ci.theta);
        ci.y = radius * Math.sin(ci.theta) * Math.cos(ci.phi);
        ci.x = radius * Math.sin(ci.theta) * Math.sin(ci.phi);

        // TODO heightOfAllItems ?!

        // TODO font size

        context2d.fillText(ci.text, ci.y, ci.z);
        System.out.println(ci.x + " " + ci.y + " " + ci.z + " - " + ci.theta + " " + ci.phi);

    }

    Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {

        @Override
        public boolean execute() {

            canvas.setCoordinateSpaceHeight(height);
            canvas.setCoordinateSpaceWidth(width);

            final double cosPsi = Math.cos(psi);
            final double sinPsi = Math.sin(psi);

            final double cosTheta = Math.cos(theta);
            final double sinTheta = Math.sin(theta);

            final double sinThetaCosPsi = sinTheta * cosPsi;
            final double sinThetaSinPsi = sinTheta * sinPsi;

            for (final CloudItem ci : itemList) {

                final double x, y, z;

                x = ci.x * cosTheta * cosPsi + ci.y * cosTheta * sinPsi - ci.z * sinTheta;
                y = ci.x * (-sinPsi) + ci.y * cosPsi;
                z = ci.x * sinThetaCosPsi + ci.y * sinThetaSinPsi + ci.z * cosTheta;
                ci.x = x;
                ci.y = y;
                ci.z = z;

                context2d.setGlobalAlpha(0.7 + ci.x / radius / 3.0);
                context2d.setFont("20pt Arial");
                context2d.fillText(ci.text, radius + ci.y, radius + ci.z);

                // System.out.println(ci.x + " " + ci.y + " " + ci.z + " - "
                // + ci.theta + " " + ci.phi + " " + ci.text);
            }

            theta += ySteps;
            psi += xSteps;
            // System.out.println(theta);
            if (theta > Math.PI * 2.0) {
                theta = 0.0;
            }
            if (psi > Math.PI * 2.0) {
                psi = 0.0;
            }
            return true;
        }
    }, refreshrate);

    // final EventListener listener = new EventListener() {
    //
    // @Override
    // public void onBrowserEvent(final Event event) {
    // if (event.getTypeInt() == Event.ONMOUSEMOVE) {
    // moveSteps(event);
    // } else if (event.getTypeInt() == Event.ONTOUCHMOVE) {
    // event.preventDefault(); // prevents the default behavior of
    // // a page when touching
    // moveSteps(event);
    // }
    // }
    //
    // private void moveSteps(final Event event) {
    // ySteps = -((event.getClientY() + Window.getScrollTop())
    // / canvas.getCoordinateSpaceHeight() * 0.000002 - 0.1) / 2.0;
    // xSteps = ((event.getClientX() + Window.getScrollLeft())
    // / canvas.getCoordinateSpaceWidth() * 0.000002 - 0.1) / 2.0;
    // }
    // };
    //
    // DOM.setEventListener(
    // (com.google.gwt.user.client.Element) cloudContainer, listener);
    // DOM.sinkEvents((com.google.gwt.user.client.Element) cloudContainer,
    // Event.ONMOUSEMOVE + Event.ONTOUCHMOVE);

    System.out.println(radius);
    cloudContainer.appendChild(canvas.getCanvasElement());
}

From source file:edu.caltech.ipac.firefly.visualize.draw.HtmlGwtCanvas.java

public void copyAsImage(AdvancedGraphics g) {
    Canvas sourceCanvas = g.getCanvasPanel().getCanvas();
    int w = sourceCanvas.getCoordinateSpaceWidth();
    int h = sourceCanvas.getCoordinateSpaceHeight();
    ctx.drawImage(sourceCanvas.getCanvasElement(), 0, 0, w, h, 0, 0, w, h);
}

From source file:net.blimster.gwt.threejs.renderers.CanvasRenderer.java

License:Open Source License

public static CanvasRenderer create(Canvas canvas) {

    return CanvasRenderer.create(canvas.getCanvasElement());

}