Frage

I have a website where I want to integrate a GWT canvas in the main layer. When I resize the browser window, I want the canvas "visible area" to resize accordingly, BUT not it's content. Somehow like in google maps where I just can see portions of what has been drawn.

canvas.setSize(..)
canvas.setCoordinateSpaceHeight(..);
canvas.setCoordinateSpaceWidth(..);

What do I have to set in order to

  • always resize the canvas according to the browser window
  • not having it's content resized?
War es hilfreich?

Lösung

All three properties.

You want to setSize to resize the canvas, and you want to make the coordinate space (the "inner size" of the canvas) the same as its size (its "external size"), or within the same ratio as before the resize.

If you start with a 300×200 canvas with a 300×200 coordinate space (so that a pixel in Context2D maps to a CSS pixel) and you need to resize the canvas to 600×400, then set you want to set the coordinate space to 600×400 too to keep the 1 canvas pixel == 1 CSS pixel ratio.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top