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

@ -64,8 +64,8 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
auto [title_color, border_color, border_color2, stripes_color, shadow_color] = compute_frame_colors(window_state, palette);
painter.draw_line(titlebar_rect.bottom_left().translated(0, 1), titlebar_rect.bottom_right().translated(0, 1), palette.button());
painter.draw_line(titlebar_rect.bottom_left().translated(0, 2), titlebar_rect.bottom_right().translated(0, 2), palette.button());
painter.draw_line(titlebar_rect.bottom_left(), titlebar_rect.bottom_right().moved_left(1), palette.button());
painter.draw_line(titlebar_rect.bottom_left().moved_down(1), titlebar_rect.bottom_right().translated(-1, 1), palette.button());
painter.fill_rect_with_gradient(titlebar_rect, border_color, border_color2);
@ -87,7 +87,7 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
if (stripes_color.alpha() > 0) {
switch (title_alignment) {
case Gfx::TextAlignment::CenterLeft: {
int stripe_left = titlebar_title_rect.right() + 5;
int stripe_left = titlebar_title_rect.right() + 4;
if (stripe_left && stripe_right && stripe_left < stripe_right) {
for (int i = 2; i <= titlebar_inner_rect.height() - 2; i += 2) {
@ -164,12 +164,11 @@ void ClassicWindowTheme::paint_notification_frame(Painter& painter, WindowMode w
painter.fill_rect_with_gradient(Gfx::Orientation::Vertical, titlebar_rect, palette.active_window_border1(), palette.active_window_border2());
if (palette.active_window_title_stripes().alpha() > 0) {
int stripe_top = close_button_rect.bottom() + 4;
int stripe_top = close_button_rect.bottom() + 3;
int stripe_bottom = window_rect.height() - 3;
if (stripe_top && stripe_bottom && stripe_top < stripe_bottom) {
for (int i = 2; i <= palette.window_title_height() - 2; i += 2) {
for (int i = 2; i <= palette.window_title_height() - 2; i += 2)
painter.draw_line({ titlebar_rect.x() + i, stripe_top }, { titlebar_rect.x() + i, stripe_bottom }, palette.active_window_title_stripes());
}
}
}
}
@ -208,7 +207,7 @@ Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, Windo
if (window_type == WindowType::Notification)
pos = titlebar_rect(window_type, window_mode, window_rect, palette).top() + 2;
else
pos = titlebar_text_rect(window_type, window_mode, window_rect, palette).right() + 1;
pos = titlebar_text_rect(window_type, window_mode, window_rect, palette).right();
for (size_t i = 0; i < buttons; i++) {
if (window_type == WindowType::Notification) {