mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:17:44 +00:00
PixelPaint: Add lasso selection tool
Lasso selection works by allowing the user to draw an arbitrary shape much like the pen tool and ensuring the shape is closed by connecting the start/end points when the user is done drawing. Everything inside the shape becomes the selection. Selection is determined via an outer flood fill. We begin a flood fill from a point that is guaranteed to be outside of the drawn shape, and anything the fill doesn't touch is determined to be the selection region.
This commit is contained in:
parent
dc5402f61e
commit
3d542b0c38
5 changed files with 281 additions and 0 deletions
47
Userland/Applications/PixelPaint/Tools/LassoSelectTool.h
Normal file
47
Userland/Applications/PixelPaint/Tools/LassoSelectTool.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Timothy Slater <tslater2006@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Selection.h"
|
||||
#include "Tool.h"
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
|
||||
namespace PixelPaint {
|
||||
|
||||
class LassoSelectTool final : public Tool {
|
||||
public:
|
||||
LassoSelectTool() = default;
|
||||
virtual ~LassoSelectTool() = default;
|
||||
|
||||
virtual void on_mousedown(Layer*, MouseEvent& event) override;
|
||||
virtual void on_mouseup(Layer*, MouseEvent& event) override;
|
||||
virtual void on_mousemove(Layer*, MouseEvent& event) override;
|
||||
virtual bool on_keydown(GUI::KeyEvent const&) override;
|
||||
virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
|
||||
private:
|
||||
virtual StringView tool_name() const override { return "Lasso Select Tool"sv; }
|
||||
void flood_lasso_selection(Gfx::Bitmap&, Gfx::IntPoint);
|
||||
|
||||
RefPtr<GUI::Widget> m_properties_widget;
|
||||
Selection::MergeMode m_merge_mode { Selection::MergeMode::Set };
|
||||
|
||||
Gfx::IntPoint m_start_position;
|
||||
Gfx::IntPoint m_most_recent_position;
|
||||
RefPtr<Gfx::Bitmap> m_selection_bitmap;
|
||||
RefPtr<Gfx::Bitmap> m_preview_bitmap;
|
||||
|
||||
Gfx::IntPoint m_top_left;
|
||||
Gfx::IntPoint m_bottom_right;
|
||||
|
||||
bool m_selecting { false };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue