summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-08-21 20:25:52 +0200
committerAndreas Kling <kling@serenityos.org>2022-08-21 20:33:01 +0200
commit101eb53de5497239e8ffc0afa6dc488c4d4521a4 (patch)
tree3443c7083fd6519c1821e1e2ce02c34c5b531bd0
parentc45f99f735316564115f787cb4fb93bad8c16437 (diff)
downloadserenity-101eb53de5497239e8ffc0afa6dc488c4d4521a4.zip
PixelPaint: Add Tool::tool_name() as a single-point-of-truth
Let the tools know what their names are.
-rw-r--r--Userland/Applications/PixelPaint/ToolboxWidget.cpp32
-rw-r--r--Userland/Applications/PixelPaint/Tools/BrushTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/BucketTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/CloneTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/EllipseTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/EraseTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/GuideTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/LineTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/MoveTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/PenTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/PickerTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/RectangleSelectTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/RectangleTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/SprayTool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/Tool.h2
-rw-r--r--Userland/Applications/PixelPaint/Tools/ZoomTool.h2
16 files changed, 46 insertions, 16 deletions
diff --git a/Userland/Applications/PixelPaint/ToolboxWidget.cpp b/Userland/Applications/PixelPaint/ToolboxWidget.cpp
index 179b3e563e..481aca55c6 100644
--- a/Userland/Applications/PixelPaint/ToolboxWidget.cpp
+++ b/Userland/Applications/PixelPaint/ToolboxWidget.cpp
@@ -49,8 +49,8 @@ ToolboxWidget::ToolboxWidget()
void ToolboxWidget::setup_tools()
{
- auto add_tool = [&](String name, StringView icon_name, GUI::Shortcut const& shortcut, NonnullOwnPtr<Tool> tool) {
- auto action = GUI::Action::create_checkable(move(name), shortcut, Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/pixelpaint/{}.png", icon_name)).release_value_but_fixme_should_propagate_errors(),
+ auto add_tool = [&](StringView icon_name, GUI::Shortcut const& shortcut, NonnullOwnPtr<Tool> tool) {
+ auto action = GUI::Action::create_checkable(tool->tool_name(), shortcut, Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/pixelpaint/{}.png", icon_name)).release_value_but_fixme_should_propagate_errors(),
[this, tool = tool.ptr()](auto& action) {
if (action.is_checked()) {
on_tool_selection(tool);
@@ -69,20 +69,20 @@ void ToolboxWidget::setup_tools()
m_tools.append(move(tool));
};
- add_tool("Move", "move"sv, { 0, Key_M }, make<MoveTool>());
- add_tool("Pen", "pen"sv, { 0, Key_N }, make<PenTool>());
- add_tool("Brush", "brush"sv, { 0, Key_P }, make<BrushTool>());
- add_tool("Bucket Fill", "bucket"sv, { Mod_Shift, Key_B }, make<BucketTool>());
- add_tool("Spray", "spray"sv, { Mod_Shift, Key_S }, make<SprayTool>());
- add_tool("Color Picker", "picker"sv, { 0, Key_O }, make<PickerTool>());
- add_tool("Erase", "eraser"sv, { Mod_Shift, Key_E }, make<EraseTool>());
- add_tool("Line", "line"sv, { Mod_Ctrl | Mod_Shift, Key_L }, make<LineTool>());
- add_tool("Rectangle", "rectangle"sv, { Mod_Ctrl | Mod_Shift, Key_R }, make<RectangleTool>());
- add_tool("Ellipse", "circle"sv, { Mod_Ctrl | Mod_Shift, Key_E }, make<EllipseTool>());
- add_tool("Zoom", "zoom"sv, { 0, Key_Z }, make<ZoomTool>());
- add_tool("Rectangle Select", "rectangle-select"sv, { 0, Key_R }, make<RectangleSelectTool>());
- add_tool("Guides", "guides"sv, { 0, Key_G }, make<GuideTool>());
- add_tool("Clone Tool", "clone"sv, { 0, Key_C }, make<CloneTool>());
+ add_tool("move"sv, { 0, Key_M }, make<MoveTool>());
+ add_tool("pen"sv, { 0, Key_N }, make<PenTool>());
+ add_tool("brush"sv, { 0, Key_P }, make<BrushTool>());
+ add_tool("bucket"sv, { Mod_Shift, Key_B }, make<BucketTool>());
+ add_tool("spray"sv, { Mod_Shift, Key_S }, make<SprayTool>());
+ add_tool("picker"sv, { 0, Key_O }, make<PickerTool>());
+ add_tool("eraser"sv, { Mod_Shift, Key_E }, make<EraseTool>());
+ add_tool("line"sv, { Mod_Ctrl | Mod_Shift, Key_L }, make<LineTool>());
+ add_tool("rectangle"sv, { Mod_Ctrl | Mod_Shift, Key_R }, make<RectangleTool>());
+ add_tool("circle"sv, { Mod_Ctrl | Mod_Shift, Key_E }, make<EllipseTool>());
+ add_tool("zoom"sv, { 0, Key_Z }, make<ZoomTool>());
+ add_tool("rectangle-select"sv, { 0, Key_R }, make<RectangleSelectTool>());
+ add_tool("guides"sv, { 0, Key_G }, make<GuideTool>());
+ add_tool("clone"sv, { 0, Key_C }, make<CloneTool>());
}
}
diff --git a/Userland/Applications/PixelPaint/Tools/BrushTool.h b/Userland/Applications/PixelPaint/Tools/BrushTool.h
index d76c40e295..27139bdf9f 100644
--- a/Userland/Applications/PixelPaint/Tools/BrushTool.h
+++ b/Userland/Applications/PixelPaint/Tools/BrushTool.h
@@ -36,6 +36,8 @@ public:
}
protected:
+ virtual StringView tool_name() const override { return "Brush Tool"sv; }
+
virtual Color color_for(GUI::MouseEvent const& event);
virtual void draw_point(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& point);
virtual void draw_line(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& start, Gfx::IntPoint const& end);
diff --git a/Userland/Applications/PixelPaint/Tools/BucketTool.h b/Userland/Applications/PixelPaint/Tools/BucketTool.h
index fc5e01f5d1..08fb9875ae 100644
--- a/Userland/Applications/PixelPaint/Tools/BucketTool.h
+++ b/Userland/Applications/PixelPaint/Tools/BucketTool.h
@@ -21,6 +21,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return m_cursor; }
private:
+ virtual StringView tool_name() const override { return "Bucket Tool"sv; }
+
RefPtr<GUI::Widget> m_properties_widget;
int m_threshold { 0 };
Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> m_cursor { Gfx::StandardCursor::Crosshair };
diff --git a/Userland/Applications/PixelPaint/Tools/CloneTool.h b/Userland/Applications/PixelPaint/Tools/CloneTool.h
index b86dd7d4f2..5b26f4cf4d 100644
--- a/Userland/Applications/PixelPaint/Tools/CloneTool.h
+++ b/Userland/Applications/PixelPaint/Tools/CloneTool.h
@@ -29,6 +29,8 @@ protected:
virtual void on_keyup(GUI::KeyEvent&) override;
private:
+ virtual StringView tool_name() const override { return "Clone Tool"sv; }
+
RefPtr<GUI::Widget> m_properties_widget;
Optional<Gfx::IntPoint> m_sample_location;
diff --git a/Userland/Applications/PixelPaint/Tools/EllipseTool.h b/Userland/Applications/PixelPaint/Tools/EllipseTool.h
index 89a0a5796b..b937f6a1a6 100644
--- a/Userland/Applications/PixelPaint/Tools/EllipseTool.h
+++ b/Userland/Applications/PixelPaint/Tools/EllipseTool.h
@@ -29,6 +29,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Crosshair; }
private:
+ virtual StringView tool_name() const override { return "Ellipse Tool"sv; }
+
enum class FillMode {
Outline,
Fill
diff --git a/Userland/Applications/PixelPaint/Tools/EraseTool.h b/Userland/Applications/PixelPaint/Tools/EraseTool.h
index e53e0d22ee..6797c0211f 100644
--- a/Userland/Applications/PixelPaint/Tools/EraseTool.h
+++ b/Userland/Applications/PixelPaint/Tools/EraseTool.h
@@ -27,6 +27,8 @@ protected:
virtual void draw_point(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& point) override;
private:
+ virtual StringView tool_name() const override { return "Erase Tool"sv; }
+
RefPtr<GUI::Widget> m_properties_widget;
enum class DrawMode {
diff --git a/Userland/Applications/PixelPaint/Tools/GuideTool.h b/Userland/Applications/PixelPaint/Tools/GuideTool.h
index 67aeabc09c..00d173143e 100644
--- a/Userland/Applications/PixelPaint/Tools/GuideTool.h
+++ b/Userland/Applications/PixelPaint/Tools/GuideTool.h
@@ -31,6 +31,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Crosshair; }
private:
+ virtual StringView tool_name() const override { return "Guide Tool"sv; }
+
RefPtr<Guide> closest_guide(Gfx::IntPoint const&);
RefPtr<GUI::Widget> m_properties_widget;
diff --git a/Userland/Applications/PixelPaint/Tools/LineTool.h b/Userland/Applications/PixelPaint/Tools/LineTool.h
index 8d744880d7..58c8db81cc 100644
--- a/Userland/Applications/PixelPaint/Tools/LineTool.h
+++ b/Userland/Applications/PixelPaint/Tools/LineTool.h
@@ -29,6 +29,8 @@ public:
void draw_using(GUI::Painter&, Gfx::IntPoint const& start_position, Gfx::IntPoint const& end_position, Color color, int thickness);
private:
+ virtual StringView tool_name() const override { return "Line Tool"sv; }
+
RefPtr<GUI::Widget> m_properties_widget;
GUI::MouseButton m_drawing_button { GUI::MouseButton::None };
diff --git a/Userland/Applications/PixelPaint/Tools/MoveTool.h b/Userland/Applications/PixelPaint/Tools/MoveTool.h
index e022256cce..20e7e5a685 100644
--- a/Userland/Applications/PixelPaint/Tools/MoveTool.h
+++ b/Userland/Applications/PixelPaint/Tools/MoveTool.h
@@ -24,6 +24,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Move; }
private:
+ virtual StringView tool_name() const override { return "Move Tool"sv; }
+
RefPtr<Layer> m_layer_being_moved;
Gfx::IntPoint m_event_origin;
Gfx::IntPoint m_layer_origin;
diff --git a/Userland/Applications/PixelPaint/Tools/PenTool.h b/Userland/Applications/PixelPaint/Tools/PenTool.h
index 502724ce03..fb94242eb5 100644
--- a/Userland/Applications/PixelPaint/Tools/PenTool.h
+++ b/Userland/Applications/PixelPaint/Tools/PenTool.h
@@ -26,6 +26,8 @@ protected:
virtual void draw_line(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& start, Gfx::IntPoint const& end) override;
private:
+ virtual StringView tool_name() const override { return "Pen Tool"sv; }
+
RefPtr<GUI::Widget> m_properties_widget;
};
diff --git a/Userland/Applications/PixelPaint/Tools/PickerTool.h b/Userland/Applications/PixelPaint/Tools/PickerTool.h
index 1fab7e04e1..2b83017d4f 100644
--- a/Userland/Applications/PixelPaint/Tools/PickerTool.h
+++ b/Userland/Applications/PixelPaint/Tools/PickerTool.h
@@ -23,6 +23,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Eyedropper; }
private:
+ virtual StringView tool_name() const override { return "Picker Tool"sv; }
+
RefPtr<GUI::Widget> m_properties_widget;
bool m_sample_all_layers { false };
};
diff --git a/Userland/Applications/PixelPaint/Tools/RectangleSelectTool.h b/Userland/Applications/PixelPaint/Tools/RectangleSelectTool.h
index 7d151a9fc2..8fa1bd043f 100644
--- a/Userland/Applications/PixelPaint/Tools/RectangleSelectTool.h
+++ b/Userland/Applications/PixelPaint/Tools/RectangleSelectTool.h
@@ -30,6 +30,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Crosshair; }
private:
+ virtual StringView tool_name() const override { return "Rectangle Select Tool"sv; }
+
enum class MovingMode {
MovingOrigin,
AroundCenter,
diff --git a/Userland/Applications/PixelPaint/Tools/RectangleTool.h b/Userland/Applications/PixelPaint/Tools/RectangleTool.h
index 823c80662e..52a59c82ab 100644
--- a/Userland/Applications/PixelPaint/Tools/RectangleTool.h
+++ b/Userland/Applications/PixelPaint/Tools/RectangleTool.h
@@ -28,6 +28,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Crosshair; }
private:
+ virtual StringView tool_name() const override { return "Rectangle Tool"sv; }
+
enum class FillMode {
Outline,
Fill,
diff --git a/Userland/Applications/PixelPaint/Tools/SprayTool.h b/Userland/Applications/PixelPaint/Tools/SprayTool.h
index 015e5703ee..20d602be9f 100644
--- a/Userland/Applications/PixelPaint/Tools/SprayTool.h
+++ b/Userland/Applications/PixelPaint/Tools/SprayTool.h
@@ -26,6 +26,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Crosshair; }
private:
+ virtual StringView tool_name() const override { return "Spray Tool"sv; }
+
void paint_it();
RefPtr<GUI::Widget> m_properties_widget;
diff --git a/Userland/Applications/PixelPaint/Tools/Tool.h b/Userland/Applications/PixelPaint/Tools/Tool.h
index 379513a4af..b3634934aa 100644
--- a/Userland/Applications/PixelPaint/Tools/Tool.h
+++ b/Userland/Applications/PixelPaint/Tools/Tool.h
@@ -74,6 +74,8 @@ public:
GUI::Action* action() { return m_action; }
void set_action(GUI::Action*);
+ virtual StringView tool_name() const = 0;
+
protected:
Tool() = default;
WeakPtr<ImageEditor> m_editor;
diff --git a/Userland/Applications/PixelPaint/Tools/ZoomTool.h b/Userland/Applications/PixelPaint/Tools/ZoomTool.h
index b52440c812..472ea5036c 100644
--- a/Userland/Applications/PixelPaint/Tools/ZoomTool.h
+++ b/Userland/Applications/PixelPaint/Tools/ZoomTool.h
@@ -22,6 +22,8 @@ public:
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Zoom; }
private:
+ virtual StringView tool_name() const override { return "Zoom Tool"sv; }
+
RefPtr<GUI::Widget> m_properties_widget;
double m_sensitivity { 0.5 };
};