1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

PixelPaint: Add Polygonal Select Tool

Polygonal selection tool allows for the drawing of any arbitrary
polygonal shape. It tracks clicked points in a vector, upon double
clicking we finalize the polygon and generate the selection mask. The
user can press the escape key during selection to cancel.

The 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.
This commit is contained in:
Timothy Slater 2022-09-02 15:50:47 -05:00 committed by Linus Groh
parent 20f6485311
commit 038a833f0c
5 changed files with 269 additions and 0 deletions

View file

@ -16,6 +16,7 @@
#include "Tools/MoveTool.h"
#include "Tools/PenTool.h"
#include "Tools/PickerTool.h"
#include "Tools/PolygonalSelectTool.h"
#include "Tools/RectangleSelectTool.h"
#include "Tools/RectangleTool.h"
#include "Tools/SprayTool.h"
@ -83,6 +84,7 @@ void ToolboxWidget::setup_tools()
add_tool("zoom"sv, { 0, Key_Z }, make<ZoomTool>());
add_tool("rectangle-select"sv, { 0, Key_R }, make<RectangleSelectTool>());
add_tool("wand-select"sv, { 0, Key_W }, make<WandSelectTool>());
add_tool("polygonal-select"sv, { Mod_Shift, Key_P }, make<PolygonalSelectTool>());
add_tool("guides"sv, { 0, Key_G }, make<GuideTool>());
add_tool("clone"sv, { 0, Key_C }, make<CloneTool>());
}