From 79bcb908874f028c4babff90d2c73d6af779da86 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 10 Sep 2021 23:12:25 -0400 Subject: 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. --- Userland/Applications/PixelPaint/ImageEditor.cpp | 11 ++++++++++- Userland/Applications/PixelPaint/ImageEditor.h | 5 +++++ Userland/Applications/PixelPaint/MainWidget.cpp | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) 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 * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2021, Mustafa Quraish * * 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 * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2021, Mustafa Quraish * * SPDX-License-Identifier: BSD-2-Clause */ @@ -94,6 +95,9 @@ public: void set_guide_visibility(bool show_guides); Function 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); @@ -127,6 +131,7 @@ private: NonnullRefPtrVector 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) { -- cgit v1.2.3