1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:47:35 +00:00

PixelPaint: Make Guides' visibility optional

Whether Guides are drawn or not is now controlled via the menu-entry
View->Show Guides.
This commit is contained in:
Tobias Christiansen 2021-08-05 15:48:59 +02:00 committed by Ali Mohammad Pur
parent 193f1e01cf
commit 0ca085910e
3 changed files with 21 additions and 7 deletions

View file

@ -83,6 +83,7 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
painter.draw_rect(enclosing_int_rect(image_rect_to_editor_rect(m_active_layer->relative_rect())).inflated(2, 2), Color::Black); painter.draw_rect(enclosing_int_rect(image_rect_to_editor_rect(m_active_layer->relative_rect())).inflated(2, 2), Color::Black);
} }
if (m_show_guides) {
for (auto& guide : m_guides) { for (auto& guide : m_guides) {
if (guide.orientation() == Guide::Orientation::Horizontal) { if (guide.orientation() == Guide::Orientation::Horizontal) {
int y_coordinate = (int)image_position_to_editor_position({ 0.0f, guide.offset() }).y(); int y_coordinate = (int)image_position_to_editor_position({ 0.0f, guide.offset() }).y();
@ -92,6 +93,7 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
painter.draw_line({ x_coordinate, 0 }, { x_coordinate, rect().height() }, Color::Cyan, 1, Gfx::Painter::LineStyle::Dashed, Color::LightGray); painter.draw_line({ x_coordinate, 0 }, { x_coordinate, rect().height() }, Color::Cyan, 1, Gfx::Painter::LineStyle::Dashed, Color::LightGray);
} }
} }
}
if (!m_selection.is_empty()) if (!m_selection.is_empty())
m_selection.paint(painter); m_selection.paint(painter);

View file

@ -85,6 +85,7 @@ public:
Gfx::FloatPoint editor_position_to_image_position(Gfx::IntPoint const&) const; Gfx::FloatPoint editor_position_to_image_position(Gfx::IntPoint const&) const;
NonnullRefPtrVector<Guide> const& guides() const { return m_guides; } NonnullRefPtrVector<Guide> const& guides() const { return m_guides; }
void toggle_guide_visibility() { m_show_guides = !m_show_guides; }
private: private:
explicit ImageEditor(NonnullRefPtr<Image>); explicit ImageEditor(NonnullRefPtr<Image>);
@ -116,6 +117,7 @@ private:
OwnPtr<GUI::UndoStack> m_undo_stack; OwnPtr<GUI::UndoStack> m_undo_stack;
NonnullRefPtrVector<Guide> m_guides; NonnullRefPtrVector<Guide> m_guides;
bool m_show_guides { true };
Tool* m_active_tool { nullptr }; Tool* m_active_tool { nullptr };

View file

@ -347,11 +347,21 @@ int main(int argc, char** argv)
}, },
window); window);
auto show_guides_action = GUI::Action::create_checkable(
"Show Guides", [&](auto&) {
if (auto* editor = current_image_editor()) {
editor->toggle_guide_visibility();
}
},
window);
show_guides_action->set_checked(true);
view_menu.add_action(zoom_in_action); view_menu.add_action(zoom_in_action);
view_menu.add_action(zoom_out_action); view_menu.add_action(zoom_out_action);
view_menu.add_action(reset_zoom_action); view_menu.add_action(reset_zoom_action);
view_menu.add_separator(); view_menu.add_separator();
view_menu.add_action(add_guide_action); view_menu.add_action(add_guide_action);
view_menu.add_action(show_guides_action);
auto& tool_menu = window->add_menu("&Tool"); auto& tool_menu = window->add_menu("&Tool");
toolbox.for_each_tool([&](auto& tool) { toolbox.for_each_tool([&](auto& tool) {