/** Kindly borrowed from PlayN. **/ protected int getRelativeX (NativeEvent e, CanvasElement target) { float xScaleRatio = target.getWidth() * 1f / target.getClientWidth(); // Correct for canvas CSS scaling return Math.round(xScaleRatio * (e.getClientX() - target.getAbsoluteLeft() + target.getScrollLeft() + target.getOwnerDocument().getScrollLeft())); }
/** Kindly borrowed from PlayN. **/ protected int getRelativeY (NativeEvent e, CanvasElement target) { float yScaleRatio = target.getHeight() * 1f / target.getClientHeight(); // Correct for canvas CSS scaling return Math.round(yScaleRatio * (e.getClientY() - target.getAbsoluteTop() + target.getScrollTop() + target.getOwnerDocument().getScrollTop())); }
protected int getRelativeX (Touch touch, CanvasElement target) { float xScaleRatio = target.getWidth() * 1f / target.getClientWidth(); // Correct for canvas CSS scaling return Math.round(xScaleRatio * touch.getRelativeX(target)); }
private HtmlCanvas(CanvasElement canvas, float width, float height) { this(canvas.getContext2d(), canvas, width, height); canvas.setWidth(MathUtil.iceil(width)); canvas.setHeight(MathUtil.iceil(height)); }
/** * Sizes or resizes the root element that contains the game view. This is specified in pixels as * understood by page elements. If the page is actually being dispalyed on a HiDPI (Retina) * device, the actual framebuffer may be 2x (or larger) the specified size. */ public void setSize (int width, int height) { rootElement.getStyle().setWidth(width, Unit.PX); rootElement.getStyle().setHeight(height, Unit.PX); // the frame buffer may be larger (or smaller) than the logical size, depending on whether // we're on a HiDPI display, or how the game has configured things (maybe they're scaling down // from native resolution to improve performance) Scale fbScale = new Scale(frameBufferPixelRatio); canvas.setWidth(fbScale.scaledCeil(width)); canvas.setHeight(fbScale.scaledCeil(height)); // set the canvas's CSS size to the logical size; the browser works in logical pixels canvas.getStyle().setWidth(width, Style.Unit.PX); canvas.getStyle().setHeight(height, Style.Unit.PX); viewportChanged(canvas.getWidth(), canvas.getHeight()); }
@Override public void setPixelSize(int wide, int high) { if (LienzoGlobals.getInstance().isCanvasSupported()) { super.setPixelSize(wide, high); CanvasElement element = getCanvasElement(); element.setHeight(high); element.setWidth(wide); element.getStyle().setPosition(Position.ABSOLUTE); element.getStyle().setDisplay(Display.INLINE_BLOCK); } }
/** * Native call to capture the frame of the video stream. */ 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); }
@Override protected Pattern toSubPattern(AbstractImageGL<?> image, boolean repeatX, boolean repeatY, float x, float y, float width, float height) { CanvasElement canvas = Document.get().createElement("canvas").<CanvasElement>cast(); canvas.setWidth(MathUtil.iceil(width)); canvas.setHeight(MathUtil.iceil(height)); canvas.getContext2d().drawImage(img, x, y, width, height, 0, 0, width, height); ImageElement subelem = canvas.cast(); return new HtmlPattern(image, subelem, repeatX, repeatY); }
@Override public int getBackBufferWidth () { return canvas.getWidth(); }
@Override public void setCursor (Cursor cursor) { ((GwtApplication)Gdx.app).graphics.canvas.getStyle().setProperty("cursor", ((GwtCursor)cursor).cssCursorProperty); }
/** * Sets the height of the internal canvas coordinate space. * * @param height the height, in pixels * @see #getCoordinateSpaceHeight() */ public void setCoordinateSpaceHeight(int height) { getCanvasElement().setHeight(height); }
@Override public CanvasBuilder width(int width) { assertCanAddAttribute().setWidth(width); return this; } }
@Override public int getHeight () { return canvas.getHeight(); }
/** * Returns a 2D rendering context. * * This is a convenience method, see {@link #getContext(String)}. * * @return a 2D canvas rendering context */ public Context2d getContext2d() { return getCanvasElement().getContext2d(); }
protected int getRelativeY (Touch touch, CanvasElement target) { float yScaleRatio = target.getHeight() * 1f / target.getClientHeight(); // Correct for canvas CSS scaling return Math.round(yScaleRatio * touch.getRelativeY(target)); }
cssCursorProperty += pixmap.getCanvasElement().toDataUrl("image/png"); cssCursorProperty += "')"; cssCursorProperty += xHotspot;