deno-windowing / dwm

Deno Window Manager: Cross-platform window creation and management
https://deno.land/x/dwm
Apache License 2.0
138 stars 10 forks source link

Scale canvas to window size example #25

Open jakeklassen opened 1 year ago

jakeklassen commented 1 year ago

I'm not sure this is the proper place to ask, but does anyone have an example of how to best scale a Skia Canvas to match the window size?

For example, say I am making a game with a canvas size 128x128 and a window sized at 512x512 (so 4x), is there an easy way to auto scale (stretch) the canvas to the window size? I don't want to actually create a 512x512 canvas and the draw all the native 128x128 sprite at a larger resolution.

I'm basically after something like the transform: scale(4) you'd get with CSS.

nhrones commented 1 year ago

Skia-canvas has the same API surface as html-canvas. https://www.w3schools.com/tags/canvas_scale.asp

hashrock commented 10 months ago

so I guess we might need dwm version of window.devicePixelRatio to achieve that?

jakeklassen commented 8 months ago

@nhrones yeah that makes sense but I'm thinking more along the lines of:

canvas.style.transform = `scale(4)`;

Using the context API to scale a 128x128 canvas won't make the canvas fill the 512x512 window. Unless I am misunderstanding something. I'm thinking something along the lines of a window stretch mode that could be fill, etc. Not sure how to achieve that with this lib.

Hopefully that helps clear up my original question.