mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 19:10:26 +00:00
PixelPaint: Show Guides on GuideTool activation
This adds on_tool_activation() to Tool which GuideTool can use to show guides, if they're hidden, when it's activated. Also show guides on mousedown since there's no use in drawing invisible guides.
This commit is contained in:
parent
3b3df40eb9
commit
1ad08ab7d6
Notes:
sideshowbarker
2024-07-18 06:58:13 +09:00
Author: https://github.com/metmo Commit: https://github.com/SerenityOS/serenity/commit/1ad08ab7d64 Pull-request: https://github.com/SerenityOS/serenity/pull/9393
6 changed files with 40 additions and 3 deletions
|
@ -57,6 +57,8 @@ void GuideTool::on_mousedown(Layer&, GUI::MouseEvent& mouse_event, GUI::MouseEve
|
|||
if (mouse_event.button() != GUI::MouseButton::Left)
|
||||
return;
|
||||
|
||||
m_editor->set_guide_visibility(true);
|
||||
|
||||
RefPtr<Guide> new_guide;
|
||||
if (image_event.position().x() < 0 || image_event.position().x() > editor()->image().size().width()) {
|
||||
new_guide = Guide::construct(Guide::Orientation::Vertical, image_event.position().x());
|
||||
|
@ -129,6 +131,11 @@ void GuideTool::on_mousemove(Layer&, GUI::MouseEvent&, GUI::MouseEvent& image_ev
|
|||
|
||||
void GuideTool::on_context_menu(Layer&, GUI::ContextMenuEvent& event)
|
||||
{
|
||||
if (!m_editor)
|
||||
return;
|
||||
|
||||
m_editor->set_guide_visibility(true);
|
||||
|
||||
if (!m_context_menu) {
|
||||
m_context_menu = GUI::Menu::construct();
|
||||
m_context_menu->add_action(GUI::Action::create(
|
||||
|
@ -148,6 +155,12 @@ void GuideTool::on_context_menu(Layer&, GUI::ContextMenuEvent& event)
|
|||
m_context_menu->popup(event.screen_position());
|
||||
}
|
||||
|
||||
void GuideTool::on_tool_activation()
|
||||
{
|
||||
if (m_editor)
|
||||
m_editor->set_guide_visibility(true);
|
||||
}
|
||||
|
||||
GUI::Widget* GuideTool::get_properties_widget()
|
||||
{
|
||||
if (!m_properties_widget) {
|
||||
|
|
|
@ -23,6 +23,8 @@ public:
|
|||
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
|
||||
virtual void on_context_menu(Layer&, GUI::ContextMenuEvent&) override;
|
||||
|
||||
virtual void on_tool_activation() override;
|
||||
|
||||
virtual GUI::Widget* get_properties_widget() override;
|
||||
virtual Gfx::StandardCursor cursor() override { return Gfx::StandardCursor::Crosshair; }
|
||||
|
||||
|
|
|
@ -316,10 +316,24 @@ void ImageEditor::set_active_tool(Tool* tool)
|
|||
|
||||
if (m_active_tool) {
|
||||
m_active_tool->setup(*this);
|
||||
m_active_tool->on_tool_activation();
|
||||
m_active_cursor = m_active_tool->cursor();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageEditor::set_guide_visibility(bool show_guides)
|
||||
{
|
||||
if (m_show_guides == show_guides)
|
||||
return;
|
||||
|
||||
m_show_guides = show_guides;
|
||||
|
||||
if (on_set_guide_visibility)
|
||||
on_set_guide_visibility(m_show_guides);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ImageEditor::layers_did_change()
|
||||
{
|
||||
update();
|
||||
|
|
|
@ -85,7 +85,9 @@ public:
|
|||
Gfx::FloatPoint editor_position_to_image_position(Gfx::IntPoint const&) const;
|
||||
|
||||
NonnullRefPtrVector<Guide> const& guides() const { return m_guides; }
|
||||
void toggle_guide_visibility() { m_show_guides = !m_show_guides; }
|
||||
bool guide_visibility() { return m_show_guides; }
|
||||
void set_guide_visibility(bool show_guides);
|
||||
Function<void(bool)> on_set_guide_visibility;
|
||||
|
||||
private:
|
||||
explicit ImageEditor(NonnullRefPtr<Image>);
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
virtual void on_second_paint(Layer const&, GUI::PaintEvent&) { }
|
||||
virtual void on_keydown(GUI::KeyEvent&) { }
|
||||
virtual void on_keyup(GUI::KeyEvent&) { }
|
||||
virtual void on_tool_activation() { }
|
||||
virtual GUI::Widget* get_properties_widget() { return nullptr; }
|
||||
virtual Gfx::StandardCursor cursor() { return Gfx::StandardCursor::None; }
|
||||
|
||||
|
|
|
@ -399,9 +399,9 @@ int main(int argc, char** argv)
|
|||
window);
|
||||
|
||||
auto show_guides_action = GUI::Action::create_checkable(
|
||||
"Show Guides", [&](auto&) {
|
||||
"Show Guides", [&](auto& action) {
|
||||
if (auto* editor = current_image_editor()) {
|
||||
editor->toggle_guide_visibility();
|
||||
editor->set_guide_visibility(action.is_checked());
|
||||
}
|
||||
},
|
||||
window);
|
||||
|
@ -706,6 +706,10 @@ int main(int argc, char** argv)
|
|||
statusbar.set_override_text({});
|
||||
};
|
||||
|
||||
image_editor.on_set_guide_visibility = [&](bool show_guides) {
|
||||
show_guides_action->set_checked(show_guides);
|
||||
};
|
||||
|
||||
// NOTE: We invoke the above hook directly here to make sure the tab title is set up.
|
||||
image_editor.on_image_title_change(image->title());
|
||||
|
||||
|
@ -742,6 +746,7 @@ int main(int argc, char** argv)
|
|||
image_editor.set_active_tool(&tool);
|
||||
}
|
||||
});
|
||||
show_guides_action->set_checked(image_editor.guide_visibility());
|
||||
};
|
||||
|
||||
if (Core::File::exists(file_to_edit_full_path)) {
|
||||
|
|
Loading…
Reference in a new issue