mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
PixelPaint: Set Tool on_*_color_change logic using virtual functions
Previously, we were rewriting the on_primary_color_change in the Text Tool and Gradient, which made the palette widget no longer update after picking a color from an image. Additionally, it also crashed the program after leaving the Gradient tool and trying to change color.
This commit is contained in:
parent
cb96c892cc
commit
d27d19f012
7 changed files with 23 additions and 18 deletions
|
@ -1229,6 +1229,17 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr<Image> image)
|
|||
},
|
||||
100);
|
||||
|
||||
image_editor.on_primary_color_change = [&](Color color) {
|
||||
m_palette_widget->set_primary_color(color);
|
||||
if (image_editor.active_tool())
|
||||
image_editor.active_tool()->on_primary_color_change(color);
|
||||
};
|
||||
image_editor.on_secondary_color_change = [&](Color color) {
|
||||
m_palette_widget->set_secondary_color(color);
|
||||
if (image_editor.active_tool())
|
||||
image_editor.active_tool()->on_secondary_color_change(color);
|
||||
};
|
||||
|
||||
if (image->layer_count())
|
||||
image_editor.set_active_layer(&image->layer(0));
|
||||
|
||||
|
|
|
@ -150,14 +150,6 @@ void PaletteWidget::set_image_editor(ImageEditor* editor)
|
|||
|
||||
set_primary_color(editor->primary_color());
|
||||
set_secondary_color(editor->secondary_color());
|
||||
|
||||
editor->on_primary_color_change = [this](Color color) {
|
||||
set_primary_color(color);
|
||||
};
|
||||
|
||||
editor->on_secondary_color_change = [this](Color color) {
|
||||
set_secondary_color(color);
|
||||
};
|
||||
}
|
||||
|
||||
void PaletteWidget::set_primary_color(Color color)
|
||||
|
|
|
@ -163,13 +163,14 @@ void GradientTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event)
|
|||
draw_gradient(painter, true, m_editor->content_to_frame_position(Gfx::IntPoint(0, 0)), m_editor->scale(), m_editor->content_rect());
|
||||
}
|
||||
|
||||
void GradientTool::on_primary_color_change(Color)
|
||||
{
|
||||
if (m_gradient_end.has_value())
|
||||
m_editor->update();
|
||||
}
|
||||
|
||||
void GradientTool::on_tool_activation()
|
||||
{
|
||||
m_editor->on_primary_color_change = [this](Color) {
|
||||
if (m_gradient_end.has_value())
|
||||
m_editor->update();
|
||||
};
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
virtual void on_mouseup(Layer*, MouseEvent&) override;
|
||||
virtual bool on_keydown(GUI::KeyEvent&) override;
|
||||
virtual void on_keyup(GUI::KeyEvent&) override;
|
||||
virtual void on_primary_color_change(Color) override;
|
||||
virtual void on_tool_activation() override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
|
||||
|
|
|
@ -41,11 +41,9 @@ TextTool::TextTool()
|
|||
}).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
||||
void TextTool::on_tool_activation()
|
||||
void TextTool::on_primary_color_change(Color color)
|
||||
{
|
||||
m_editor->on_primary_color_change = [this](auto color) {
|
||||
m_text_color = color;
|
||||
};
|
||||
m_text_color = color;
|
||||
}
|
||||
|
||||
void TextTool::on_tool_deactivation()
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
virtual void on_mousedown(Layer*, MouseEvent&) override;
|
||||
virtual bool on_keydown(GUI::KeyEvent&) override;
|
||||
virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override;
|
||||
virtual void on_tool_activation() override;
|
||||
virtual void on_primary_color_change(Color) override;
|
||||
virtual void on_tool_deactivation() override;
|
||||
virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override;
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
|
|
|
@ -63,6 +63,8 @@ public:
|
|||
virtual void on_second_paint(Layer const*, GUI::PaintEvent&) { }
|
||||
virtual bool on_keydown(GUI::KeyEvent&);
|
||||
virtual void on_keyup(GUI::KeyEvent&) { }
|
||||
virtual void on_primary_color_change(Color) { }
|
||||
virtual void on_secondary_color_change(Color) { }
|
||||
virtual void on_tool_activation() { }
|
||||
virtual void on_tool_deactivation() { }
|
||||
virtual GUI::Widget* get_properties_widget() { return nullptr; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue