Search in sources :

Example 6 with Context2d

use of com.google.gwt.canvas.dom.client.Context2d in project gwt-cs by iSergio.

the class ParticleSystemFireworks method getImage.

private CanvasElement getImage() {
    if (!Cesium.defined(particleCanvas)) {
        particleCanvas = RootPanel.get().getElement().getOwnerDocument().createCanvasElement();
        particleCanvas.setWidth(20);
        particleCanvas.setHeight(20);
        Context2d context2d = particleCanvas.getContext2d();
        context2d.beginPath();
        context2d.arc(8, 8, 8, 0, Math.TWO_PI(), true);
        context2d.closePath();
        context2d.setFillStyle("rgb(255, 255, 255)");
        context2d.fill();
        Cesium.log(particleCanvas);
    }
    return particleCanvas;
}
Also used : Context2d(com.google.gwt.canvas.dom.client.Context2d)

Example 7 with Context2d

use of com.google.gwt.canvas.dom.client.Context2d in project rstudio by rstudio.

the class FontDetector method isFontSupported.

public static boolean isFontSupported(String fontName) {
    SimplePanel panel = null;
    try {
        // default font name as a reference point
        final String defaultFontName = "Arial";
        if (defaultFontName.equals(fontName))
            return true;
        // make sure canvas is supported
        if (!Canvas.isSupported())
            return false;
        // add a temporary div to the dom
        panel = new SimplePanel();
        panel.setHeight("200px");
        panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
        panel.getElement().getStyle().setOverflow(Overflow.SCROLL);
        RootPanel.get().add(panel, -2000, -2000);
        // add a canvas element to the div and get the 2d drawing context
        final Canvas canvas = Canvas.createIfSupported();
        canvas.setWidth("512px");
        canvas.setHeight("64px");
        canvas.getElement().getStyle().setLeft(400, Unit.PX);
        canvas.getElement().getStyle().setBackgroundColor("#ffe");
        panel.add(canvas);
        final Context2d ctx = canvas.getContext2d();
        ctx.setFillStyle("#000000");
        // closure to generate a hash for a font
        class HashGenerator {

            public String getHash(String fontName) {
                ctx.setFont("57px " + fontName + ", " + defaultFontName);
                int width = canvas.getOffsetWidth();
                int height = canvas.getOffsetHeight();
                ctx.clearRect(0, 0, width, height);
                ctx.fillText("TheQuickBrownFox", 2, 50);
                return canvas.toDataUrl();
            }
        }
        ;
        // get hashes and compare them
        HashGenerator hashGenerator = new HashGenerator();
        String defaultHash = hashGenerator.getHash(defaultFontName);
        String fontHash = hashGenerator.getHash(fontName);
        return !defaultHash.equals(fontHash);
    } catch (Exception ex) {
        Debug.log(ex.toString());
        return false;
    } finally {
        if (panel != null)
            RootPanel.get().remove(panel);
    }
}
Also used : Context2d(com.google.gwt.canvas.dom.client.Context2d) Canvas(com.google.gwt.canvas.client.Canvas) SimplePanel(com.google.gwt.user.client.ui.SimplePanel)

Example 8 with Context2d

use of com.google.gwt.canvas.dom.client.Context2d in project rstudio by rstudio.

the class ProgressSpinner method redraw.

private void redraw() {
    Context2d ctx = canvas_.getContext2d();
    double center = COORD_SIZE / 2;
    // clear canvas (we draw with an alpha channel so otherwise would stack)
    ctx.clearRect(0, 0, COORD_SIZE, COORD_SIZE);
    for (int i = 0; i < NUM_BLADES; i++) {
        // compute angle for this blade
        double theta = ((2 * Math.PI) / NUM_BLADES) * i;
        double sin = Math.sin(theta);
        double cos = Math.cos(theta);
        // set line drawing context
        ctx.beginPath();
        ctx.setLineWidth(BLADE_WIDTH);
        ctx.setLineCap(LineCap.ROUND);
        // compute transparency for this blade
        double alpha = 1.0 - (((double) ((i + frame_) % NUM_BLADES)) / ((double) NUM_BLADES));
        ctx.setStrokeStyle("rgba(" + color_ + ", " + alpha + ")");
        // draw the blade
        ctx.moveTo(center + sin * innerRadius_, center + cos * innerRadius_);
        ctx.lineTo(center + sin * outerRadius_, center + cos * outerRadius_);
        ctx.stroke();
    }
}
Also used : Context2d(com.google.gwt.canvas.dom.client.Context2d)

Example 9 with Context2d

use of com.google.gwt.canvas.dom.client.Context2d in project playn by threerings.

the class HtmlImage method getRgb.

@Override
public void getRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
    assert isReady() : "Cannot getRgb() a non-ready image";
    if (canvas == null) {
        canvas = img.getOwnerDocument().createCanvasElement();
        canvas.setHeight(img.getHeight());
        canvas.setWidth(img.getWidth());
        canvas.getContext2d().drawImage(img, 0, 0);
    // img.getOwnerDocument().getBody().appendChild(canvas);
    }
    Context2d ctx = canvas.getContext2d();
    ImageData imageData = ctx.getImageData(startX, startY, width, height);
    CanvasPixelArray pixelData = imageData.getData();
    int i = 0;
    int dst = offset;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int r = pixelData.get(i++);
            int g = pixelData.get(i++);
            int b = pixelData.get(i++);
            int a = pixelData.get(i++);
            rgbArray[dst + x] = a << 24 | r << 16 | g << 8 | b;
        }
        dst += scanSize;
    }
}
Also used : CanvasPixelArray(com.google.gwt.canvas.dom.client.CanvasPixelArray) Context2d(com.google.gwt.canvas.dom.client.Context2d) ImageData(com.google.gwt.canvas.dom.client.ImageData)

Example 10 with Context2d

use of com.google.gwt.canvas.dom.client.Context2d in project gwt-cs by iSergio.

the class MarkerGroup method createBillboard.

public static BillboardOptions createBillboard(DrawInteractionOptions options) {
    Canvas canvas = Canvas.createIfSupported();
    Context2d context = canvas.getContext2d();
    context.setFillStyle(options.color.toCssColorString());
    context.setStrokeStyle(options.outlineColor.toCssColorString());
    context.setLineWidth(options.outlineWidth);
    context.translate(canvas.getCoordinateSpaceWidth() / 2, canvas.getCoordinateSpaceHeight() / 2);
    context.beginPath();
    context.arc(0, 0, options.pixelSize, 0, Math.PI * 2, true);
    context.closePath();
    context.stroke();
    context.fill();
    BillboardOptions billboard = new BillboardOptions();
    billboard.horizontalOrigin = HorizontalOrigin.CENTER();
    billboard.verticalOrigin = VerticalOrigin.CENTER();
    billboard.imageCanvas = canvas.getCanvasElement();
    return billboard;
}
Also used : BillboardOptions(org.cesiumjs.cs.scene.options.BillboardOptions) Context2d(com.google.gwt.canvas.dom.client.Context2d) Canvas(com.google.gwt.canvas.client.Canvas)

Aggregations

Context2d (com.google.gwt.canvas.dom.client.Context2d)11 Canvas (com.google.gwt.canvas.client.Canvas)3 CanvasPixelArray (com.google.gwt.canvas.dom.client.CanvasPixelArray)2 ImageData (com.google.gwt.canvas.dom.client.ImageData)2 CanvasElement (com.google.gwt.dom.client.CanvasElement)1 ImageElement (com.google.gwt.dom.client.ImageElement)1 AbsolutePanel (com.google.gwt.user.client.ui.AbsolutePanel)1 HTML (com.google.gwt.user.client.ui.HTML)1 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)1 TextMetrics (com.xenoage.utils.font.TextMetrics)1 Size2f (com.xenoage.utils.math.geom.Size2f)1 Size2i (com.xenoage.utils.math.geom.Size2i)1 Page (com.xenoage.zong.layout.Page)1 GwtCanvas (com.xenoage.zong.renderer.gwtcanvas.canvas.GwtCanvas)1 ResourceImageOptions (org.cesiumjs.cs.core.options.ResourceImageOptions)1 Entity (org.cesiumjs.cs.datasources.Entity)1 BillboardGraphics (org.cesiumjs.cs.datasources.graphics.BillboardGraphics)1 BillboardGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions)1 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)1 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)1