HaikuArchives / ArtPaint

ArtPaint is a painting and image processing program.
https://haikuarchives.github.io/ArtPaint/
29 stars 18 forks source link

ColorSelector: Draw a box showing the size of the color sample #457

Closed dsizzle closed 1 year ago

dsizzle commented 1 year ago

Fixes #325

I'm sure it would be desirable to show the sample square even when the mouse button isn't down, but that isn't the way ArtPaint works right now. Same problem with #304 - "tools" in ArtPaint only operate at all when you press the mouse.

of course with code all things are possible... ;D

humdingerb commented 1 year ago

Nice! There seems to be an off-by-1 error, or better 2 off-by-0.5 errors...:

size4

This is with a "size" of 4. The sampling seems to take an additional half-pixel all around.

humdingerb commented 1 year ago

To add: A size of 1 shows the sampling box is centered on the top left corner of a pixel. Shouldn't it center on the center? Now it appears as if you sample the 4 "half-pixels" around the mouse pointer, when in fact the one on the bottom right is sampled. A visual...:

1px

dsizzle commented 1 year ago

Hmm, also looking at the 4px example maybe it’s not 0.5 all around, but rather it just needs to be shifted down and right by 0.5 ? The pointer doesn’t look centered in that case (although it does in the 1px case)

humdingerb commented 1 year ago

That is just a result of being zoomed in so much that you can move the mouse pointer around within the area of one pixel and the samplebox only jumping to the next pixel-border when you cross over to the next pixel. If you know what I mean... video: http://0x0.st/oFaS.mpg

dsizzle commented 1 year ago

this was a bit harder than I thought - can you please give it a try? I think it's working.

humdingerb commented 1 year ago

Almost. Works nicely with all sizes >1. Maybe a 1-pixel sample box needs special casing (?), as the box picks the pixel one pixel to the top and left of the one under the mouse pointer: screenshot1

dsizzle commented 1 year ago

Odd, 1 pixel worked fine for me. I guess I’ll try it again tomorrow.

dsizzle commented 1 year ago

Ok, it should be fixed now. I also changed the sampling. It was doing some weird square root distance thing and wasn't getting all the pixels. I changed it to just average all the pixels in the square.

humdingerb commented 1 year ago

Yep. Works perfectly now, thanks!

dsizzle commented 1 year ago

It occurred to me that perhaps the old method was trying to do a circular sample rather than square - but imo not sure if that’s useful or intuitive in a pixel drawing app?

humdingerb commented 1 year ago

Yeah, I think going with a square sampling box is a good decision, because we end up with whole pixels being in/outside the sampling.