summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint/Selection.h
diff options
context:
space:
mode:
authorDavipb <daviparca@gmail.com>2021-06-20 10:53:41 -0300
committerAndreas Kling <kling@serenityos.org>2021-06-22 11:00:00 +0200
commit22585e2845c0b9a3ea7799f576239a5478a18050 (patch)
tree5b22e29baa67a2e040b3695e869bccb19c3e74de /Userland/Applications/PixelPaint/Selection.h
parentd922e35579bd0a51e625fd81aebadc51af3cf7a3 (diff)
downloadserenity-22585e2845c0b9a3ea7799f576239a5478a18050.zip
PixelPaint: Expose more complex selection operations
Now that we use RectMask internally to store the selection, we can expose more powerful APIs to allow for better control over the image selection.
Diffstat (limited to 'Userland/Applications/PixelPaint/Selection.h')
-rw-r--r--Userland/Applications/PixelPaint/Selection.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/Userland/Applications/PixelPaint/Selection.h b/Userland/Applications/PixelPaint/Selection.h
index f521421f7f..4080b9c09e 100644
--- a/Userland/Applications/PixelPaint/Selection.h
+++ b/Userland/Applications/PixelPaint/Selection.h
@@ -18,13 +18,28 @@ class ImageEditor;
// Coordinates are image-relative.
class Selection {
public:
+ enum class MergeMode {
+ Set,
+ Add,
+ Subtract,
+ Intersect,
+ __Count,
+ };
+
explicit Selection(ImageEditor&);
bool is_empty() const { return m_mask.is_null(); }
void clear();
- void set(Gfx::IntRect const& rect) { m_mask = Mask::full(rect); }
+ void merge(Mask const&, MergeMode);
+ void merge(Gfx::IntRect const& rect, MergeMode mode) { merge(Mask::full(rect), mode); }
Gfx::IntRect bounding_rect() const { return m_mask.bounding_rect(); }
+ [[nodiscard]] bool is_selected(int x, int y) const { return m_mask.get(x, y) > 0; }
+ [[nodiscard]] bool is_selected(Gfx::IntPoint const& point) const { return is_selected(point.x(), point.y()); }
+
+ [[nodiscard]] u8 get_selection_alpha(int x, int y) const { return m_mask.get(x, y); }
+ [[nodiscard]] u8 get_selection_alpha(Gfx::IntPoint const& point) const { return get_selection_alpha(point.x(), point.y()); }
+
void paint(Gfx::Painter&);
void draw_marching_ants(Gfx::Painter&, Gfx::IntRect const&) const;