Exemplo n.º 1
0
 @Override
 protected Canvas createCanvasImpl(Scale scale, int pixelWidth, int pixelHeight) {
   CanvasElement elem = Document.get().createCanvasElement();
   elem.setWidth(pixelWidth);
   elem.setHeight(pixelHeight);
   return new GWTCanvas(this, new GWTImage(this, scale, elem, "<canvas>"));
 }
Exemplo n.º 2
0
  @Override
  public void getRgb(
      int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
    Asserts.checkState(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;
    }
  }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 public void setSize(int width, int height) {
   rootElement.getStyle().setWidth(width, Unit.PX);
   rootElement.getStyle().setHeight(height, Unit.PX);
   canvas.setWidth(scale().scaledCeil(width));
   canvas.setHeight(scale().scaledCeil(height));
   canvas.getStyle().setWidth(width, Style.Unit.PX);
   canvas.getStyle().setHeight(height, Style.Unit.PX);
   viewportChanged(scale(), canvas.getWidth(), canvas.getHeight());
 }
Exemplo n.º 5
0
 @Override
 public boolean setDisplayMode(int width, int height, boolean fullscreen) {
   if (fullscreen) {
     if (width != getScreenWidthJSNI() && height != getScreenHeightJSNI()) return false;
     return setFullscreenJSNI(this, canvas);
   } else {
     if (isFullscreenJSNI()) exitFullscreen();
     canvas.setWidth(width);
     canvas.setHeight(height);
     return true;
   }
 }
Exemplo n.º 6
0
 @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);
 }
Exemplo n.º 7
0
  public ScratchCanvas(int wide, int high) {
    m_wide = wide;

    m_high = high;

    if (LienzoCore.IS_CANVAS_SUPPORTED) {
      m_element = Document.get().createCanvasElement();

      m_element.setWidth(wide);

      m_element.setHeight(high);

      m_context = new Context2D(m_element);
    } else {
      m_element = null;

      m_context = null;
    }
  }
  public GwtRenderingContext(Panel root, GwtAppConfiguration config)
      throws ParallaxRuntimeException {
    this.root = root;
    root.clear();

    Canvas canvasWidget = Canvas.createIfSupported();
    if (canvasWidget == null) throw new ParallaxRuntimeException("Canvas not supported");

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

    if (width == 0 || height == 0)
      new ParallaxRuntimeException("Width or Height of the Panel is 0");

    lastWidth = width;
    lastHeight = height;

    canvas = canvasWidget.getCanvasElement();
    root.add(canvasWidget);
    canvas.setWidth(width);
    canvas.setHeight(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, width, height);

    gl = new GwtGL20(context);

    renderer = new GLRenderer(gl, width, height);

    input = new GwtInput(canvas);

    addEventListeners();

    Window.addResizeHandler(this);
  }
Exemplo n.º 9
0
  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);
    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(false);
    attributes.setPremultipliedAlpha(false);
    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);
  }
Exemplo n.º 10
0
  public final void setPixelSize(int wide, int high) {
    m_element.setWidth(wide);

    m_element.setHeight(high);
  }
Exemplo n.º 11
0
 private void fullscreenChanged() {
   if (!isFullscreen()) {
     canvas.setWidth(config.width);
     canvas.setHeight(config.height);
   }
 }