mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
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:
parent
9413dddb8b
commit
4af0a99634
Notes:
sideshowbarker
2024-07-18 04:17:17 +09:00
Author: https://github.com/mustafaquraish Commit: https://github.com/SerenityOS/serenity/commit/4af0a996346 Pull-request: https://github.com/SerenityOS/serenity/pull/9952
1 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue