1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 09:37:44 +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

@ -369,12 +369,12 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
}
if (underline_style == UnderlineStyle::Solid) {
painter.draw_line(cell_rect.bottom_left(), cell_rect.bottom_right(), underline_color);
painter.draw_line(cell_rect.bottom_left().moved_up(1), cell_rect.bottom_right().translated(-1), underline_color);
} else if (underline_style == UnderlineStyle::Dotted) {
int x1 = cell_rect.bottom_left().x();
int x2 = cell_rect.bottom_right().x();
int y = cell_rect.bottom_left().y();
for (int x = x1; x <= x2; ++x) {
int x1 = cell_rect.left();
int x2 = cell_rect.right();
int y = cell_rect.bottom() - 1;
for (int x = x1; x < x2; ++x) {
if ((x % 3) == 0)
painter.set_pixel({ x, y }, underline_color);
}
@ -439,16 +439,16 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
auto cursor_color = terminal_color_to_rgb(cursor_line.attribute_at(m_terminal.cursor_column()).effective_foreground_color());
auto cell_rect = glyph_rect(row_with_cursor, m_terminal.cursor_column()).inflated(0, m_line_spacing);
if (m_cursor_shape == VT::CursorShape::Underline) {
auto x1 = cell_rect.bottom_left().x();
auto x2 = cell_rect.bottom_right().x();
auto y = cell_rect.bottom_left().y();
for (auto x = x1; x <= x2; ++x)
auto x1 = cell_rect.left();
auto x2 = cell_rect.right();
auto y = cell_rect.bottom() - 1;
for (auto x = x1; x < x2; ++x)
painter.set_pixel({ x, y }, cursor_color);
} else if (m_cursor_shape == VT::CursorShape::Bar) {
auto x = cell_rect.bottom_left().x();
auto y1 = cell_rect.top_left().y();
auto y2 = cell_rect.bottom_left().y();
for (auto y = y1; y <= y2; ++y)
auto x = cell_rect.left();
auto y1 = cell_rect.top();
auto y2 = cell_rect.bottom();
for (auto y = y1; y < y2; ++y)
painter.set_pixel({ x, y }, cursor_color);
} else {
// We fall back to a block if we don't support the selected cursor type.