/** * Returns a WebGL context for the given canvas element. Returns null if no 3d * context is available. */ public static native WebGLRenderingContext getContext(CanvasElement canvas, WebGLContextAttributes attributes) /*-{ var names = ["webgl", "experimental-webgl", "moz-webgl", "webkit-webgl", "webkit-3d"]; for (var i = 0; i < names.length; i++) { try { var ctx = canvas.getContext(names[i], attributes); if (ctx != null) { // Hook for the semi-standard WebGLDebugUtils script. if ($wnd.WebGLDebugUtils) { if ($wnd.console && $wnd.console.log) console.log('WebGL debugging enabled'); return $wnd.WebGLDebugUtils.makeDebugContext(ctx); } return ctx; } } catch(e) { } } return null; }-*/;
/** * Creates a WebGL 1.0 context upon a canvas element 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>. * * @param canvas The canvas element to creeate the context upon. * @param attributes The context attributes to request the context with. * * @return The created WebGL context object. */ public static native WebGLContext createContext(CanvasElement canvas, WebGLContext.Attributes attributes) /*-{ try { if (attributes) $wnd.gl = canvas.getContext("webgl", attributes) || canvas.getContext("experimental-webgl", attributes); else $wnd.gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); $wnd.attribs = $wnd.gl.getContextAttributes(); $wnd.glv = 1.0; } catch (e) { alert(e); $wnd.alert("Your browser doesn't appear to support WebGL. Try upgrading your browser."); $wnd.location.href = 'http://get.webgl.org/'; } return $wnd.context = { gl: $wnd.gl, attribs: $wnd.attribs, glv: $wnd.glv }; }-*/;
public static native WebGLContext createContext(CanvasElement canvas, WebGLContext.Attributes attributes) /*-{ try { if (attributes) $wnd.gl = canvas.getContext("webgl2", attributes) || canvas.getContext("experimental-webgl2", attributes); else $wnd.gl = canvas.getContext("webgl2") || canvas.getContext("experimental-webgl2"); $wnd.attribs = $wnd.gl.getContextAttributes(); $wnd.glv = 2.0; } catch (e) { alert(e); $wnd.alert("Your browser doesn't appear to support WebGL 2. Try upgrading your browser."); $wnd.location.href = 'http://get.webgl.org/'; } return $wnd.context = { gl: $wnd.gl, attribs: $wnd.attribs, glv: $wnd.glv }; }-*/;
/** * Returns a WebGL context for the given canvas element. Returns null if no 3d * context is available. */ public static native WebGLRenderingContext getContext(CanvasElement canvas, WebGLContextAttributes attributes) /*-{ var names = ["experimental-webgl", "webgl", "moz-webgl", "webkit-webgl", "webkit-3d"]; for (var i = 0; i < names.length; i++) { try { var ctx = canvas.getContext(names[i], attributes); if (ctx != null) { // Hook for the semi-standard WebGLDebugUtils script. if ($wnd.WebGLDebugUtils) { if ($wnd.console && $wnd.console.log) console.log('WebGL debugging enabled'); return $wnd.WebGLDebugUtils.makeDebugContext(ctx); } return ctx; } } catch(e) { } } return null; }-*/;
private CanvasElement prepareMissingTileImage() { int tileSize = DjvuContext.getTileSize(); CanvasElement canvas = createImage(tileSize, tileSize); Context2d context2d = canvas.getContext2d(); context2d.setFillStyle("white"); context2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); Image image = new Image(); final ImageElement imageElement = image.getElement().cast(); imageElement.getStyle().setProperty("visibility", "hidden"); Event.setEventListener(imageElement, event -> { if (Event.ONLOAD == event.getTypeInt()) { missingTileImage.getContext2d().drawImage(imageElement, 0, 0); RootPanel.get().getElement().removeChild(imageElement); } }); RootPanel.get().getElement().appendChild(imageElement); image.setUrl(getBlankImageUrl()); return canvas; }
public void setTile(TileInfo tileInfo, GMap bufferGMap) { if (bufferImageData == null || bufferImageData.getWidth() != bufferGMap.getDataWidth() || bufferImageData.getHeight() != bufferGMap.getDataHeight()) { bufferImageData = bufferCanvas.getContext2d() .createImageData(bufferGMap.getDataWidth(), bufferGMap.getDataHeight()); } Uint8Array imageArray = bufferImageData.getData().cast(); imageArray.set(bufferGMap.getImageData()); bufferCanvas.getContext2d().putImageData(bufferImageData, -bufferGMap.getBorder(), 0); CanvasElement tile = tiles.get(tileInfo); if (tile == null) { tile = createImage(bufferGMap.getDataWidth() - bufferGMap.getBorder(), bufferGMap.getDataHeight()); tiles.put(new TileInfo(tileInfo), tile); } Context2d c = tile.getContext2d(); c.setFillStyle("white"); c.fillRect(0, 0, tileSize, tileSize); c.drawImage(bufferCanvas, 0, 0); for (Consumer<Integer> listener : tileListeners) listener.accept(tileInfo.page); }
public static CanvasElement createImage(int width, int height) { Canvas canvas = Canvas.createIfSupported(); canvas.setWidth(width + "px"); canvas.setCoordinateSpaceWidth(width); canvas.setHeight(height + "px"); canvas.setCoordinateSpaceHeight(height); return canvas.getCanvasElement(); }
/** from https://github.com/toji/game-shim/blob/master/game-shim.js * @param element Canvas */ private native void setCursorCatchedJSNI (CanvasElement element) /*-{ // Navigator pointer is not the right interface according to spec. // Here for backwards compatibility only if (!navigator.pointer) { navigator.pointer = navigator.webkitPointer || navigator.mozPointer; } // element.requestPointerLock if (!element.requestPointerLock) { element.requestPointerLock = (function() { return element.webkitRequestPointerLock || element.mozRequestPointerLock || function() { if (navigator.pointer) { navigator.pointer.lock(element); } }; })(); } element.requestPointerLock(); }-*/;
/** Returns a WebGL context for the given canvas element. Returns null if no 3d context is available. */ public static native WebGLRenderingContext getContext (CanvasElement canvas, WebGLContextAttributes attributes) /*-{ var names = ["experimental-webgl", "webgl", "moz-webgl", "webkit-webgl", "webkit-3d"]; for (var i = 0; i < names.length; i++) { try { var ctx = canvas.getContext(names[i], attributes); if (ctx != null) { // Hook for the semi-standard WebGLDebugUtils script. if ($wnd.WebGLDebugUtils) { if ($wnd.console && $wnd.console.log) console.log('WebGL debugging enabled'); return $wnd.WebGLDebugUtils.makeDebugContext(ctx); } return ctx; } } catch(e) { } } return null; }-*/;
/** * from https://github.com/toji/game-shim/blob/master/game-shim.js * * @param element Canvas */ private native void setCursorCatchedJSNI(CanvasElement element) /*-{ // Navigator pointer is not the right interface according to spec. // Here for backwards compatibility only if (!navigator.pointer) { navigator.pointer = navigator.webkitPointer || navigator.mozPointer; } // element.requestPointerLock if (!element.requestPointerLock) { element.requestPointerLock = (function() { return element.webkitRequestPointerLock || element.mozRequestPointerLock || function() { if (navigator.pointer) { navigator.pointer.lock(element); } }; })(); } element.requestPointerLock(); }-*/;
/** * Animate zoom and tranlate on the HTML5 canvas, after the DisplayArea has zoomed in. * * @param context * @param canvas_img * the CanvasElement of the canvas to be animated * @param cb * callback for when the animation completes * @param old_width * the width of the viewport before zoom * @param new_width * the width of the viewport after zoom, in the same coordinates as old_width * @param new_x * x coordinate of the new viewport center, relative to the HTML5 canvas * in the browser * @param new_y * y coordinate of the new viewport center, relative to the HTML5 canvas * in the browser */ public ZoomAnimation(Context2d context, CanvasElement canvas_img, AnimationCallback cb, int old_width, int new_width, int new_x, int new_y) { this.context = context; Canvas buffer = Canvas.createIfSupported(); Context2d buff_context = buffer.getContext2d(); buffer.setPixelSize(canvas_img.getWidth(), canvas_img.getHeight()); buffer.setCoordinateSpaceWidth(canvas_img.getWidth()); buffer.setCoordinateSpaceHeight(canvas_img.getHeight()); buff_context.drawImage(canvas_img, 0, 0); this.canvas_img = buff_context.getCanvas(); scale = (double) old_width / new_width; this.width_from = canvas_img.getWidth(); this.height_from = canvas_img.getHeight(); this.x_from = width_from / 2; this.y_from = height_from / 2; this.x_to = new_x; this.y_to = new_y; this.cb = cb; }
private void addAreaClickListener(final ColorfillAreaClickListener listener) { interactionHandlerFactory.applyUserClickHandler(new Command() { @Override public void execute(NativeEvent event) { event.preventDefault(); CanvasElement canvasElement = canvasStubView.getCanvas().getCanvasElement(); Area area = new Area(positionHelper.getXPositionRelativeToTarget(event, canvasElement), positionHelper.getYPositionRelativeToTarget(event, canvasElement)); if (area.getX() >= 0 && area.getY() >= 0) { listener.onAreaClick(area); } } }, canvasStubView.getCanvas()); }
public void onModuleLoad() { canvas = Canvas.createIfSupported(); if (canvas == null) { Window.alert("Canvas not supported"); return; } RootPanel.get("screen").add(canvas); CanvasElement el = canvas.getCanvasElement(); el.setWidth(960); el.setHeight(540); Context2d ctx = canvas.getContext2d(); setupContext(ctx); ctx.scale(3, 3); RootPanel.get().addDomHandler(this, KeyDownEvent.getType()); font = new Image("images/font.png"); fontElement = ImageElement.as(font.getElement()); audio = Audio.createIfSupported(); game = new Game(this); game.pushState(new WelcomeState(game)); new Timer() { @Override public void run() { game.handleEvent(); game.update(); game.draw(); } }.scheduleRepeating(50); }
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; }
HtmlCanvas(CanvasElement canvas, int width, int height) { this.canvas = canvas; this.width = width; this.height = height; canvas.setWidth(width); canvas.setHeight(height); ctx = canvas.getContext2d(); }
HtmlCanvasLayerDom(int width, int height) { super(Document.get().createCanvasElement()); CanvasElement canvas = element().cast(); canvas.setWidth(width); canvas.setHeight(height); this.canvas = new HtmlCanvas(canvas, width, height); }
HtmlCanvasLayerGL(HtmlGraphicsGL gfx, int width, int height) { super(gfx); 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); }
public void screenshot(String filename) { CanvasElement canvas = ((GwtApplication) Gdx.app).getCanvasElement(); // base64 encoded PNG file using data URL encoding! send this to your server String dataUrl = canvas.toDataUrl("image/png"); // just opening it in a new window, replace this with whatever you want to do with the data Window.open(dataUrl, "_blank", ""); }
public void drawOn(Context2d context, boolean isSelected) { if (redrawNecessary || lastSelected != isSelected) { redrawNecessary = false; CanvasElement el = canvas.getCanvasElement(); canvas.getContext2d().clearRect(0, 0, el.getWidth(), el.getHeight()); canvas.getCanvasElement().setWidth(rect.getWidth() + 1); // canvas size is +1px to make sure a rectangle with width pixels is still visible (in Swing the bound-checking happens in BaseDrawHandlerSwing because you cannot extend the clipping area) canvas.getCanvasElement().setHeight(rect.getHeight() + 1); drawer.drawAll(isSelected); if (isSelected) { metadrawer.drawAll(); } } lastSelected = isSelected; context.drawImage(canvas.getCanvasElement(), element.getRectangle().getX(), element.getRectangle().getY()); }
public CanvasElement[][] getTileImages(int pageNum, int subsample, GRect range, CanvasElement[][] reuse) { CanvasElement[][] result = reuse; int w = range.width() + 1, h = range.height() + 1; if (reuse == null || reuse.length != h || reuse[0].length != w) { result = new CanvasElement[h][w]; } tempTI.page = pageNum; tempTI.subsample = subsample; for (int y = range.ymin; y <= range.ymax; y++) for (int x = range.xmin; x <= range.xmax; x++) result[y - range.ymin][x - range.xmin] = getTileImage(tempTI.setXY(x, y)); return result; }
public void redraw() { Context2d graphics2d = canvas.getContext2d(); int w = canvas.getCoordinateSpaceWidth(), h = canvas.getCoordinateSpaceHeight(); graphics2d.setFillStyle(background); graphics2d.fillRect(0, 0, w, h); if (pageInfo == null) return; int subsample = toSubsample(zoom); double scale = zoom / toZoom(subsample); graphics2d.save(); int startX = w / 2 - centerX, startY = h / 2 - centerY; graphics2d.translate(startX, startY); graphics2d.scale(scale, scale); graphics2d.translate(-startX, -startY); graphics2d.scale(1, -1); // DjVu images have y-axis inverted int tileSize = DjvuContext.getTileSize(); int pw = (int) (pageInfo.width * zoom), ph = (int) (pageInfo.height * zoom); range.xmin = (int) (Math.max(0, centerX - w * 0.5) / tileSize / scale); range.xmax = (int) Math.ceil(Math.min(pw, centerX + w * 0.5) / tileSize / scale); range.ymin = (int) (Math.max(0, centerY - h * 0.5) / tileSize / scale); range.ymax = (int) Math.ceil(Math.min(ph, centerY + h * 0.5) / tileSize / scale); imagesArray = dataStore.getTileImages(page, subsample, range , imagesArray); for (int y = range.ymin; y <= range.ymax; y++) { for (int x = range.xmin; x <= range.xmax; x++) { CanvasElement canvasElement = imagesArray[y - range.ymin][x - range.xmin]; for (int repeats = scale == 1 ? 1 : 3; repeats > 0; repeats--) { graphics2d.drawImage(canvasElement, startX + x * tileSize, -startY - y * tileSize - canvasElement.getHeight()); } } } graphics2d.restore(); // missing tile graphics may exceed the page boundary graphics2d.fillRect(startX + pw, 0, w, h); graphics2d.fillRect(0, startY + ph, w, h); DjvuContext.setTileRange(range, subsample); }
private native void grabMouseImpl(boolean grabMouse, CanvasElement canvas) /*-{ if (grabMouse) { canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock; canvas.requestPointerLock(); } else { $doc.exitPointerLock = $doc.exitPointerLock || $doc.mozExitPointerLock; $doc.exitPointerLock(); } }-*/;
public static String getIDCode(String id) { Element el = Document.get().getElementById(id); if (el instanceof CanvasElement) { return el.getAttribute("data-idcode"); } return null; }
private static void drawStructure(String id, String idcode, String coordinates, int displayMode,String[] atomText) { Element el = Document.get().getElementById(id); if (el instanceof CanvasElement) { CanvasElement ce = (CanvasElement) el; StructureElement.drawIDCode(ce,idcode,coordinates, displayMode,atomText); } }
private static void draw(CanvasElement el, String idcode, String coordinates) { Canvas canvas = Canvas.wrap(el); if (idcode != null && idcode.length() > 0) { String combined = idcode + (coordinates != null ? " " + coordinates : ""); Context2d ctx = canvas.getContext2d(); drawMolecule(ctx, combined, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight()); } }
public static void drawIDCode(CanvasElement el, String idcode, String coordinates, int displayMode,String[] atomText) { Canvas canvas = Canvas.wrap(el); if (idcode != null && idcode.length() > 0) { String combined = idcode + (coordinates != null ? " " + coordinates : ""); Context2d ctx = canvas.getContext2d(); drawMolecule(ctx, combined, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight(), displayMode,atomText); } }
public static void drawMolecule(CanvasElement el, JSMolecule mol, int displayMode,String[] atomText) { Canvas canvas = Canvas.wrap(el); Context2d ctx = canvas.getContext2d(); drawMolecule(ctx, mol.getStereoMolecule(), canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight(), displayMode,atomText); }
@Override public void onModuleLoad() { document = RootPanel.getBodyElement().getOwnerDocument(); canvas = (CanvasElement) document.getElementById("benchmark-canvas"); resultTableBody = document.getElementById("result-table-body"); startMillisecond = System.currentTimeMillis(); makeStep(); }
/** * Creates the widget which is the HTML5 canvas. */ @Override protected Widget createWidget() { CanvasElement element = Document.get().createCanvasElement(); DiagramWidget diagramWidget = new DiagramWidget(this, element); diagramWidget.setStyleName("canvas-widget"); return diagramWidget; }
public static native PictureWidgetDriver create(VideoElement video, CanvasElement canvas, Element image) /*-{ return { video: video, canvas: canvas, image: image, streaming: false }; }-*/;
/** * Redraw the canvas with HTML5 animation * * @param old_width * width of viewport in base coordinates before any zoom * operations * @param center * optional (x, y) center coordinates. Coordinates are relative * to the HTML5 canvas in the broswer. */ public void animatedRedraw(int old_width, int... center) { CanvasElement canv = viewport_context.getCanvas(); int x = center.length == 2 ? center[0] : canv.getWidth() / 2; int y = center.length == 2 ? center[1] : canv.getHeight() / 2; Animation anim = new ZoomAnimation(viewport_context, canv, cb, old_width, area.viewportBaseWidth(), x, y); anim.run(400); }
/** * @return the canvas */ public final CanvasElement getCanvas() { return canvas; }
@Override public void buildPanel() { csVPanel = new ViewerPanel(); ListBox kmlLBox = new ListBox(); kmlLBox.addItem("KML - Global Science Facilities", GWT.getModuleBaseURL() + "SampleData/kml/facilities/facilities.kml"); kmlLBox.addItem("KMZ with embedded data - GDP per capita", GWT.getModuleBaseURL() + "SampleData/kml/gdpPerCapita2008.kmz"); kmlLBox.addItem("gx KML extensions - Bike Ride", GWT.getModuleBaseURL() + "SampleData/kml/bikeRide.kml"); kmlLBox.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent changeEvent) { reset(); ListBox source = (ListBox) changeEvent.getSource(); final Viewer viewer = csVPanel.getViewer(); org.cesiumjs.cs.scene.Camera camera = viewer.camera; CanvasElement canvas = viewer.canvas(); camera.flyHome(0); KmlDataSourceOptions kmlDataSourceOptions = new KmlDataSourceOptions();//camera, canvas); kmlDataSourceOptions.canvas = canvas; kmlDataSourceOptions.camera = camera; if (!source.getSelectedValue().contains("bikeRide")) { csVPanel.getViewer().dataSources().add(KmlDataSource.load(source.getSelectedValue(), kmlDataSourceOptions)); } else { csVPanel.getViewer().dataSources().add(KmlDataSource.load(source.getSelectedValue(), kmlDataSourceOptions)).then(new Fulfill<KmlDataSource>() { @Override public void onFulfilled(KmlDataSource dataSource) { viewer.clock().shouldAnimate = false; final Entity rider = dataSource.entities.getById("tour"); viewer.flyTo(rider).then(new Fulfill<Boolean>() { @Override public void onFulfilled(Boolean value) { viewer.trackedEntity = rider; viewer.selectedEntity = viewer.trackedEntity; viewer.clock().multiplier = 30; viewer.clock().shouldAnimate = true; } }); } }); } } }); AbsolutePanel aPanel = new AbsolutePanel(); aPanel.add(csVPanel); aPanel.add(kmlLBox, 20, 20); contentPanel.add(new HTML("<p>A simple KML example.</p>")); contentPanel.add(aPanel); initWidget(contentPanel); }
public HtmlImage (Graphics gfx, Scale scale, CanvasElement elem, String source) { super(gfx, scale, elem.getWidth(), elem.getHeight(), source, elem); this.canvas = elem; }
@Override protected Canvas createCanvasImpl(Scale scale, int pixelWidth, int pixelHeight) { CanvasElement elem = Document.get().createCanvasElement(); elem.setWidth(pixelWidth); elem.setHeight(pixelHeight); return new HtmlCanvas(this, new HtmlImage(this, scale, elem, "<canvas>")); }
public void glTexImage2D(int target, int level, int internalformat, int format, int type, CanvasElement image) { gl.texImage2D(target, level, internalformat, format, type, image); checkError("texImage2D"); }