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 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 = tileCache.tileSize;
    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 = tileCache.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];
        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);
  }
Exemplo n.º 11
0
 public HtmlImage(GLContext ctx, Scale scale, CanvasElement img) {
   super(ctx, scale);
   this.canvas = img;
   fakeComplete(img);
   this.img = img.cast();
 }
Exemplo n.º 12
0
 @Override
 public int getHeight() {
   return canvas.getHeight();
 }
Exemplo n.º 13
0
 private void fullscreenChanged() {
   if (!isFullscreen()) {
     canvas.setWidth(config.width);
     canvas.setHeight(config.height);
   }
 }
Exemplo n.º 14
0
  public GWTGraphics(final Panel panel, final LGame game, final GWTSetting cfg) {
    super(game, new GWTGL20(), new Scale(cfg.scaleFactor));

    this.config = cfg;
    Document doc = Document.get();
    this.dummyCanvas = doc.createCanvasElement();
    this.dummyCtx = dummyCanvas.getContext2d();

    Element root = panel.getElement();

    this.rootElement = root;

    measureElement = doc.createDivElement();
    measureElement.getStyle().setVisibility(Style.Visibility.HIDDEN);
    measureElement.getStyle().setPosition(Style.Position.ABSOLUTE);
    measureElement.getStyle().setTop(-500, Unit.PX);
    measureElement.getStyle().setOverflow(Style.Overflow.VISIBLE);
    measureElement.getStyle().setWhiteSpace(Style.WhiteSpace.NOWRAP);
    root.appendChild(measureElement);

    mouseScale = config.scaleFactor / Loon.devicePixelRatio();

    canvas = Document.get().createCanvasElement();
    root.appendChild(canvas);
    if (config.scaling()) {
      setSize(
          config.width_zoom > 0 ? config.width_zoom : root.getOffsetWidth(),
          config.height_zoom > 0 ? config.height_zoom : root.getOffsetHeight());
    } else {
      setSize(
          config.width > 0 ? config.width : root.getOffsetWidth(),
          config.height > 0 ? config.height : root.getOffsetHeight());
    }
    WebGLContextAttributes attrs = WebGLContextAttributes.create();
    attrs.setAntialias(config.antiAliasing);
    attrs.setStencil(config.stencil);
    attrs.setAlpha(config.transparentCanvas);
    attrs.setPremultipliedAlpha(config.premultipliedAlpha);
    attrs.setPreserveDrawingBuffer(config.preserveDrawingBuffer);

    WebGLRenderingContext glc = WebGLRenderingContext.getContext(canvas, attrs);
    if (glc == null) {
      throw new RuntimeException("Unable to create GL context");
    }

    ((GWTGL20) gl).init(glc);

    if (config.scaling()) {
      glc.viewport(0, 0, config.width_zoom, config.height_zoom);
    } else {
      glc.viewport(0, 0, config.width, config.height);
    }

    if (config.fullscreen) {
      Window.addResizeHandler(
          new ResizeHandler() {
            @Override
            public void onResize(ResizeEvent event) {
              if (getScreenWidthJSNI() == event.getWidth()
                  && getScreenHeightJSNI() == event.getHeight()) {
                float width = LSystem.viewSize.width(), height = LSystem.viewSize.height();
                experimentalScale =
                    Math.min(getScreenWidthJSNI() / width, getScreenHeightJSNI() / height);

                int yOfs = (int) ((getScreenHeightJSNI() - height * experimentalScale) / 3.f);
                int xOfs = (int) ((getScreenWidthJSNI() - width * experimentalScale) / 2.f);
                rootElement.setAttribute(
                    "style",
                    "width:"
                        + experimentalScale * width
                        + "px; "
                        + "height:"
                        + experimentalScale * height
                        + "px; "
                        + "position:absolute; left:"
                        + xOfs
                        + "px; top:"
                        + yOfs);
                Document.get().getBody().addClassName("fullscreen");
              } else {
                experimentalScale = 1;
                rootElement.removeAttribute("style");
                Document.get().getBody().removeClassName("fullscreen");
              }
            }
          });
    }

    Loon.self.addHandler(
        new OrientationChangedHandler() {
          @Override
          public void onChanged(Orientation newOrientation) {
            int width = Loon.self.getContainerWidth();
            int height = Loon.self.getContainerHeight();
            game.log().info("update screen size width :" + width + " height :" + height);
            setSize(width, height);
          }
        });
  }
Exemplo n.º 15
0
  public final void setPixelSize(int wide, int high) {
    m_element.setWidth(wide);

    m_element.setHeight(high);
  }
Exemplo n.º 16
0
 @Override
 public int getWidth() {
   return canvas.getWidth();
 }
Exemplo n.º 17
0
 public final void gwtSetImageAt(int index, CanvasElement element) {
   getImages().set(index, (ImageElement) element.cast());
 }