From 101eb53de5497239e8ffc0afa6dc488c4d4521a4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Aug 2022 20:25:52 +0200 Subject: [PATCH] PixelPaint: Add Tool::tool_name() as a single-point-of-truth Let the tools know what their names are. --- .../Applications/PixelPaint/ToolboxWidget.cpp | 32 +++++++++---------- .../Applications/PixelPaint/Tools/BrushTool.h | 2 ++ .../PixelPaint/Tools/BucketTool.h | 2 ++ .../Applications/PixelPaint/Tools/CloneTool.h | 2 ++ .../PixelPaint/Tools/EllipseTool.h | 2 ++ .../Applications/PixelPaint/Tools/EraseTool.h | 2 ++ .../Applications/PixelPaint/Tools/GuideTool.h | 2 ++ .../Applications/PixelPaint/Tools/LineTool.h | 2 ++ .../Applications/PixelPaint/Tools/MoveTool.h | 2 ++ .../Applications/PixelPaint/Tools/PenTool.h | 2 ++ .../PixelPaint/Tools/PickerTool.h | 2 ++ .../PixelPaint/Tools/RectangleSelectTool.h | 2 ++ .../PixelPaint/Tools/RectangleTool.h | 2 ++ .../Applications/PixelPaint/Tools/SprayTool.h | 2 ++ Userland/Applications/PixelPaint/Tools/Tool.h | 2 ++ .../Applications/PixelPaint/Tools/ZoomTool.h | 2 ++ 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) { - 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) { + 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()); - add_tool("Pen", "pen"sv, { 0, Key_N }, make()); - add_tool("Brush", "brush"sv, { 0, Key_P }, make()); - add_tool("Bucket Fill", "bucket"sv, { Mod_Shift, Key_B }, make()); - add_tool("Spray", "spray"sv, { Mod_Shift, Key_S }, make()); - add_tool("Color Picker", "picker"sv, { 0, Key_O }, make()); - add_tool("Erase", "eraser"sv, { Mod_Shift, Key_E }, make()); - add_tool("Line", "line"sv, { Mod_Ctrl | Mod_Shift, Key_L }, make()); - add_tool("Rectangle", "rectangle"sv, { Mod_Ctrl | Mod_Shift, Key_R }, make()); - add_tool("Ellipse", "circle"sv, { Mod_Ctrl | Mod_Shift, Key_E }, make()); - add_tool("Zoom", "zoom"sv, { 0, Key_Z }, make()); - add_tool("Rectangle Select", "rectangle-select"sv, { 0, Key_R }, make()); - add_tool("Guides", "guides"sv, { 0, Key_G }, make()); - add_tool("Clone Tool", "clone"sv, { 0, Key_C }, make()); + add_tool("move"sv, { 0, Key_M }, make()); + add_tool("pen"sv, { 0, Key_N }, make()); + add_tool("brush"sv, { 0, Key_P }, make()); + add_tool("bucket"sv, { Mod_Shift, Key_B }, make()); + add_tool("spray"sv, { Mod_Shift, Key_S }, make()); + add_tool("picker"sv, { 0, Key_O }, make()); + add_tool("eraser"sv, { Mod_Shift, Key_E }, make()); + add_tool("line"sv, { Mod_Ctrl | Mod_Shift, Key_L }, make()); + add_tool("rectangle"sv, { Mod_Ctrl | Mod_Shift, Key_R }, make()); + add_tool("circle"sv, { Mod_Ctrl | Mod_Shift, Key_E }, make()); + add_tool("zoom"sv, { 0, Key_Z }, make()); + add_tool("rectangle-select"sv, { 0, Key_R }, make()); + add_tool("guides"sv, { 0, Key_G }, make()); + add_tool("clone"sv, { 0, Key_C }, make()); } } 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> cursor() override { return m_cursor; } private: + virtual StringView tool_name() const override { return "Bucket Tool"sv; } + RefPtr m_properties_widget; int m_threshold { 0 }; Variant> 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 m_properties_widget; Optional 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> 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 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> cursor() override { return Gfx::StandardCursor::Crosshair; } private: + virtual StringView tool_name() const override { return "Guide Tool"sv; } + RefPtr closest_guide(Gfx::IntPoint const&); RefPtr 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 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> cursor() override { return Gfx::StandardCursor::Move; } private: + virtual StringView tool_name() const override { return "Move Tool"sv; } + RefPtr 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 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> cursor() override { return Gfx::StandardCursor::Eyedropper; } private: + virtual StringView tool_name() const override { return "Picker Tool"sv; } + RefPtr 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> 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> 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> cursor() override { return Gfx::StandardCursor::Crosshair; } private: + virtual StringView tool_name() const override { return "Spray Tool"sv; } + void paint_it(); RefPtr 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 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> cursor() override { return Gfx::StandardCursor::Zoom; } private: + virtual StringView tool_name() const override { return "Zoom Tool"sv; } + RefPtr m_properties_widget; double m_sensitivity { 0.5 }; };