serenity icon indicating copy to clipboard operation
serenity copied to clipboard

PixelPaint: Polygonal select tool

Open tslater2006 opened this issue 3 years ago • 8 comments

This adds a polygonal selection tool where the user can make an initial click for the starting point of the shape and then subsequent clicks add vertexes. Double clicking completes the shape by connecting the last point to the first one. Pressing escape during selection cancels the selection. Details of how the mask is generated are below.

This PR also includes a few smaller commits that address some bugs in the Wand Tool and the "Delete Selection" logic. For the Wand Tool, there was an issue of the selection not accounting for the layer being offset from (0,0).

Wand Tool also wasn't listening for the Esc key to clear the selection.

For the "Delete Selection" bug, a selection can go outside of the layer bounds (rectangle selection, and polygon selection), attempting to delete all pixels in the selection was not checking to see if the selection was in the bitmap for the layer.

The polygonal mask is generated as follows:

  • First we calculate the size of the bounding rect needed to hold the polygon
  • We add 2 pixels to height/width to allow us a 1 pixel border, the polygon will be centered in this bitmap
  • Draw the polygon into the bitmap via Gfx::Painter, making sure to connect final polygon point to the first to ensure an enclosed shape
  • Generate a selection mask the size of the bitmap, with all pixels initially selected
  • Perform a flood fill from (0,0) which is guaranteed to be outside the polygon
  • For every pixel reached by the flood fill, we clear the selected pixel from the selection mask
  • Finally we merge the selection mask like other selection tools.

tslater2006 avatar Sep 02 '22 22:09 tslater2006

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

stale[bot] avatar Sep 25 '22 13:09 stale[bot]

I've rebased this on latest master.

tslater2006 avatar Sep 28 '22 12:09 tslater2006

If you've not post this in #code-review again to try to get some maintainers eyes on it. It's easy for PRs to get lost after a while.

MacDue avatar Sep 29 '22 21:09 MacDue

Thanks for taking the time to go through this. I posted in code-review yesterday. I will work on addressing these tonight/tomorrow.

tslater2006 avatar Sep 29 '22 21:09 tslater2006

@tslater2006 this has conflicts unfortunately, please rebase :)

linusg avatar Oct 14 '22 12:10 linusg

I'm out of town for the next few days but as soon as I get back I will rebate and update this to use the just-landed flood fill in LibGfx. Thanks!

tslater2006 avatar Oct 14 '22 14:10 tslater2006

Rebased and conflicts resolved @linusg.

tslater2006 avatar Oct 17 '22 17:10 tslater2006

Removed conflicting commit :)

tslater2006 avatar Oct 18 '22 17:10 tslater2006