News for hackers. Stuff that matters.
Re:It's always been you, Canvas2D by moron4hire on Friday March 04, 2022 @03:20PM (#30559937)
Zooming also fires the Window's `resize` event, which will also catch a user rotating their smartphone/tablet, or, erh, resizing the window on desktop.
Re:It's always been you, Canvas2D by leeoniya on Friday March 04, 2022 @03:43PM (#30560276)
resize and orientationchange don't change devicePixelRatio though, so they're somewhat different concerns.
Re:It's always been you, Canvas2D by moron4hire on Friday March 04, 2022 @07:04PM (#30562326)
No, it's the same concern. The concern is not "how do I keep track of just devicePixelRatio?" It's "how do I fill this window with a canvas at native resolution?" Resize handles all of that. Device changes orientation? Resize fires. User zooms on content (this changing devicePixelRatio)? Resize fires. Anything that changes the page's clientWidth/clientHeight causes the Resize event to fire. You need only the one event.
Re:It's always been you, Canvas2D by Dylan16807 on Friday March 04, 2022 @09:39PM (#30563597)
> The concern is not "how do I keep track of just devicePixelRatio?" It's "how do I fill this window with a canvas at native resolution?"

Not everyone's canvas is filling the window.

Re:It's always been you, Canvas2D by moron4hire on Friday March 04, 2022 @10:32PM (#30563956)
All the ways in which you will care about how to buffer dimensions of your canvas to avoid aliasing artifacts can be handled with just the window.onresize event, whether your canvas is fixed or proportionally sized.

https://codepen.io/SeanMcBeth/pen/QWOoLNX

Throw a check in there to make sure the native dimensions actually did change so you don't needlessly redraw. Debounce it with setTimeout if you're super worried about people waggling their windows around or whatever.