1j01 / jspaint

🎨 Classic MS Paint, REVIVED + ✨Extras
https://jspaint.app/about
MIT License
7.23k stars 563 forks source link

Ugly scaling on mobile #103

Open 1j01 opened 6 years ago

1j01 commented 6 years ago

On mobile, it looks like this for me currently:

Yuck. Pixels aren't square; some are tall, some are wide. Look at the icon for the rectangle tool, it's not even straight on the top and bottom!

I could do:

document.body.style.zoom = 1 / window.devicePixelRatio;

but I'm not sure what the implications of this might be; it might make buttons really small. It might confuse some code using getBoundingClientRect(), etc.

Also for screens that have a higher scale than 1.5, like 2 or more, it should almost certainly round down to the nearest integer.

1j01 commented 6 years ago

Also this should apply to 98, and I'm not sure how it might apply to jspaint when it's in an iframe; it might compound, which wouldn't be good.

1j01 commented 6 years ago
var updateZoomScale = function(){
    var desiredDPR = Math.floor(devicePixelRatio);
    document.body.style.zoom = desiredDPR / devicePixelRatio;
};
updateZoomScale();
var lastDPR = devicePixelRatio;
addEventListener("resize", function(){
    updateZoomScale();
    if(lastDPR !== devicePixelRatio){
        console.log("ur zoomin'");
        // TODO: show a message to users here to let them know the zoom is being counteracted to make it even numbers of pixels to avoid jaggedness, but only within.. buckets? slices? intervals? and they can zoom in or out further for it to change
    }
    lastDPR = devicePixelRatio;
});

This isn't enough. zoom breaks things.

On 98 it breaks at least:

On jspaint it breaks at least:

1j01 commented 4 years ago

I've implemented a compromise approach, where it chooses between disabling antialiasing or not based on whether it's an integer scaling size (or large enough that it doesn't matter that the pixels are uneven in size). (https://github.com/1j01/jspaint/commit/2a5206a2c5e9555ddaa55ed773850270f62115c7, https://github.com/1j01/jspaint/commit/ad4e5c7cadd5408a304b513659ae5dba862fd592, https://github.com/1j01/jspaint/commit/6ac691e9bdcc08bf4ffdc15cd03204c95ae706f5, and maybe a few other commits around that time frame)

It's not that good of a compromise because Chrome at least has this bug where it'll do horrible flickering between antialiased and aliased.

It's worth looking into making the canvas (and selections) scale w/ the magnification code I already have (apply an additional scalar anywhere magnification is used for scaling, to correct for non-integer devicePixelRatios), even tho the UI would still be blurry - the canvas is way more important than the blurriness of the UI. And then maybe scaling individual parts of the UI that I know won't break from code that calculates stuff based on the mouse position or the positions of elements.