summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Applications/PixelPaint/CMakeLists.txt1
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.cpp3
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.h6
-rw-r--r--Userland/Applications/PixelPaint/RectangleSelectTool.cpp3
-rw-r--r--Userland/Applications/PixelPaint/Selection.cpp18
-rw-r--r--Userland/Applications/PixelPaint/Selection.h30
6 files changed, 61 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/CMakeLists.txt b/Userland/Applications/PixelPaint/CMakeLists.txt
index e937c025f3..d18d3c47bc 100644
--- a/Userland/Applications/PixelPaint/CMakeLists.txt
+++ b/Userland/Applications/PixelPaint/CMakeLists.txt
@@ -21,6 +21,7 @@ set(SOURCES
PixelPaintWindowGML.h
RectangleTool.cpp
RectangleSelectTool.cpp
+ Selection.cpp
SprayTool.cpp
ToolboxWidget.cpp
ToolPropertiesWidget.cpp
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp
index 58a1da317b..b4a543a247 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.cpp
+++ b/Userland/Applications/PixelPaint/ImageEditor.cpp
@@ -95,6 +95,9 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
if (m_active_layer) {
painter.draw_rect(enclosing_int_rect(image_rect_to_editor_rect(m_active_layer->relative_rect())).inflated(2, 2), Color::Black);
}
+
+ if (!m_selection.is_empty())
+ m_selection.paint(painter, *this);
}
Gfx::FloatRect ImageEditor::layer_rect_to_editor_rect(Layer const& layer, Gfx::IntRect const& layer_rect) const
diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h
index 9606402f5e..f57f040a64 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.h
+++ b/Userland/Applications/PixelPaint/ImageEditor.h
@@ -7,6 +7,7 @@
#pragma once
#include "Image.h"
+#include "Selection.h"
#include <LibGUI/Frame.h>
#include <LibGUI/UndoStack.h>
#include <LibGfx/Point.h>
@@ -53,6 +54,9 @@ public:
Color secondary_color() const { return m_secondary_color; }
void set_secondary_color(Color);
+ Selection& selection() { return m_selection; }
+ Selection const& selection() const { return m_selection; }
+
Color color_for(GUI::MouseEvent const&) const;
Color color_for(GUI::MouseButton) const;
@@ -105,6 +109,8 @@ private:
Gfx::FloatPoint m_pan_origin;
Gfx::FloatPoint m_saved_pan_origin;
Gfx::IntPoint m_click_position;
+
+ Selection m_selection;
};
}
diff --git a/Userland/Applications/PixelPaint/RectangleSelectTool.cpp b/Userland/Applications/PixelPaint/RectangleSelectTool.cpp
index 6a9dc62e69..820bb4219f 100644
--- a/Userland/Applications/PixelPaint/RectangleSelectTool.cpp
+++ b/Userland/Applications/PixelPaint/RectangleSelectTool.cpp
@@ -58,6 +58,9 @@ void RectangleSelectTool::on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&
m_selecting = false;
m_editor->update();
+
+ auto rect_in_image = Gfx::IntRect::from_two_points(m_selection_start, m_selection_end);
+ m_editor->selection().set(rect_in_image);
}
void RectangleSelectTool::draw_marching_ants(Gfx::Painter& painter, Gfx::IntRect const& rect) const
diff --git a/Userland/Applications/PixelPaint/Selection.cpp b/Userland/Applications/PixelPaint/Selection.cpp
new file mode 100644
index 0000000000..db93e751f0
--- /dev/null
+++ b/Userland/Applications/PixelPaint/Selection.cpp
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "Selection.h"
+#include "ImageEditor.h"
+#include <LibGfx/Painter.h>
+
+namespace PixelPaint {
+
+void Selection::paint(Gfx::Painter& painter, ImageEditor const& editor)
+{
+ painter.draw_rect(editor.image_rect_to_editor_rect(m_rect).to_type<int>(), Color::Magenta);
+}
+
+}
diff --git a/Userland/Applications/PixelPaint/Selection.h b/Userland/Applications/PixelPaint/Selection.h
new file mode 100644
index 0000000000..e852f07da4
--- /dev/null
+++ b/Userland/Applications/PixelPaint/Selection.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibGfx/Rect.h>
+
+namespace PixelPaint {
+
+class ImageEditor;
+
+// Coordinates are image-relative.
+class Selection {
+public:
+ Selection() { }
+
+ bool is_empty() const { return m_rect.is_empty(); }
+ void clear() { m_rect = {}; }
+ void set(Gfx::IntRect const& rect) { m_rect = rect; }
+
+ void paint(Gfx::Painter&, ImageEditor const&);
+
+private:
+ Gfx::IntRect m_rect;
+};
+
+}