mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:07: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:
parent
b7f4363791
commit
f391ccfe53
88 changed files with 524 additions and 518 deletions
|
@ -570,9 +570,9 @@ void BrickGame::paint_cell(GUI::Painter& painter, Gfx::IntRect rect, BrickGame::
|
|||
rect.inflate(-1, -1, -1, -1);
|
||||
painter.draw_rect(rect, outside_color);
|
||||
painter.set_pixel(rect.top_left(), m_back_color);
|
||||
painter.set_pixel(rect.bottom_left(), m_back_color);
|
||||
painter.set_pixel(rect.top_right(), m_back_color);
|
||||
painter.set_pixel(rect.bottom_right(), m_back_color);
|
||||
painter.set_pixel(rect.bottom_left().moved_up(1), m_back_color);
|
||||
painter.set_pixel(rect.top_right().moved_left(1), m_back_color);
|
||||
painter.set_pixel(rect.bottom_right().translated(-1), m_back_color);
|
||||
rect.inflate(-2, -2);
|
||||
painter.draw_rect(rect, outside_color);
|
||||
rect.inflate(-2, -2);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -75,7 +75,7 @@ void ScoreCard::paint_event(GUI::PaintEvent& event)
|
|||
if (score_index != (int)player.scores.size() - 1) {
|
||||
painter.draw_line(
|
||||
{ text_rect.left() + text_rect.width() / 2 - score_text_width / 2 - 3, text_rect.top() + font.pixel_size_rounded_up() / 2 },
|
||||
{ text_rect.right() - text_rect.width() / 2 + score_text_width / 2 + 3, text_rect.top() + font.pixel_size_rounded_up() / 2 },
|
||||
{ text_rect.right() - text_rect.width() / 2 + score_text_width / 2 + 2, text_rect.top() + font.pixel_size_rounded_up() / 2 },
|
||||
text_color);
|
||||
}
|
||||
painter.draw_text(text_rect,
|
||||
|
|
|
@ -363,14 +363,14 @@ void Field::paint_event(GUI::PaintEvent& event)
|
|||
auto inner_rect = frame_inner_rect();
|
||||
painter.add_clip_rect(inner_rect);
|
||||
|
||||
for (int y = inner_rect.top() - 1; y <= inner_rect.bottom(); y += square_size()) {
|
||||
for (int y = inner_rect.top() - 1; y < inner_rect.bottom(); y += square_size()) {
|
||||
Gfx::IntPoint a { inner_rect.left(), y };
|
||||
Gfx::IntPoint b { inner_rect.right(), y };
|
||||
Gfx::IntPoint b { inner_rect.right() - 1, y };
|
||||
painter.draw_line(a, b, palette().threed_shadow1());
|
||||
}
|
||||
for (int x = frame_inner_rect().left() - 1; x <= frame_inner_rect().right(); x += square_size()) {
|
||||
for (int x = frame_inner_rect().left() - 1; x < frame_inner_rect().right(); x += square_size()) {
|
||||
Gfx::IntPoint a { x, inner_rect.top() };
|
||||
Gfx::IntPoint b { x, inner_rect.bottom() };
|
||||
Gfx::IntPoint b { x, inner_rect.bottom() - 1 };
|
||||
painter.draw_line(a, b, palette().threed_shadow1());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ void ClassicSkin::draw_tile_at(Gfx::Painter& painter, Gfx::IntRect const& rect)
|
|||
|
||||
Gfx::IntRect left_side(rect.x(), rect.y(), 2, rect.height());
|
||||
Gfx::IntRect top_side(rect.x(), rect.y(), rect.width(), 2);
|
||||
Gfx::IntRect right_side(rect.right() - 1, rect.y(), 2, rect.height());
|
||||
Gfx::IntRect bottom_side(rect.x(), rect.bottom() - 1, rect.width(), 2);
|
||||
Gfx::IntRect right_side(rect.right() - 2, rect.y(), 2, rect.height());
|
||||
Gfx::IntRect bottom_side(rect.x(), rect.bottom() - 2, rect.width(), 2);
|
||||
auto top_left_color = m_skin_color.lightened(0.88);
|
||||
auto bottom_right_color = m_skin_color.darkened(0.55);
|
||||
painter.fill_rect(left_side, top_left_color);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue