1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:08:12 +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

@ -253,7 +253,7 @@ void TabWidget::paint_event(PaintEvent& event)
icon_rect.translate_by(4, (button_rect.height() / 2) - (icon_rect.height() / 2));
painter.draw_scaled_bitmap(icon_rect, *icon, icon->rect());
text_rect.set_x(icon_rect.right() + 1 + 4);
text_rect.set_x(icon_rect.right() + 4);
text_rect.intersect(button_rect);
};
@ -288,12 +288,12 @@ void TabWidget::paint_event(PaintEvent& event)
Gfx::IntRect icon_rect { close_button_rect.x() + 3, close_button_rect.y() + 3, 6, 6 };
if (!m_tabs[i].modified) {
painter.draw_line(icon_rect.top_left(), icon_rect.bottom_right(), palette().button_text());
painter.draw_line(icon_rect.top_right(), icon_rect.bottom_left(), palette().button_text());
painter.draw_line(icon_rect.top_left(), icon_rect.bottom_right().translated(-1), palette().button_text());
painter.draw_line(icon_rect.top_right().moved_left(1), icon_rect.bottom_left().moved_up(1), palette().button_text());
} else {
painter.draw_line(icon_rect.top_left().moved_right(1), icon_rect.bottom_right().translated(-1, -1), palette().button_text());
painter.draw_line(icon_rect.top_right().moved_left(1), icon_rect.bottom_left().translated(1, -1), palette().button_text());
painter.draw_line(icon_rect.bottom_left().moved_down(1), icon_rect.bottom_right().moved_down(1), palette().button_text(), 1, Painter::LineStyle::Dotted);
painter.draw_line(icon_rect.top_left().moved_right(1), icon_rect.bottom_right().translated(-2), palette().button_text());
painter.draw_line(icon_rect.top_right().moved_left(2), icon_rect.bottom_left().translated(1, -2), palette().button_text());
painter.draw_line(icon_rect.bottom_left(), icon_rect.bottom_right().moved_left(1), palette().button_text(), 1, Painter::LineStyle::Dotted);
}
}
}
@ -329,12 +329,12 @@ void TabWidget::paint_event(PaintEvent& event)
}
if (m_tab_position == TabPosition::Top) {
painter.draw_line(button_rect.bottom_left().translated(1, 1), button_rect.bottom_right().translated(-1, 1), palette().button());
painter.draw_line(button_rect.bottom_left().moved_right(1), button_rect.bottom_right().translated(-2, 0), palette().button());
} else if (m_tab_position == TabPosition::Bottom) {
painter.set_pixel(button_rect.top_left().translated(0, -1), palette().threed_highlight());
painter.set_pixel(button_rect.top_right().translated(-1, -1), palette().threed_shadow1());
painter.draw_line(button_rect.top_left().translated(1, -1), button_rect.top_right().translated(-2, -1), palette().button());
painter.draw_line(button_rect.top_left().translated(1, -2), button_rect.top_right().translated(-2, -2), palette().button());
painter.set_pixel(button_rect.top_right().translated(-2, -1), palette().threed_shadow1());
painter.draw_line(button_rect.top_left().translated(1, -1), button_rect.top_right().translated(-3, -1), palette().button());
painter.draw_line(button_rect.top_left().translated(1, -2), button_rect.top_right().translated(-3, -2), palette().button());
}
break;
}
@ -362,12 +362,12 @@ void TabWidget::paint_event(PaintEvent& event)
Gfx::IntRect icon_rect { close_button_rect.x() + 3, close_button_rect.y() + 3, 6, 6 };
if (!m_tabs[i].modified) {
painter.draw_line(icon_rect.top_left(), icon_rect.bottom_right(), palette().button_text());
painter.draw_line(icon_rect.top_right(), icon_rect.bottom_left(), palette().button_text());
painter.draw_line(icon_rect.top_left(), icon_rect.bottom_right().translated(-1), palette().button_text());
painter.draw_line(icon_rect.top_right().moved_left(1), icon_rect.bottom_left().moved_up(1), palette().button_text());
} else {
painter.draw_line(icon_rect.top_left().moved_right(1), icon_rect.bottom_right().translated(-1, -1), palette().button_text());
painter.draw_line(icon_rect.top_right().moved_left(1), icon_rect.bottom_left().translated(1, -1), palette().button_text());
painter.draw_line(icon_rect.bottom_left().moved_down(1), icon_rect.bottom_right().moved_down(1), palette().button_text(), 1, Painter::LineStyle::Dotted);
painter.draw_line(icon_rect.top_left().moved_right(1), icon_rect.bottom_right().translated(-2, -2), palette().button_text());
painter.draw_line(icon_rect.top_right().moved_left(2), icon_rect.bottom_left().moved_right(1), palette().button_text());
painter.draw_line(icon_rect.bottom_left(), icon_rect.bottom_right().moved_left(1), palette().button_text(), 1, Painter::LineStyle::Dotted);
}
}
}
@ -444,7 +444,7 @@ Gfx::IntRect TabWidget::close_button_rect(size_t index) const
auto rect = button_rect(index);
Gfx::IntRect close_button_rect { 0, 0, 12, 12 };
close_button_rect.translate_by(rect.right(), rect.top());
close_button_rect.translate_by(rect.right() - 1, rect.top());
close_button_rect.translate_by(-(close_button_rect.width() + 4), (rect.height() / 2) - (close_button_rect.height() / 2));
return close_button_rect;
@ -459,9 +459,8 @@ int TabWidget::TabData::width(Gfx::Font const& font) const
// text and the focus rect has an odd number of pixels, and this
// causes the text (and subsequently the focus rect) to not be aligned
// to the center perfectly.
if (width % 2 == 0) {
if (width % 2 == 0)
width++;
}
return width;
}