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

@ -47,16 +47,15 @@ void OpacitySlider::paint_event(PaintEvent& event)
constexpr int notch_size = 3;
if (orientation() == Gfx::Orientation::Horizontal) {
int notch_y_top = inner_rect.top() + notch_size;
int notch_y_bottom = inner_rect.bottom() - notch_size;
int notch_y_bottom = inner_rect.bottom() - 1 - notch_size;
int notch_x = inner_rect.left() + ((float)value() / (float)max() * (float)inner_rect.width());
// Top notch
painter.set_pixel(notch_x, notch_y_top, palette().threed_shadow2());
for (int i = notch_size; i >= 0; --i) {
painter.set_pixel(notch_x - (i + 1), notch_y_top - i - 1, palette().threed_highlight());
for (int j = 0; j < i * 2; ++j) {
for (int j = 0; j < i * 2; ++j)
painter.set_pixel(notch_x - (i + 1) + j + 1, notch_y_top - i - 1, palette().button());
}
painter.set_pixel(notch_x + (i + 0), notch_y_top - i - 1, palette().threed_shadow1());
painter.set_pixel(notch_x + (i + 1), notch_y_top - i - 1, palette().threed_shadow2());
}
@ -65,9 +64,8 @@ void OpacitySlider::paint_event(PaintEvent& event)
painter.set_pixel(notch_x, notch_y_bottom, palette().threed_shadow2());
for (int i = 0; i < notch_size; ++i) {
painter.set_pixel(notch_x - (i + 1), notch_y_bottom + i + 1, palette().threed_highlight());
for (int j = 0; j < i * 2; ++j) {
for (int j = 0; j < i * 2; ++j)
painter.set_pixel(notch_x - (i + 1) + j + 1, notch_y_bottom + i + 1, palette().button());
}
painter.set_pixel(notch_x + (i + 0), notch_y_bottom + i + 1, palette().threed_shadow1());
painter.set_pixel(notch_x + (i + 1), notch_y_bottom + i + 1, palette().threed_shadow2());
}
@ -83,16 +81,15 @@ void OpacitySlider::paint_event(PaintEvent& event)
painter.draw_line({ notch_x - 1, notch_y_top }, { notch_x - 1, notch_y_bottom }, Color(h, h, h, 255));
} else {
int notch_x_left = inner_rect.left() + notch_size;
int notch_x_right = inner_rect.right() - notch_size;
int notch_x_right = inner_rect.right() - 1 - notch_size;
int notch_y = inner_rect.top() + ((float)value() / (float)max() * (float)inner_rect.height());
// Left notch
painter.set_pixel(notch_x_left, notch_y, palette().threed_shadow2());
for (int i = notch_size; i >= 0; --i) {
painter.set_pixel(notch_x_left - i - 1, notch_y - (i + 1), palette().threed_highlight());
for (int j = 0; j < i * 2; ++j) {
for (int j = 0; j < i * 2; ++j)
painter.set_pixel(notch_x_left - i - 1, notch_y - (i + 1) + j + 1, palette().button());
}
painter.set_pixel(notch_x_left - i - 1, notch_y + (i + 0), palette().threed_shadow1());
painter.set_pixel(notch_x_left - i - 1, notch_y + (i + 1), palette().threed_shadow2());
}
@ -101,9 +98,8 @@ void OpacitySlider::paint_event(PaintEvent& event)
painter.set_pixel(notch_x_right, notch_y, palette().threed_shadow2());
for (int i = 0; i < notch_size; ++i) {
painter.set_pixel(notch_x_right + i + 1, notch_y - (i + 1), palette().threed_highlight());
for (int j = 0; j < i * 2; ++j) {
for (int j = 0; j < i * 2; ++j)
painter.set_pixel(notch_x_right + i + 1, notch_y - (i + 1) + j + 1, palette().button());
}
painter.set_pixel(notch_x_right + i + 1, notch_y + (i + 0), palette().threed_shadow1());
painter.set_pixel(notch_x_right + i + 1, notch_y + (i + 1), palette().threed_shadow2());
}