Example usage for com.google.gwt.dom.client CanvasElement setWidth

List of usage examples for com.google.gwt.dom.client CanvasElement setWidth

Introduction

In this page you can find the example usage for com.google.gwt.dom.client CanvasElement setWidth.

Prototype

public final native void setWidth(int width) ;

Source Link

Document

Sets the width of the canvas.

Usage

From source file:forplay.html.HtmlCanvas.java

License:Apache License

HtmlCanvas(CanvasElement canvas, int width, int height) {
    this.canvas = canvas;
    this.width = width;
    this.height = height;
    canvas.setWidth(width);
    canvas.setHeight(height);/* w w w .  j a  va2 s  .co m*/
    ctx = canvas.getContext2d();
}

From source file:forplay.html.HtmlCanvasLayerDom.java

License:Apache License

HtmlCanvasLayerDom(int width, int height) {
    super(Document.get().createCanvasElement());

    CanvasElement canvas = element().cast();
    canvas.setWidth(width);
    canvas.setHeight(height);/*  w ww . j  a v  a 2 s .  c  o  m*/

    this.canvas = new HtmlCanvas(canvas, width, height);
}

From source file:forplay.html.HtmlCanvasLayerGL.java

License:Apache License

HtmlCanvasLayerGL(HtmlGraphicsGL gfx, int width, int height) {
    super(gfx);/*from w  w w.  j  a va 2 s. c o  m*/

    this.width = width;
    this.height = height;

    CanvasElement canvas = Document.get().createCanvasElement();
    canvas.setWidth(width);
    canvas.setHeight(height);

    this.canvas = new HtmlCanvas(canvas, width, height);
    tex = gfx.createTexture(false, false);
}

From source file:gwt.material.design.addins.client.camera.MaterialCameraCapture.java

License:Apache License

/**
 * Native call to capture the frame of the video stream.
 *///from  w  w w.  j  av a  2  s.  c  om
protected String nativeCaptureToDataURL(CanvasElement canvas, Element element, String mimeType) {
    VideoElement videoElement = (VideoElement) element;
    int width = videoElement.getVideoWidth();
    int height = videoElement.getVideoHeight();
    if (Double.isNaN(width) || Double.isNaN(height)) {
        width = videoElement.getClientWidth();
        height = videoElement.getClientHeight();
    }
    canvas.setWidth(width);
    canvas.setHeight(height);
    Context2d context = canvas.getContext2d();
    context.drawImage(videoElement, 0, 0, width, height);
    return canvas.toDataUrl(mimeType);
}

From source file:gwt.material.design.addins.client.signature.MaterialSignaturePad.java

License:Apache License

protected void applyResize() {
    CanvasElement element = getElement().cast();
    double ratio = getRatio();
    element.setWidth((int) (getOffsetWidth() * ratio));
    element.setHeight((int) (getOffsetHeight() * ratio));
    element.getContext2d().scale(ratio, ratio);
    getSignaturePad().clear();/*from w w w. ja  v a2 s.  c  o  m*/
}

From source file:org.cruxframework.crux.core.client.image.ImageProcessor.java

License:Apache License

/**
 * Resize the internal image//from   ww  w.j a va  2s.  co m
 * @param width
 * @param height
 */
public void resize(int width, int height) {
    assert (image != null || this.canvas != null) : "You must load an image first";

    CanvasElement canvas = Document.get().createCanvasElement().cast();
    canvas.setWidth(width);
    canvas.setHeight(height);
    if (image != null) {
        canvas.getContext2d().drawImage(image.asImageElement(), 0, 0, width, height);
    } else {
        canvas.getContext2d().drawImage(this.canvas, 0, 0, this.canvas.getWidth(), this.canvas.getHeight(), 0,
                0, width, height);
    }

    this.canvas = canvas;
    image = null;
}

From source file:org.parallax3d.parallax.graphics.textures.PixmapTextureData.java

License:Open Source License

/**
 * Warning: Scaling through the canvas will only work with images that use
 * premultiplied alpha./*  w  ww.ja  v  a  2 s .com*/
 *
 * @param maxSize  the max size of absoluteWidth or absoluteHeight
 *
 * @return a new Image, or the same one if no clamping was necessary
 */
public PixmapTextureData clampToMaxSize(int maxSize) {
    int imgWidth = image.getOffsetWidth();
    int imgHeight = image.getOffsetHeight();

    if (imgWidth <= maxSize && imgHeight <= maxSize)
        return this;

    int maxDimension = Math.max(imgWidth, imgHeight);
    int newWidth = (int) Math.floor(imgWidth * maxSize / maxDimension);
    int newHeight = (int) Math.floor(imgHeight * maxSize / maxDimension);

    CanvasElement canvas = Document.get().createElement("canvas").cast();
    canvas.setWidth(newWidth);
    canvas.setHeight(newHeight);

    Context2d context = canvas.getContext2d();
    context.drawImage((ImageElement) image, 0, 0, imgWidth, imgHeight, 0, 0, newWidth, newHeight);

    image.getParentElement().appendChild(canvas);
    image.removeFromParent();
    image = canvas;

    return this;
}

From source file:org.parallax3d.parallax.graphics.textures.PixmapTextureData.java

License:Open Source License

@Override
public PixmapTextureData toPowerOfTwo() {
    if (isPowerOfTwo())
        return this;

    int width = image.getOffsetWidth();
    int height = image.getOffsetHeight();

    CanvasElement canvas = Document.get().createElement("canvas").cast();

    // Scale up the texture to the next highest power of two dimensions.
    canvas.setWidth(Mathematics.getNextHighestPowerOfTwo(width));
    canvas.setHeight(Mathematics.getNextHighestPowerOfTwo(height));

    Context2d context = canvas.getContext2d();
    context.drawImage((ImageElement) image, 0, 0, width, height);

    image = canvas;// w  w w. ja  v  a 2 s  . c  o  m
    return this;
}

From source file:playn.html.HtmlCanvas.java

License:Apache License

HtmlCanvas(CanvasElement canvas, float width, float height) {
    this(canvas, canvas.getContext2d(), width, height);
    canvas.setWidth(MathUtil.iceil(width));
    canvas.setHeight(MathUtil.iceil(height));
}

From source file:playn.html.HtmlCanvasLayerCanvas.java

License:Apache License

HtmlCanvasLayerCanvas(int width, int height) {
    CanvasElement canvas = Document.get().createCanvasElement();
    canvas.setWidth(width);
    canvas.setHeight(height);/*from w w  w.ja v a 2s.co  m*/

    this.canvas = new HtmlCanvas(canvas, width, height);
}