mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:07:36 +00:00
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.
This commit is contained in:
parent
4af0a99634
commit
79bcb90887
3 changed files with 24 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -100,7 +101,7 @@ void ImageEditor::paint_event(GUI::PaintEvent& event)
|
||||||
m_selection.paint(painter);
|
m_selection.paint(painter);
|
||||||
|
|
||||||
const float pixel_grid_threshold = 15.0f;
|
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 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);
|
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();
|
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()
|
void ImageEditor::layers_did_change()
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -94,6 +95,9 @@ public:
|
||||||
void set_guide_visibility(bool show_guides);
|
void set_guide_visibility(bool show_guides);
|
||||||
Function<void(bool)> on_set_guide_visibility;
|
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:
|
private:
|
||||||
explicit ImageEditor(NonnullRefPtr<Image>);
|
explicit ImageEditor(NonnullRefPtr<Image>);
|
||||||
|
|
||||||
|
@ -127,6 +131,7 @@ private:
|
||||||
|
|
||||||
NonnullRefPtrVector<Guide> m_guides;
|
NonnullRefPtrVector<Guide> m_guides;
|
||||||
bool m_show_guides { true };
|
bool m_show_guides { true };
|
||||||
|
bool m_show_pixel_grid { true };
|
||||||
|
|
||||||
Tool* m_active_tool { nullptr };
|
Tool* m_active_tool { nullptr };
|
||||||
|
|
||||||
|
|
|
@ -357,6 +357,15 @@ void MainWidget::initialize_menubar(GUI::Window& window)
|
||||||
if (auto* editor = current_image_editor())
|
if (auto* editor = current_image_editor())
|
||||||
editor->clear_guides();
|
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");
|
auto& tool_menu = window.add_menu("&Tool");
|
||||||
m_toolbox->for_each_tool([&](auto& tool) {
|
m_toolbox->for_each_tool([&](auto& tool) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue