WeslomPo, thanks for the code (and thanks for the efla function, it's faster than what I use).
Why if you have a layer on top the preview is incorrectly drawn over that layer is not problem for my code?Because my code draw buffer to tileset first, then draw buffered tileset on layer (not on screen). If you have layer over current, you need only redraw it, if it needed.
But if two layers have the tile in them, I need to update both layers (or layer previews) during the stroke. I still don't understand how to do that with correct occlusion. (again, sorry if I'm misunderstanding)
Lay1 Lay2 Lay3
0000 0000 0000
0110 0000 0000
0110 0110 0022
0000 0110 0022
If I'm drawing on tile1 in layer1 (bottom layer), I need to update that tile in both layer1 and layer2. If tile2 is only
partly covering then the stroke preview need to be partly updated "under" that tile.
There would need to be separate preview buffers for each layer or something.
Or (which is what I'm currently considering) there can be a grayscale buffer ("cover buffer") that stores how much color has been applied to each screen pixel. When drawing pixels I can check this buffer to see whether a pixel is already drawn to or not.
This buffer can store a binary value per pixel 1/0, or it can store a range 0-255 to allow for drawing with flow (adding color continuously during the stroke until a pixel reaches 255).
Then the stroke would not be stored in a buffer. The pixels would be changed directly in the layers but the buffer limits their value. This means it would work nice with my current tile pixel update system.
Sadly though I don't have any time to work on it right now, so I have to wait to try it out.