From 4af0a9963469f1e3e90e328ebce6be50a13daf89 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 10 Sep 2021 22:54:36 -0400 Subject: [PATCH] PixelPaint: Show a pixel grid when zoomed in enough The editor now draws a grid showing the pixels if you are zoomed in enough. Currently the threshold is a scale of 15 (so if one pixel side on the image takes up > 15 pixels in the editor) --- .../Applications/PixelPaint/ImageEditor.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index d0e98279d6..890fb76f96 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -98,6 +98,24 @@ void ImageEditor::paint_event(GUI::PaintEvent& event) if (!m_selection.is_empty()) m_selection.paint(painter); + + const float pixel_grid_threshold = 15.0f; + if (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); + + for (auto i = image_rect.left(); i < image_rect.right(); i++) { + auto start_point = image_position_to_editor_position({ i, image_rect.top() }).to_type(); + auto end_point = image_position_to_editor_position({ i, image_rect.bottom() }).to_type(); + painter.draw_line(start_point, end_point, Color::LightGray); + } + + for (auto i = image_rect.top(); i < image_rect.bottom(); i++) { + auto start_point = image_position_to_editor_position({ image_rect.left(), i }).to_type(); + auto end_point = image_position_to_editor_position({ image_rect.right(), i }).to_type(); + painter.draw_line(start_point, end_point, Color::LightGray); + } + } } Gfx::FloatRect ImageEditor::layer_rect_to_editor_rect(Layer const& layer, Gfx::IntRect const& layer_rect) const