diff options
author | Mustafa Quraish <mustafaq9@gmail.com> | 2021-09-10 23:12:25 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-11 13:17:31 +0200 |
commit | 79bcb908874f028c4babff90d2c73d6af779da86 (patch) | |
tree | b06d68be2c738d4a80f85076ede2805de6e5fb9f /Userland/Applications/PixelPaint | |
parent | 4af0a9963469f1e3e90e328ebce6be50a13daf89 (diff) | |
download | serenity-79bcb908874f028c4babff90d2c73d6af779da86.zip |
PixelPaint: Add menu action to toggle pixel grid visibility
You can now toggle on/off the visibility of the pixel grid from
the View menu, if you don't want it shown for some reason.
Diffstat (limited to 'Userland/Applications/PixelPaint')
-rw-r--r-- | Userland/Applications/PixelPaint/ImageEditor.cpp | 11 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/ImageEditor.h | 5 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/MainWidget.cpp | 9 |
3 files changed, 24 insertions, 1 deletions
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 890fb76f96..e8d6f29579 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -100,7 +101,7 @@ void ImageEditor::paint_event(GUI::PaintEvent& event) m_selection.paint(painter); const float pixel_grid_threshold = 15.0f; - if (m_scale > pixel_grid_threshold) { + if (m_show_pixel_grid && m_scale > pixel_grid_threshold) { auto grid_rect = m_editor_image_rect.intersected(event.rect()); auto image_rect = enclosing_int_rect(editor_rect_to_image_rect(grid_rect)).inflated(1, 1); @@ -354,6 +355,14 @@ void ImageEditor::set_guide_visibility(bool show_guides) update(); } +void ImageEditor::set_pixel_grid_visibility(bool show_pixel_grid) +{ + if (m_show_pixel_grid == show_pixel_grid) + return; + m_show_pixel_grid = show_pixel_grid; + update(); +} + void ImageEditor::layers_did_change() { update(); diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index 62b5691b68..695152dffb 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -94,6 +95,9 @@ public: void set_guide_visibility(bool show_guides); Function<void(bool)> on_set_guide_visibility; + bool pixel_grid_visibility() const { return m_show_pixel_grid; } + void set_pixel_grid_visibility(bool show_pixel_grid); + private: explicit ImageEditor(NonnullRefPtr<Image>); @@ -127,6 +131,7 @@ private: NonnullRefPtrVector<Guide> m_guides; bool m_show_guides { true }; + bool m_show_pixel_grid { true }; Tool* m_active_tool { nullptr }; diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index e8ddd0b5a2..4ea0ceec39 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -357,6 +357,15 @@ void MainWidget::initialize_menubar(GUI::Window& window) if (auto* editor = current_image_editor()) editor->clear_guides(); })); + view_menu.add_separator(); + + auto show_pixel_grid_action = GUI::Action::create_checkable( + "Show Pixel Grid", [&](auto& action) { + if (auto* editor = current_image_editor()) + editor->set_pixel_grid_visibility(action.is_checked()); + }); + show_pixel_grid_action->set_checked(true); + view_menu.add_action(*show_pixel_grid_action); auto& tool_menu = window.add_menu("&Tool"); m_toolbox->for_each_tool([&](auto& tool) { |