1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:17:45 +00:00

LibGfx+Everywhere: Change Gfx::Rect to be endpoint exclusive

Previously, calling `.right()` on a `Gfx::Rect` would return the last
column's coordinate still inside the rectangle, or `left + width - 1`.
This is called 'endpoint inclusive' and does not make a lot of sense for
`Gfx::Rect<float>` where a rectangle of width 5 at position (0, 0) would
return 4 as its right side. This same problem exists for `.bottom()`.

This changes `Gfx::Rect` to be endpoint exclusive, which gives us the
nice property that `width = right - left` and `height = bottom - top`.
It enables us to treat `Gfx::Rect<int>` and `Gfx::Rect<float>` exactly
the same.

All users of `Gfx::Rect` have been updated accordingly.
This commit is contained in:
Jelle Raaijmakers 2023-05-22 00:41:18 +02:00 committed by Andreas Kling
parent b7f4363791
commit f391ccfe53
88 changed files with 524 additions and 518 deletions

View file

@ -179,7 +179,7 @@ void ColorLines::paint_event(GUI::PaintEvent& event)
auto paint_cell = [&](GUI::Painter& painter, Gfx::IntRect rect, int color, int animation_frame) {
painter.draw_rect(rect, Color::Black);
rect.shrink(0, 1, 1, 0);
rect.shrink(0, 2, 2, 0);
painter.draw_line(rect.bottom_left(), rect.top_left(), Color::White);
painter.draw_line(rect.top_left(), rect.top_right(), Color::White);
painter.draw_line(rect.top_right(), rect.bottom_right(), Color::DarkGray);
@ -189,7 +189,6 @@ void ColorLines::paint_event(GUI::PaintEvent& event)
painter.draw_line(rect.top_left(), rect.top_right(), Color::LightGray);
painter.draw_line(rect.top_right(), rect.bottom_right(), Color::MidGray);
painter.draw_line(rect.bottom_right(), rect.bottom_left(), Color::MidGray);
rect.shrink(1, 1, 1, 1);
painter.fill_rect(rect, tile_color);
rect.shrink(1, 1, 1, 1);
if (color >= 0 && color < Marble::number_of_colors) {
@ -222,7 +221,7 @@ void ColorLines::paint_event(GUI::PaintEvent& event)
auto const high_score_text = MUST(String::formatted("{:05}"sv, m_high_score));
text_width = m_score_font->width(high_score_text);
auto const high_score_text_rect = Gfx::IntRect {
frame_inner_rect().top_right().translated(-(text_margin + text_width), text_margin),
frame_inner_rect().top_right().translated(-(text_margin + text_width) - 1, text_margin),
Gfx::IntSize { text_width, font().pixel_size_rounded_up() }
};
painter.draw_text(high_score_text_rect, high_score_text, Gfx::TextAlignment::CenterLeft, text_color);