1j01 / jspaint

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

"Browser cleared canvas" message appears every action while image is empty #203

Open CST1229 opened 3 years ago

CST1229 commented 3 years ago

Basically, the "the browser may have cleared the canvas due to memory leaks" message shows up every action I do while the image is empty with transparency. This happens not only if it actually cleared the canvas to memory leaks (the intended behavior), but also when it was done intentionally, i.e choosing the "Clear Canvas" option.

1j01 commented 3 years ago

Yep, I figured it was more important to include this dialog than to get the condition exactly right. I'm not sure of a good way to exclude cases where the image is supposed to be completely transparent. I thought of having an extra canvas to test if it becomes blank when memory is cleared, but it turns out individual canvases can be cleared while leaving others in tact, and bigger ones probably get cleared first, and I don't really want a giant canvas taking up memory in order to detect when memory gets cleared because then it'll get cleared earlier, and it might be unreliable anyways. Probably there needs to be some flag that's maintained of whether it's supposed to be blank or not, and canvas-clearing operations set it, and then it only gets reset when (after any operation) the canvas stops being blank. But what is a canvas-clearing operation? Image > Clear Image sure, but also deleting a selection sometimes, or dragging a selection off the canvas, or using the Fill tool to fill with transparency. Basically it's a surprisingly complicated problem, and not very interesting. Other options include making the dialog less alarming, maybe starting with "Did you mean to clear the canvas?" or something

Tubaleviao commented 3 years ago

Oh, is that why the transparency settings is not abled by default? I was wondering why the transparency is not listed as a color at the colors bar.

1j01 commented 2 years ago

@Tubaleviao No, transparency is not the default simply to match MS Paint and because it's more intuitive to have the document be opaque: with an opaque document, you can be guaranteed (basically) of the look of the image, but with a transparent document, it may appear invisible in some scenarios (black on black or white on white). Also, whilst it's possible to load transparent/translucent colors into the palette, currently there is no "overwrite" blending mode, so fully transparent is useless as a color, as it doesn't affect the image.