mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-22 08:25:45 -07:00
js: Distinguish manual resizes from device pixel ratio changes
This adds a new callback, rescale_puzzle(), that's called when the device pixel ratio changes. This means that resize_puzzle() can safely set the nominal canvas size, which means that manual resizing of the puzzle now sticks. Still missing: paying attention to the device pixel ratio when choosing the initial (or reset) size.
This commit is contained in:
@ -535,12 +535,14 @@ function initPuzzle() {
|
||||
* <https://developer.mozilla.org/en-US/docs/Web/API/Window/
|
||||
* devicePixelRatio> (CC0) to work on older browsers.
|
||||
*/
|
||||
var rescale_puzzle = Module.cwrap('rescale_puzzle',
|
||||
'void', ['number', 'number']);
|
||||
var mql = null;
|
||||
var update_pixel_ratio = function() {
|
||||
var dpr = window.devicePixelRatio;
|
||||
if (mql !== null)
|
||||
mql.removeListener(update_pixel_ratio);
|
||||
resize_puzzle(nominal_width * dpr, nominal_height * dpr);
|
||||
rescale_puzzle(nominal_width * dpr, nominal_height * dpr);
|
||||
mql = window.matchMedia(`(resolution: ${dpr}dppx)`);
|
||||
mql.addListener(update_pixel_ratio);
|
||||
}
|
||||
|
Reference in New Issue
Block a user