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)
This commit is contained in:
Mustafa Quraish 2021-09-10 22:54:36 -04:00 committed by Andreas Kling
parent 9413dddb8b
commit 4af0a99634
Notes: sideshowbarker 2024-07-18 04:17:17 +09:00

View file

@ -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<int>();
auto end_point = image_position_to_editor_position({ i, image_rect.bottom() }).to_type<int>();
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<int>();
auto end_point = image_position_to_editor_position({ image_rect.right(), i }).to_type<int>();
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