mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03: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
Notes:
sideshowbarker
2024-07-18 04:17:13 +09:00
Author: https://github.com/mustafaquraish Commit: https://github.com/SerenityOS/serenity/commit/79bcb908874 Pull-request: https://github.com/SerenityOS/serenity/pull/9952
@ -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();
|
||||
|
@ -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 };
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user