PixelPaint: Add Tool::tool_name() as a single-point-of-truth

Let the tools know what their names are.
This commit is contained in:
Andreas Kling 2022-08-21 20:25:52 +02:00
parent c45f99f735
commit 101eb53de5
Notes: sideshowbarker 2024-07-17 08:05:29 +09:00
16 changed files with 46 additions and 16 deletions

View file

@ -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>());
}
}

View file

@ -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);

View file

@ -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 };

View file

@ -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;

View file

@ -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

View file

@ -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 {

View file

@ -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;

View file

@ -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 };

View file

@ -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;

View file

@ -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;
};

View file

@ -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 };
};

View file

@ -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,

View file

@ -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,

View file

@ -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;

View file

@ -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;

View file

@ -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 };
};