1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 16:57:34 +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

@ -205,13 +205,12 @@ void CardPainter::paint_card_front(Gfx::Bitmap& bitmap, Cards::Suit suit, Cards:
painter.draw_text(text_rect, card_rank_label(rank), font, Gfx::TextAlignment::Center, suit_color);
painter.draw_bitmap(
{ text_rect.x() + (text_rect.width() - suit_symbol.size().width()) / 2, text_rect.bottom() + 5 },
{ text_rect.x() + (text_rect.width() - suit_symbol.size().width()) / 2, text_rect.bottom() + 4 },
suit_symbol, suit_color);
for (int y = Card::height / 2; y < Card::height; ++y) {
for (int x = 0; x < Card::width; ++x) {
for (int x = 0; x < Card::width; ++x)
bitmap.set_pixel(x, y, bitmap.get_pixel(Card::width - x - 1, Card::height - y - 1));
}
}
}

View file

@ -105,7 +105,7 @@ void AbstractScrollableWidget::custom_layout()
{
int vertical_scrollbar_width = m_vertical_scrollbar->effective_min_size().width().as_int();
m_vertical_scrollbar->set_relative_rect(
inner_rect.right() + 1 - vertical_scrollbar_width,
inner_rect.right() - vertical_scrollbar_width,
inner_rect.top() + height_wanted_by_banner_widget,
vertical_scrollbar_width,
inner_rect.height() - height_wanted_by_horizontal_scrollbar - height_wanted_by_banner_widget);
@ -115,14 +115,14 @@ void AbstractScrollableWidget::custom_layout()
int horizontal_scrollbar_height = m_horizontal_scrollbar->effective_min_size().height().as_int();
m_horizontal_scrollbar->set_relative_rect(
inner_rect.left(),
inner_rect.bottom() + 1 - horizontal_scrollbar_height,
inner_rect.bottom() - horizontal_scrollbar_height,
inner_rect.width() - width_wanted_by_vertical_scrollbar,
horizontal_scrollbar_height);
}
m_corner_widget->set_visible(m_vertical_scrollbar->is_visible() && m_horizontal_scrollbar->is_visible());
if (m_corner_widget->is_visible()) {
Gfx::IntRect corner_rect { m_horizontal_scrollbar->relative_rect().right() + 1, m_vertical_scrollbar->relative_rect().bottom() + 1, width_occupied_by_vertical_scrollbar(), height_occupied_by_horizontal_scrollbar() };
Gfx::IntRect corner_rect { m_horizontal_scrollbar->relative_rect().right(), m_vertical_scrollbar->relative_rect().bottom(), width_occupied_by_vertical_scrollbar(), height_occupied_by_horizontal_scrollbar() };
m_corner_widget->set_relative_rect(corner_rect);
}
}
@ -273,18 +273,16 @@ void AbstractScrollableWidget::scroll_into_view(Gfx::IntRect const& rect, bool s
return;
if (scroll_vertically) {
if (rect.top() < visible_content_rect.top()) {
if (rect.top() < visible_content_rect.top())
m_vertical_scrollbar->set_value(rect.top());
} else if (rect.top() > visible_content_rect.top() && rect.bottom() > visible_content_rect.bottom()) {
m_vertical_scrollbar->set_value(rect.bottom() - visible_content_rect.height() + 1);
}
else if (rect.top() > visible_content_rect.top() && rect.bottom() > visible_content_rect.bottom())
m_vertical_scrollbar->set_value(rect.bottom() - visible_content_rect.height());
}
if (scroll_horizontally) {
if (rect.left() < visible_content_rect.left()) {
if (rect.left() < visible_content_rect.left())
m_horizontal_scrollbar->set_value(rect.left());
} else if (rect.left() > visible_content_rect.left() && rect.right() > visible_content_rect.right()) {
m_horizontal_scrollbar->set_value(rect.right() - visible_content_rect.width() + 1);
}
else if (rect.left() > visible_content_rect.left() && rect.right() > visible_content_rect.right())
m_horizontal_scrollbar->set_value(rect.right() - visible_content_rect.width());
}
}

View file

@ -106,7 +106,7 @@ void AbstractThemePreview::paint_window(StringView title, Gfx::IntRect const& re
int window_button_width = m_preview_palette.window_title_button_width();
int window_button_height = m_preview_palette.window_title_button_height();
auto titlebar_text_rect = Gfx::WindowTheme::current().titlebar_text_rect(Gfx::WindowTheme::WindowType::Normal, Gfx::WindowTheme::WindowMode::Other, rect, m_preview_palette);
int pos = titlebar_text_rect.right() + 1;
int pos = titlebar_text_rect.right();
Array possible_buttons {
Button { {}, m_close_bitmap.is_null() ? m_default_close_bitmap : m_close_bitmap },

View file

@ -222,7 +222,7 @@ void Button::set_menu(RefPtr<GUI::Menu> menu)
void Button::mousedown_event(MouseEvent& event)
{
if (m_menu) {
m_menu->popup(screen_relative_rect().bottom_left(), {}, rect());
m_menu->popup(screen_relative_rect().bottom_left().moved_up(1), {}, rect());
update();
return;
}

View file

@ -64,7 +64,7 @@ void CheckBox::paint_event(PaintEvent& event)
auto box_rect = this->box_rect();
auto text_rect = rect();
if (m_checkbox_position == CheckBoxPosition::Left)
text_rect.set_left(box_rect.right() + 1 + gap_between_box_and_rect());
text_rect.set_left(box_rect.right() + gap_between_box_and_rect());
text_rect.set_width(font().width_rounded_up(text()));
text_rect.set_top(height() / 2 - font().pixel_size_rounded_up() / 2);
text_rect.set_height(font().pixel_size_rounded_up());

View file

@ -80,8 +80,8 @@ void ColumnsView::second_paint_event(PaintEvent& event)
auto column_right = column_x + m_rubber_band_origin_column.width;
// The rubber band rect always stays inside the widget inner rect, the vertical component is handled by mousemove
auto rubber_band_left = clamp(column_left, widget_inner_rect().left(), widget_inner_rect().right() + 1);
auto rubber_band_right = clamp(column_right, widget_inner_rect().left(), widget_inner_rect().right() + 1);
auto rubber_band_left = clamp(column_left, widget_inner_rect().left(), widget_inner_rect().right());
auto rubber_band_right = clamp(column_right, widget_inner_rect().left(), widget_inner_rect().right());
auto rubber_band_rect = Gfx::IntRect::from_two_points({ rubber_band_left, m_rubber_band_origin }, { rubber_band_right, m_rubber_band_current });
@ -155,7 +155,7 @@ void ColumnsView::paint_event(PaintEvent& event)
}
Gfx::IntRect text_rect = {
icon_rect.right() + 1 + icon_spacing(), row * item_height(),
icon_rect.right() + icon_spacing(), row * item_height(),
column.width - icon_spacing() - icon_size() - icon_spacing() - icon_spacing() - static_cast<int>(s_arrow_bitmap.width()) - icon_spacing(), item_height()
};
draw_item_text(painter, index, is_selected_row, text_rect, index.data().to_deprecated_string(), font_for_index(index), Gfx::TextAlignment::CenterLeft, Gfx::TextElision::None);
@ -172,7 +172,7 @@ void ColumnsView::paint_event(PaintEvent& event)
bool expandable = model()->row_count(index) > 0;
if (expandable) {
Gfx::IntRect arrow_rect = {
text_rect.right() + 1 + icon_spacing(), 0,
text_rect.right() + icon_spacing(), 0,
s_arrow_bitmap.width(), s_arrow_bitmap.height()
};
arrow_rect.center_vertically_within(row_rect);
@ -339,7 +339,7 @@ void ColumnsView::mousedown_event(MouseEvent& event)
void ColumnsView::mousemove_event(MouseEvent& event)
{
if (m_rubber_banding) {
m_rubber_band_current = clamp(event.position().y(), widget_inner_rect().top(), widget_inner_rect().bottom() + 1);
m_rubber_band_current = clamp(event.position().y(), widget_inner_rect().top(), widget_inner_rect().bottom());
auto parent = m_rubber_band_origin_column.parent_index;
int row_count = model()->row_count(parent);

View file

@ -246,11 +246,11 @@ void ComboBox::open()
auto max_height = min(m_list_view->item_height() * m_max_visible_items, m_list_view->content_height());
auto min_width = m_list_view->content_width() + frame;
Gfx::IntSize size { max(width(), min_width), max_height + frame };
Gfx::IntRect rect { screen_relative_rect().bottom_left(), size };
Gfx::IntRect rect { screen_relative_rect().bottom_left().moved_up(1), size };
auto desktop = Desktop::the().rect();
auto min_height = 5 * m_list_view->item_height() + frame;
auto go_upwards_instead = rect.bottom() >= desktop.height() && rect.intersected(desktop).height() < min_height;
auto go_upwards_instead = rect.bottom() - 1 >= desktop.height() && rect.intersected(desktop).height() < min_height;
if (go_upwards_instead) {
auto origin = screen_relative_rect().top_left();
rect = { Gfx::IntPoint { origin.x(), origin.y() - size.height() }, size };

View file

@ -81,8 +81,8 @@ HeaderView::VisibleSectionRange HeaderView::visible_section_range() const
auto section_count = this->section_count();
auto is_horizontal = m_orientation == Orientation::Horizontal;
auto rect = m_table_view.visible_content_rect();
auto start = is_horizontal ? rect.top_left().x() : rect.top_left().y();
auto end = is_horizontal ? (rect.top_left().x() + m_table_view.content_width()) : rect.bottom_left().y();
auto start = is_horizontal ? rect.left() : rect.top();
auto end = is_horizontal ? (rect.left() + m_table_view.content_width()) : rect.bottom() - 1;
auto offset = 0;
VisibleSectionRange range;
for (; range.end < section_count; ++range.end) {
@ -113,7 +113,7 @@ Gfx::IntRect HeaderView::section_resize_grabbable_rect(int section) const
if (m_orientation == Gfx::Orientation::Vertical)
return {};
auto rect = section_rect(section);
return { rect.right() - 1, rect.top(), 4, rect.height() };
return { rect.right() - 2, rect.top(), 4, rect.height() };
}
int HeaderView::section_count() const
@ -250,8 +250,8 @@ void HeaderView::mouseup_event(MouseEvent& event)
void HeaderView::paint_horizontal(Painter& painter)
{
painter.draw_line({ 0, 0 }, { rect().right(), 0 }, palette().threed_highlight());
painter.draw_line({ 0, rect().bottom() }, { rect().right(), rect().bottom() }, palette().threed_shadow1());
painter.draw_line({ 0, 0 }, { rect().right() - 1, 0 }, palette().threed_highlight());
painter.draw_line({ 0, rect().bottom() - 1 }, { rect().right() - 1, rect().bottom() - 1 }, palette().threed_shadow1());
auto range = visible_section_range();
int x_offset = range.start_offset;
for (int section = range.start; section < range.end; ++section) {
@ -283,7 +283,7 @@ void HeaderView::paint_horizontal(Painter& painter)
x_offset += section_width + m_table_view.horizontal_padding() * 2;
}
if (x_offset < rect().right()) {
if (x_offset < rect().right() - 1) {
Gfx::IntRect cell_rect(x_offset, 0, width() - x_offset, height());
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, false, false);
}
@ -291,8 +291,8 @@ void HeaderView::paint_horizontal(Painter& painter)
void HeaderView::paint_vertical(Painter& painter)
{
painter.draw_line(rect().top_left(), rect().bottom_left(), palette().threed_highlight());
painter.draw_line(rect().top_right(), rect().bottom_right(), palette().threed_shadow1());
painter.draw_line(rect().top_left(), rect().bottom_left().moved_up(1), palette().threed_highlight());
painter.draw_line(rect().top_right().moved_left(1), rect().bottom_right().translated(-1), palette().threed_shadow1());
auto range = visible_section_range();
int y_offset = range.start_offset;
for (int section = range.start; section < range.end; ++section) {
@ -312,7 +312,7 @@ void HeaderView::paint_vertical(Painter& painter)
y_offset += section_size;
}
if (y_offset < rect().bottom()) {
if (y_offset < rect().bottom() - 1) {
Gfx::IntRect cell_rect(0, y_offset, width(), height() - y_offset);
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, false, false);
}

View file

@ -431,7 +431,7 @@ void IconView::get_item_rects(int item_index, ItemData& item_data, Gfx::Font con
int unwrapped_text_width = font.width_rounded_up(item_data.text);
int available_width = item_rect.width() - 6;
item_data.text_rect = { 0, item_data.icon_rect.bottom() + 6 + 1, 0, font.pixel_size_rounded_up() };
item_data.text_rect = { 0, item_data.icon_rect.bottom() + 6, 0, font.pixel_size_rounded_up() };
item_data.wrapped_text_lines.clear();
if ((unwrapped_text_width > available_width) && (item_data.selected || m_hovered_index == item_data.index || cursor_index() == item_data.index || m_always_wrap_item_labels)) {
@ -789,7 +789,7 @@ inline IterationDecision IconView::for_each_item_intersecting_rect(Gfx::IntRect
int begin_row, begin_column;
column_row_from_content_position(rect.top_left(), begin_row, begin_column);
int end_row, end_column;
column_row_from_content_position(rect.bottom_right(), end_row, end_column);
column_row_from_content_position(rect.bottom_right().translated(-1), end_row, end_column);
int items_per_flow_axis_step;
int item_index;

View file

@ -118,8 +118,8 @@ void IncrementalSearchBanner::paint_event(PaintEvent& event)
Painter painter(*this);
painter.add_clip_rect(event.rect());
painter.draw_line({ 0, rect().bottom() - 1 }, { width(), rect().bottom() - 1 }, palette().threed_shadow1());
painter.draw_line({ 0, rect().bottom() }, { width(), rect().bottom() }, palette().threed_shadow2());
painter.draw_line({ 0, rect().bottom() - 2 }, { width(), rect().bottom() - 2 }, palette().threed_shadow1());
painter.draw_line({ 0, rect().bottom() - 1 }, { width(), rect().bottom() - 1 }, palette().threed_shadow2());
}
Optional<UISize> IncrementalSearchBanner::calculated_min_size() const

View file

@ -98,7 +98,7 @@ void LinkLabel::paint_event(PaintEvent& event)
GUI::Painter painter(*this);
if (m_hovered)
painter.draw_line({ 0, rect().bottom() }, { font().width_rounded_up(text()), rect().bottom() }, palette().link());
painter.draw_line({ 0, rect().bottom() - 1 }, { font().width_rounded_up(text()), rect().bottom() - 1 }, palette().link());
if (is_focused())
painter.draw_focus_rect(text_rect(), palette().focus_outline());

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());
}

View file

@ -51,7 +51,7 @@ void RadioButton::paint_event(PaintEvent& event)
Gfx::StylePainter::paint_radio_button(painter, circle_rect, palette(), is_checked(), is_being_pressed());
Gfx::IntRect text_rect { circle_rect.right() + 5 + horizontal_padding(), 0, font().width_rounded_up(text()), font().pixel_size_rounded_up() };
Gfx::IntRect text_rect { circle_rect.right() + 4 + horizontal_padding(), 0, font().width_rounded_up(text()), font().pixel_size_rounded_up() };
text_rect.center_vertically_within(rect());
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);

View file

@ -179,21 +179,21 @@ void Scrollbar::paint_event(PaintEvent& event)
Gfx::IntRect rect_to_fill = rect();
if (orientation() == Orientation::Vertical) {
if (m_gutter_click_state == GutterClickState::BeforeScrubber) {
rect_to_fill.set_top(decrement_button_rect().bottom());
rect_to_fill.set_bottom(scrubber_rect().top());
rect_to_fill.set_top(decrement_button_rect().bottom() - 1);
rect_to_fill.set_bottom(scrubber_rect().top() + 1);
} else {
VERIFY(m_gutter_click_state == GutterClickState::AfterScrubber);
rect_to_fill.set_top(scrubber_rect().bottom());
rect_to_fill.set_bottom(increment_button_rect().top());
rect_to_fill.set_top(scrubber_rect().bottom() - 1);
rect_to_fill.set_bottom(increment_button_rect().top() + 1);
}
} else {
if (m_gutter_click_state == GutterClickState::BeforeScrubber) {
rect_to_fill.set_left(decrement_button_rect().right());
rect_to_fill.set_right(scrubber_rect().left());
rect_to_fill.set_left(decrement_button_rect().right() - 1);
rect_to_fill.set_right(scrubber_rect().left() + 1);
} else {
VERIFY(m_gutter_click_state == GutterClickState::AfterScrubber);
rect_to_fill.set_left(scrubber_rect().right());
rect_to_fill.set_right(increment_button_rect().left());
rect_to_fill.set_left(scrubber_rect().right() - 1);
rect_to_fill.set_right(increment_button_rect().left() + 1);
}
}
painter.fill_rect_with_dither_pattern(rect_to_fill, palette().button(), palette().button().lightened(0.77f));

View file

@ -29,12 +29,12 @@ void SeparatorWidget::paint_event(PaintEvent& event)
if (m_orientation == Gfx::Orientation::Vertical) {
painter.translate(rect().center().x() - 1, 0);
painter.draw_line({ 0, 0 }, { 0, rect().bottom() }, palette().threed_shadow1());
painter.draw_line({ 1, 0 }, { 1, rect().bottom() }, palette().threed_highlight());
painter.draw_line({ 0, 0 }, { 0, rect().bottom() - 1 }, palette().threed_shadow1());
painter.draw_line({ 1, 0 }, { 1, rect().bottom() - 1 }, palette().threed_highlight());
} else {
painter.translate(0, rect().center().y() - 1);
painter.draw_line({ 0, 0 }, { rect().right(), 0 }, palette().threed_shadow1());
painter.draw_line({ 0, 1 }, { rect().right(), 1 }, palette().threed_highlight());
painter.draw_line({ 0, 0 }, { rect().right() - 1, 0 }, palette().threed_shadow1());
painter.draw_line({ 0, 1 }, { rect().right() - 1, 1 }, palette().threed_highlight());
}
}

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;
}

View file

@ -53,7 +53,7 @@ void TableView::paint_event(PaintEvent& event)
bool dummy;
int first_visible_row = index_at_event_position(frame_inner_rect().top_left().translated(x_offset, y_offset), dummy).row();
int last_visible_row = index_at_event_position(frame_inner_rect().bottom_right().translated(x_offset, y_offset), dummy).row();
int last_visible_row = index_at_event_position(frame_inner_rect().bottom_right().translated(-1).translated(x_offset, y_offset), dummy).row();
if (first_visible_row == -1)
first_visible_row = 0;
@ -136,9 +136,9 @@ void TableView::paint_event(PaintEvent& event)
}
if (m_grid_style == GridStyle::Horizontal || m_grid_style == GridStyle::Both)
painter.draw_line(cell_rect_for_fill.bottom_left(), cell_rect_for_fill.bottom_right(), palette().ruler());
painter.draw_line(cell_rect_for_fill.bottom_left().moved_up(1), cell_rect_for_fill.bottom_right().translated(-1), palette().ruler());
if (m_grid_style == GridStyle::Vertical || m_grid_style == GridStyle::Both)
painter.draw_line(cell_rect_for_fill.top_right(), cell_rect_for_fill.bottom_right(), palette().ruler());
painter.draw_line(cell_rect_for_fill.top_right().moved_left(1), cell_rect_for_fill.bottom_right().translated(-1), palette().ruler());
if (selection_behavior() == SelectionBehavior::SelectItems && cell_index == cursor_index())
painter.draw_rect(cell_rect_for_fill, palette().text_cursor());
@ -173,7 +173,7 @@ void TableView::second_paint_event(PaintEvent& event)
// The rubber band rect always borders the widget inner to the left and right
auto rubber_band_left = widget_inner_rect().left();
auto rubber_band_right = widget_inner_rect().right() + 1;
auto rubber_band_right = widget_inner_rect().right();
auto rubber_band_rect = Gfx::IntRect::from_two_points({ rubber_band_left, m_rubber_band_origin }, { rubber_band_right, m_rubber_band_current });
@ -250,7 +250,7 @@ void TableView::mousemove_event(MouseEvent& event)
{
if (m_rubber_banding) {
// The rubber band rect cannot go outside the bounds of the rect enclosing all rows
m_rubber_band_current = clamp(event.position().y(), widget_inner_rect().top() + column_header().height(), widget_inner_rect().bottom() + 1);
m_rubber_band_current = clamp(event.position().y(), widget_inner_rect().top() + column_header().height(), widget_inner_rect().bottom());
int row_count = model()->row_count();

View file

@ -114,7 +114,7 @@ void PasswordBox::paint_event(PaintEvent& event)
painter.fill_ellipse(dot_indicator_rect, icon_color);
Gfx::IntPoint arc_start_point { dot_indicator_rect.x() - dot_indicator_padding / 2, dot_indicator_rect.y() + dot_indicator_padding / 2 };
Gfx::IntPoint arc_end_point = { dot_indicator_rect.top_right().x() + dot_indicator_padding / 2, dot_indicator_rect.top_right().y() + dot_indicator_padding / 2 };
Gfx::IntPoint arc_end_point = { dot_indicator_rect.right() - 1 + dot_indicator_padding / 2, dot_indicator_rect.top() + dot_indicator_padding / 2 };
Gfx::IntPoint arc_center_point = { dot_indicator_rect.center().x(), dot_indicator_rect.top() - dot_indicator_padding };
painter.draw_quadratic_bezier_curve(arc_center_point, arc_start_point, arc_end_point, icon_color, 1);
}

View file

@ -167,11 +167,11 @@ TextPosition TextEditor::text_position_at_content_position(Gfx::IntPoint content
continue;
auto& rect = m_line_data[i]->visual_rect;
if (position.y() >= rect.top() && position.y() <= rect.bottom()) {
if (rect.contains_vertically(position.y())) {
line_index = i;
break;
}
if (position.y() > rect.bottom())
if (position.y() >= rect.bottom())
line_index = last_visible_line_index;
}
line_index = max((size_t)0, min(line_index, last_visible_line_index));
@ -473,7 +473,7 @@ Gfx::IntRect TextEditor::gutter_indicator_rect(size_t line_number, int indicator
auto gutter_rect = gutter_content_rect(line_number);
auto indicator_size = gutter_rect.height();
return Gfx::IntRect {
gutter_rect.right() - static_cast<int>(lroundf(indicator_size * (indicator_position + 1.5f))),
gutter_rect.right() - 1 - static_cast<int>(lroundf(indicator_size * (indicator_position + 1.5f))),
gutter_rect.top(),
indicator_size,
indicator_size
@ -538,7 +538,7 @@ void TextEditor::paint_event(PaintEvent& event)
}
if (attributes.underline_style.has_value()) {
auto bottom_left = [&]() {
auto point = rect.bottom_left().translated(0, 1);
auto point = rect.bottom_left();
if constexpr (IsSame<RemoveCVReference<decltype(rect)>, Gfx::IntRect>)
return point;
@ -547,7 +547,7 @@ void TextEditor::paint_event(PaintEvent& event)
};
auto bottom_right = [&]() {
auto point = rect.bottom_right().translated(0, 1);
auto point = rect.bottom_right().translated(-1, 0);
if constexpr (IsSame<RemoveCVReference<decltype(rect)>, Gfx::IntRect>)
return point;
@ -584,13 +584,13 @@ void TextEditor::paint_event(PaintEvent& event)
auto gutter_rect = gutter_rect_in_inner_coordinates();
painter.fill_rect(gutter_rect, palette().gutter());
if (!m_ruler_visible)
painter.draw_line(gutter_rect.top_right(), gutter_rect.bottom_right(), palette().gutter_border());
painter.draw_line(gutter_rect.top_right().translated(-1, 0), gutter_rect.bottom_right().translated(-1), palette().gutter_border());
}
if (m_ruler_visible) {
auto ruler_rect = ruler_rect_in_inner_coordinates().inflated(0, folding_indicator_width(), 0, 0);
painter.fill_rect(ruler_rect, palette().ruler());
painter.draw_line(ruler_rect.top_right(), ruler_rect.bottom_right(), palette().ruler_border());
painter.draw_line(ruler_rect.top_right().translated(-1, 0), ruler_rect.bottom_right().translated(-1), palette().ruler_border());
// Paint +/- buttons for folding regions
for (auto const& folding_region : document().folding_regions()) {
@ -606,7 +606,7 @@ void TextEditor::paint_event(PaintEvent& event)
}
size_t first_visible_line = text_position_at(event.rect().top_left()).line();
size_t last_visible_line = text_position_at(event.rect().bottom_right()).line();
size_t last_visible_line = text_position_at(event.rect().bottom_right().translated(-1)).line();
auto selection = normalized_selection();
bool has_selection = selection.is_valid();
@ -855,7 +855,7 @@ void TextEditor::paint_event(PaintEvent& event)
int selection_right = selection_ends_on_current_visual_line
? content_x_for_position({ line_index, (size_t)selection_end_column_within_line })
: visual_line_rect.right() + 1;
: visual_line_rect.right();
Gfx::IntRect selection_rect {
selection_left,
@ -1842,7 +1842,7 @@ void TextEditor::try_show_autocomplete(UserRequestedAutocomplete user_requested_
{
force_update_autocomplete([&, user_requested_autocomplete = move(user_requested_autocomplete)] {
if (user_requested_autocomplete == Yes || m_autocomplete_box->has_suggestions()) {
auto position = content_rect_for_position(cursor()).translated(0, -visible_content_rect().y()).bottom_right().translated(screen_relative_rect().top_left().translated(ruler_width(), 0).translated(10, 5));
auto position = content_rect_for_position(cursor()).translated(0, -visible_content_rect().y()).bottom_right().translated(screen_relative_rect().top_left().translated(ruler_width(), 0).translated(9, 4));
m_autocomplete_box->show(position);
}
});

View file

@ -169,7 +169,7 @@ Optional<UISize> Toolbar::calculated_min_size() const
ErrorOr<void> Toolbar::create_overflow_objects()
{
m_overflow_action = Action::create("Overflow Menu", { Mod_Ctrl | Mod_Shift, Key_O }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/overflow-menu.png"sv)), [&](auto&) {
m_overflow_menu->popup(m_overflow_button->screen_relative_rect().bottom_left(), {}, m_overflow_button->rect());
m_overflow_menu->popup(m_overflow_button->screen_relative_rect().bottom_left().moved_up(1), {}, m_overflow_button->rect());
});
m_overflow_action->set_status_tip("Show hidden toolbar actions");
m_overflow_action->set_enabled(false);

View file

@ -31,8 +31,8 @@ void ToolbarContainer::paint_event(GUI::PaintEvent& event)
for_each_child_widget([&](auto& widget) {
if (widget.is_visible()) {
auto rect = widget.relative_rect();
painter.draw_line(rect.top_left().translated(0, -1), rect.top_right().translated(0, -1), palette().threed_highlight());
painter.draw_line(rect.bottom_left().translated(0, 1), rect.bottom_right().translated(0, 1), palette().threed_shadow1());
painter.draw_line(rect.top_left().moved_up(1), rect.top_right().translated(-1), palette().threed_highlight());
painter.draw_line(rect.bottom_left(), rect.bottom_right().moved_left(1), palette().threed_shadow1());
}
return IterationDecision::Continue;
});

View file

@ -82,7 +82,7 @@ void Tray::paint_event(GUI::PaintEvent& event)
icon_rect.center_vertically_within(rect);
Gfx::IntRect text_rect {
icon_rect.right() + 5,
icon_rect.right() + 4,
rect.y(),
rect.width(),
rect.height(),

View file

@ -327,7 +327,7 @@ void TreeView::paint_event(PaintEvent& event)
Gfx::IntRect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() };
icon_rect.center_vertically_within(rect);
Gfx::IntRect background_rect = {
icon_rect.right() + 1 + icon_spacing(), rect.y(),
icon_rect.right() + icon_spacing(), rect.y(),
min(rect.width(), column_width - indent_width) - icon_size() - icon_spacing(), rect.height()
};
Gfx::IntRect text_rect = background_rect.shrunken(text_padding() * 2, 0);

View file

@ -84,7 +84,7 @@ void ValueSlider::paint_event(PaintEvent& event)
painter.fill_rect_with_gradient(m_orientation, bar_rect(), palette().inactive_window_border1(), palette().inactive_window_border2());
auto unfilled_rect = bar_rect();
unfilled_rect.set_left(knob_rect().right());
unfilled_rect.set_left(knob_rect().right() - 1);
painter.fill_rect(unfilled_rect, palette().base());
Gfx::StylePainter::paint_frame(painter, bar_rect(), palette(), Gfx::FrameStyle::SunkenContainer);
@ -143,7 +143,7 @@ int ValueSlider::value_at(Gfx::IntPoint position) const
float leftmost_knob_center = (float)bar_rect().left() + (float)knob_thickness / 2;
if (position.x() < leftmost_knob_center)
return min();
float rightmost_knob_center = (float)bar_rect().right() - (float)knob_thickness / 2;
float rightmost_knob_center = (float)(bar_rect().right() - 1) - (float)knob_thickness / 2;
if (position.x() > rightmost_knob_center)
return max();
float relative_offset = (float)(position.x() - leftmost_knob_center) / (rightmost_knob_center - leftmost_knob_center);

View file

@ -354,7 +354,7 @@ void Widget::handle_keydown_event(KeyEvent& event)
}
if (event.key() == KeyCode::Key_Menu) {
ContextMenuEvent c_event(window_relative_rect().bottom_right(), screen_relative_rect().bottom_right());
ContextMenuEvent c_event(window_relative_rect().bottom_right().translated(-1), screen_relative_rect().bottom_right().translated(-1));
dispatch_event(c_event);
return;
}

View file

@ -204,9 +204,9 @@ template<>
FloatRect AffineTransform::map(FloatRect const& rect) const
{
FloatPoint p1 = map(rect.top_left());
FloatPoint p2 = map(rect.top_right().translated(1, 0));
FloatPoint p3 = map(rect.bottom_right().translated(1, 1));
FloatPoint p4 = map(rect.bottom_left().translated(0, 1));
FloatPoint p2 = map(rect.top_right());
FloatPoint p3 = map(rect.bottom_right());
FloatPoint p4 = map(rect.bottom_left());
float left = smallest_of(p1.x(), p2.x(), p3.x(), p4.x());
float top = smallest_of(p1.y(), p2.y(), p3.y(), p4.y());
float right = largest_of(p1.x(), p2.x(), p3.x(), p4.x());

View file

@ -683,11 +683,11 @@ void AntiAliasingPainter::fill_rect_with_rounded_corners(IntRect const& a_rect,
if (top_left)
fill_corner(top_left_corner, bounding_rect.top_left(), top_left);
if (top_right)
fill_corner(top_right_corner, bounding_rect.top_right(), top_right);
fill_corner(top_right_corner, bounding_rect.top_right().moved_left(1), top_right);
if (bottom_left)
fill_corner(bottom_left_corner, bounding_rect.bottom_left(), bottom_left);
fill_corner(bottom_left_corner, bounding_rect.bottom_left().moved_up(1), bottom_left);
if (bottom_right)
fill_corner(bottom_right_corner, bounding_rect.bottom_right(), bottom_right);
fill_corner(bottom_right_corner, bounding_rect.bottom_right().translated(-1), bottom_right);
}
void AntiAliasingPainter::stroke_segment_intersection(FloatPoint current_line_a, FloatPoint current_line_b, FloatLine const& previous_line, Color color, float thickness)

View file

@ -280,12 +280,12 @@ void ClassicStylePainter::paint_frame(Painter& painter, IntRect const& rect, Pal
VERIFY_NOT_REACHED();
}
painter.draw_line(rect.top_left(), rect.top_right(), top_left_color);
painter.draw_line(rect.bottom_left(), rect.bottom_right(), bottom_right_color);
painter.draw_line(rect.top_left(), rect.top_right().moved_left(1), top_left_color);
painter.draw_line(rect.bottom_left().moved_up(1), rect.bottom_right().translated(-1), bottom_right_color);
if ((style != FrameStyle::SunkenPanel && style != FrameStyle::RaisedPanel) || !skip_vertical_lines) {
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), top_left_color);
painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), bottom_right_color);
painter.draw_line(rect.top_left().moved_down(1), rect.bottom_left().moved_up(2), top_left_color);
painter.draw_line(rect.top_right().moved_left(1), rect.bottom_right().translated(-1, -2), bottom_right_color);
}
if (style == FrameStyle::RaisedContainer || style == FrameStyle::SunkenContainer) {
@ -302,19 +302,19 @@ void ClassicStylePainter::paint_frame(Painter& painter, IntRect const& rect, Pal
bottom_right_color = light_shade;
}
IntRect inner_container_frame_rect = rect.shrunken(2, 2);
painter.draw_line(inner_container_frame_rect.top_left(), inner_container_frame_rect.top_right(), top_left_color);
painter.draw_line(inner_container_frame_rect.bottom_left(), inner_container_frame_rect.bottom_right(), bottom_right_color);
painter.draw_line(inner_container_frame_rect.top_left().translated(0, 1), inner_container_frame_rect.bottom_left().translated(0, -1), top_left_color);
painter.draw_line(inner_container_frame_rect.top_right(), inner_container_frame_rect.bottom_right().translated(0, -1), bottom_right_color);
painter.draw_line(inner_container_frame_rect.top_left(), inner_container_frame_rect.top_right().moved_left(1), top_left_color);
painter.draw_line(inner_container_frame_rect.bottom_left().moved_up(1), inner_container_frame_rect.bottom_right().translated(-1), bottom_right_color);
painter.draw_line(inner_container_frame_rect.top_left().moved_down(1), inner_container_frame_rect.bottom_left().moved_up(2), top_left_color);
painter.draw_line(inner_container_frame_rect.top_right().moved_left(1), inner_container_frame_rect.bottom_right().translated(-1, -2), bottom_right_color);
}
if (style == FrameStyle::RaisedBox || style == FrameStyle::SunkenBox) {
swap(top_left_color, bottom_right_color);
IntRect inner_rect = rect.shrunken(2, 2);
painter.draw_line(inner_rect.top_left(), inner_rect.top_right(), top_left_color);
painter.draw_line(inner_rect.bottom_left(), inner_rect.bottom_right(), bottom_right_color);
painter.draw_line(inner_rect.top_left().translated(0, 1), inner_rect.bottom_left().translated(0, -1), top_left_color);
painter.draw_line(inner_rect.top_right(), inner_rect.bottom_right().translated(0, -1), bottom_right_color);
painter.draw_line(inner_rect.top_left(), inner_rect.top_right().moved_left(1), top_left_color);
painter.draw_line(inner_rect.bottom_left().moved_up(1), inner_rect.bottom_right().translated(-1), bottom_right_color);
painter.draw_line(inner_rect.top_left().moved_down(1), inner_rect.bottom_left().moved_up(2), top_left_color);
painter.draw_line(inner_rect.top_right().moved_left(1), inner_rect.bottom_right().translated(-1, -2), bottom_right_color);
}
}
@ -342,22 +342,22 @@ void ClassicStylePainter::paint_window_frame(Painter& painter, IntRect const& re
rect.height() - border_thickness },
base_color, border_thickness);
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left(), base_color);
painter.draw_line(rect.top_left().translated(1, 1), rect.top_right().translated(-1, 1), light_shade);
painter.draw_line(rect.top_left().translated(1, 1), rect.bottom_left().translated(1, -1), light_shade);
painter.draw_line(rect.top_left().translated(2, 2), rect.top_right().translated(-2, 2), base_color);
painter.draw_line(rect.top_left().translated(2, 2), rect.bottom_left().translated(2, -2), base_color);
painter.draw_line(rect.top_left().translated(3, 3), rect.top_right().translated(-3, 3), base_color);
painter.draw_line(rect.top_left().translated(3, 3), rect.bottom_left().translated(3, -3), base_color);
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), base_color);
painter.draw_line(rect.top_left().translated(1, 1), rect.top_right().translated(-2, 1), light_shade);
painter.draw_line(rect.top_left().translated(1, 1), rect.bottom_left().translated(1, -2), light_shade);
painter.draw_line(rect.top_left().translated(2, 2), rect.top_right().translated(-3, 2), base_color);
painter.draw_line(rect.top_left().translated(2, 2), rect.bottom_left().translated(2, -3), base_color);
painter.draw_line(rect.top_left().translated(3, 3), rect.top_right().translated(-4, 3), base_color);
painter.draw_line(rect.top_left().translated(3, 3), rect.bottom_left().translated(3, -4), base_color);
painter.draw_line(rect.top_right(), rect.bottom_right(), dark_shade);
painter.draw_line(rect.top_right().translated(-1, 1), rect.bottom_right().translated(-1, -1), mid_shade);
painter.draw_line(rect.top_right().translated(-2, 2), rect.bottom_right().translated(-2, -2), base_color);
painter.draw_line(rect.top_right().translated(-3, 3), rect.bottom_right().translated(-3, -3), base_color);
painter.draw_line(rect.bottom_left(), rect.bottom_right(), dark_shade);
painter.draw_line(rect.bottom_left().translated(1, -1), rect.bottom_right().translated(-1, -1), mid_shade);
painter.draw_line(rect.bottom_left().translated(2, -2), rect.bottom_right().translated(-2, -2), base_color);
painter.draw_line(rect.bottom_left().translated(3, -3), rect.bottom_right().translated(-3, -3), base_color);
painter.draw_line(rect.top_right().translated(-1, 0), rect.bottom_right().translated(-1, -1), dark_shade);
painter.draw_line(rect.top_right().translated(-2, 1), rect.bottom_right().translated(-2, -2), mid_shade);
painter.draw_line(rect.top_right().translated(-3, 2), rect.bottom_right().translated(-3, -3), base_color);
painter.draw_line(rect.top_right().translated(-4, 3), rect.bottom_right().translated(-4, -4), base_color);
painter.draw_line(rect.bottom_left().translated(0, -1), rect.bottom_right().translated(-1, -1), dark_shade);
painter.draw_line(rect.bottom_left().translated(1, -2), rect.bottom_right().translated(-2, -2), mid_shade);
painter.draw_line(rect.bottom_left().translated(2, -3), rect.bottom_right().translated(-3, -3), base_color);
painter.draw_line(rect.bottom_left().translated(3, -4), rect.bottom_right().translated(-4, -4), base_color);
}
void ClassicStylePainter::paint_progressbar(Painter& painter, IntRect const& rect, Palette const& palette, int min, int max, int value, StringView text, Orientation orientation)
@ -624,7 +624,7 @@ void ClassicStylePainter::paint_simple_rect_shadow(Painter& painter, IntRect con
auto half_width = containing_horizontal_rect.width() / 2;
int corner_piece_width = min(containing_horizontal_rect.width() / 2, base_size * 2);
int left_corners_right = containing_horizontal_rect.left() + corner_piece_width;
int right_corners_left = max(containing_horizontal_rect.right() - corner_piece_width + 1, left_corners_right + 1);
int right_corners_left = max(containing_horizontal_rect.right() - corner_piece_width, left_corners_right + 1);
auto paint_horizontal = [&](int y, int src_row) {
if (half_width <= 0)
return;
@ -639,7 +639,7 @@ void ClassicStylePainter::paint_simple_rect_shadow(Painter& painter, IntRect con
};
paint_horizontal(containing_rect.top(), 0);
paint_horizontal(containing_rect.bottom() - base_size + 1, 1);
paint_horizontal(containing_rect.bottom() - base_size, 1);
int corner_piece_height = min(half_height, base_size);
int top_corners_bottom = base_size + corner_piece_height;
@ -658,7 +658,7 @@ void ClassicStylePainter::paint_simple_rect_shadow(Painter& painter, IntRect con
paint_vertical(containing_rect.left(), 0, horizontal_shift, 0);
if (shadow_includes_frame)
horizontal_shift = 0; // TODO: fix off-by-one on rectangles barely wide enough
paint_vertical(containing_rect.right() - base_size + 1, 1, 0, horizontal_shift);
paint_vertical(containing_rect.right() - base_size, 1, 0, horizontal_shift);
if (fill_content) {
// Fill the enclosed rectangle with the RGBA color of the right-bottom pixel of the TL tile

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) {

View file

@ -68,7 +68,7 @@ ALWAYS_INLINE void Painter::draw_scanline_for_fill_path(int y, T x_start, T x_en
if (paint_left_subpixel)
set_physical_pixel(clipped.top_left(), get_color_with_alpha(0, left_subpixel_alpha), true);
if (paint_right_subpixel)
set_physical_pixel(clipped.top_right(), get_color_with_alpha(scanline.width(), right_subpixel_alpha), true);
set_physical_pixel(clipped.top_right().moved_left(1), get_color_with_alpha(scanline.width(), right_subpixel_alpha), true);
clipped.shrink(0, paint_right_subpixel, 0, paint_left_subpixel);
if (clipped.is_empty())
return;
@ -82,9 +82,8 @@ ALWAYS_INLINE void Painter::draw_scanline_for_fill_path(int y, T x_start, T x_en
}
}
for (int x = clipped.x(); x <= clipped.right(); x++) {
for (int x = clipped.x(); x < clipped.right(); x++)
set_physical_pixel({ x, clipped.y() }, get_color(x - scanline.x()), true);
}
}
[[maybe_unused]] inline void approximately_place_on_int_grid(FloatPoint ffrom, FloatPoint fto, IntPoint& from, IntPoint& to, Optional<IntPoint> previous_to)
@ -144,8 +143,8 @@ void Painter::fill_path_impl(Path const& path, ColorOrFunction color, Gfx::Paint
active_list.ensure_capacity(segments.size());
// first, grab the segments for the very first scanline
GridCoordinateType first_y = path.bounding_box().bottom_right().y() + 1;
GridCoordinateType last_y = path.bounding_box().top_left().y() - 1;
GridCoordinateType first_y = path.bounding_box().bottom();
GridCoordinateType last_y = path.bounding_box().top() - 1;
float scanline = first_y;
size_t last_active_segment { 0 };

View file

@ -110,7 +110,7 @@ public:
FloatVector3 value(0, 0, 0);
for (auto k = 0l; k < (ssize_t)N; ++k) {
auto ki = i + k - offset;
if (ki < source_rect.x() || ki > source_rect.right()) {
if (ki < source_rect.x() || ki >= source_rect.right()) {
if (parameters.should_wrap())
ki = (ki + source.size().width()) % source.size().width(); // TODO: fix up using source_rect
else
@ -119,7 +119,7 @@ public:
for (auto l = 0l; l < (ssize_t)N; ++l) {
auto lj = j + l - offset;
if (lj < source_rect.y() || lj > source_rect.bottom()) {
if (lj < source_rect.y() || lj >= source_rect.bottom()) {
if (parameters.should_wrap())
lj = (lj + source.size().height()) % source.size().height(); // TODO: fix up using source_rect
else

View file

@ -560,18 +560,14 @@ static void for_each_pixel_around_rect_clockwise(RectType const& rect, Callback
{
if (rect.is_empty())
return;
for (auto x = rect.left(); x <= rect.right(); ++x) {
for (auto x = rect.left(); x < rect.right(); ++x)
callback(x, rect.top());
}
for (auto y = rect.top() + 1; y <= rect.bottom(); ++y) {
callback(rect.right(), y);
}
for (auto x = rect.right() - 1; x >= rect.left(); --x) {
callback(x, rect.bottom());
}
for (auto y = rect.bottom() - 1; y > rect.top(); --y) {
for (auto y = rect.top() + 1; y < rect.bottom(); ++y)
callback(rect.right() - 1, y);
for (auto x = rect.right() - 2; x >= rect.left(); --x)
callback(x, rect.bottom() - 1);
for (auto y = rect.bottom() - 2; y > rect.top(); --y)
callback(rect.left(), y);
}
}
void Painter::draw_focus_rect(IntRect const& rect, Color color)
@ -596,17 +592,17 @@ void Painter::draw_rect(IntRect const& a_rect, Color color, bool rough)
return;
int min_y = clipped_rect.top();
int max_y = clipped_rect.bottom();
int max_y = clipped_rect.bottom() - 1;
int scale = this->scale();
if (rect.top() >= clipped_rect.top() && rect.top() <= clipped_rect.bottom()) {
if (rect.top() >= clipped_rect.top() && rect.top() < clipped_rect.bottom()) {
int start_x = rough ? max(rect.x() + 1, clipped_rect.x()) : clipped_rect.x();
int width = rough ? min(rect.width() - 2, clipped_rect.width()) : clipped_rect.width();
for (int i = 0; i < scale; ++i)
fill_physical_scanline_with_draw_op(rect.top() * scale + i, start_x * scale, width * scale, color);
++min_y;
}
if (rect.bottom() >= clipped_rect.top() && rect.bottom() <= clipped_rect.bottom()) {
if (rect.bottom() > clipped_rect.top() && rect.bottom() <= clipped_rect.bottom()) {
int start_x = rough ? max(rect.x() + 1, clipped_rect.x()) : clipped_rect.x();
int width = rough ? min(rect.width() - 2, clipped_rect.width()) : clipped_rect.width();
for (int i = 0; i < scale; ++i)
@ -624,7 +620,7 @@ void Painter::draw_rect(IntRect const& a_rect, Color color, bool rough)
for (int i = 0; i < scale; ++i)
set_physical_pixel_with_draw_op(bits[rect.left() * scale + i], color);
for (int i = 0; i < scale; ++i)
set_physical_pixel_with_draw_op(bits[rect.right() * scale + i], color);
set_physical_pixel_with_draw_op(bits[(rect.right() - 1) * scale + i], color);
}
} else {
for (int y = min_y * scale; y <= max_y * scale; ++y) {
@ -634,7 +630,7 @@ void Painter::draw_rect(IntRect const& a_rect, Color color, bool rough)
set_physical_pixel_with_draw_op(bits[rect.left() * scale + i], color);
if (draw_right_side)
for (int i = 0; i < scale; ++i)
set_physical_pixel_with_draw_op(bits[rect.right() * scale + i], color);
set_physical_pixel_with_draw_op(bits[(rect.right() - 1) * scale + i], color);
}
}
}
@ -672,8 +668,8 @@ void Painter::draw_bitmap(IntPoint p, CharacterBitmap const& bitmap, Color color
char const* bitmap_row = &bitmap.bits()[first_row * bitmap.width() + first_column];
size_t const bitmap_skip = bitmap.width();
for (int row = first_row; row <= last_row; ++row) {
for (int j = 0; j <= (last_column - first_column); ++j) {
for (int row = first_row; row < last_row; ++row) {
for (int j = 0; j < (last_column - first_column); ++j) {
char fc = bitmap_row[j];
if (fc == '#')
dst[j] = color.value();
@ -700,16 +696,16 @@ void Painter::draw_bitmap(IntPoint p, GlyphBitmap const& bitmap, Color color)
size_t const dst_skip = m_target->pitch() / sizeof(ARGB32);
if (scale == 1) {
for (int row = first_row; row <= last_row; ++row) {
for (int j = 0; j <= (last_column - first_column); ++j) {
for (int row = first_row; row < last_row; ++row) {
for (int j = 0; j < (last_column - first_column); ++j) {
if (bitmap.bit_at(j + first_column, row))
dst[j] = color_for_format(dst_format, dst[j]).blend(color).value();
}
dst += dst_skip;
}
} else {
for (int row = first_row; row <= last_row; ++row) {
for (int j = 0; j <= (last_column - first_column); ++j) {
for (int row = first_row; row < last_row; ++row) {
for (int j = 0; j < (last_column - first_column); ++j) {
if (bitmap.bit_at((j + first_column), row)) {
for (int iy = 0; iy < scale; ++iy)
for (int ix = 0; ix < scale; ++ix) {
@ -753,7 +749,7 @@ void Painter::draw_triangle(IntPoint a, IntPoint b, IntPoint c, Color color)
// return if top is below clip rect or bottom is above clip rect
auto clip = clip_rect();
if (p0.y() >= clip.bottom())
if (p0.y() >= clip.bottom() - 1)
return;
if (p2.y() < clip.top())
return;
@ -801,7 +797,7 @@ void Painter::draw_triangle(IntPoint a, IntPoint b, IntPoint c, Color color)
int rgba = color.value();
for (int y = max(p0.y(), clip.top()); y <= min(p2.y(), clip.bottom()); y++) {
for (int y = max(p0.y(), clip.top()); y < min(p2.y() + 1, clip.bottom()); y++) {
Optional<int>
x0 = l0.intersection_on_x(y),
x1 = l1.intersection_on_x(y),
@ -827,9 +823,8 @@ void Painter::draw_triangle(IntPoint a, IntPoint b, IntPoint c, Color color)
int left_bound = result_a, right_bound = result_b;
ARGB32* scanline = m_target->scanline(y);
for (int x = max(left_bound, clip.left()); x <= min(right_bound, clip.right()); x++) {
for (int x = max(left_bound, clip.left()); x <= min(right_bound, clip.right() - 1); x++)
scanline[x] = rgba;
}
}
}
@ -920,8 +915,8 @@ void Painter::blit_with_opacity(IntPoint position, Gfx::Bitmap const& source, In
.dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(),
.src_pitch = source.pitch() / sizeof(ARGB32),
.dst_pitch = m_target->pitch() / sizeof(ARGB32),
.row_count = last_row - first_row + 1,
.column_count = last_column - first_column + 1,
.row_count = last_row - first_row,
.column_count = last_column - first_column,
.opacity = opacity,
.src_format = source.format(),
};
@ -968,8 +963,8 @@ void Painter::blit_filtered(IntPoint position, Gfx::Bitmap const& source, IntRec
ARGB32 const* src = source.scanline(safe_src_rect.top() + first_row) + safe_src_rect.left() + first_column;
size_t const src_skip = source.pitch() / sizeof(ARGB32);
for (int row = first_row; row <= last_row; ++row) {
for (int x = 0; x <= (last_column - first_column); ++x) {
for (int row = first_row; row < last_row; ++row) {
for (int x = 0; x < (last_column - first_column); ++x) {
u8 alpha = color_for_format(src_format, src[x]).alpha();
if (alpha == 0xff) {
auto color = filter(Color::from_argb(src[x]));
@ -986,9 +981,9 @@ void Painter::blit_filtered(IntPoint position, Gfx::Bitmap const& source, IntRec
src += src_skip;
}
} else {
for (int row = first_row; row <= last_row; ++row) {
for (int row = first_row; row < last_row; ++row) {
ARGB32 const* src = source.scanline(safe_src_rect.top() + row / s) + safe_src_rect.left() + first_column / s;
for (int x = 0; x <= (last_column - first_column); ++x) {
for (int x = 0; x < (last_column - first_column); ++x) {
u8 alpha = color_for_format(src_format, src[x / s]).alpha();
if (alpha == 0xff) {
auto color = filter(color_for_format(src_format, src[x / s]));
@ -1033,9 +1028,9 @@ void Painter::draw_tiled_bitmap(IntRect const& a_dst_rect, Gfx::Bitmap const& so
clipped_rect *= scale;
dst_rect *= scale;
int const first_row = (clipped_rect.top() - dst_rect.top());
int const last_row = (clipped_rect.bottom() - dst_rect.top());
int const first_column = (clipped_rect.left() - dst_rect.left());
int const first_row = clipped_rect.top() - dst_rect.top();
int const last_row = clipped_rect.bottom() - dst_rect.top();
int const first_column = clipped_rect.left() - dst_rect.left();
ARGB32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x();
size_t const dst_skip = m_target->pitch() / sizeof(ARGB32);
@ -1043,20 +1038,18 @@ void Painter::draw_tiled_bitmap(IntRect const& a_dst_rect, Gfx::Bitmap const& so
int s = scale / source.scale();
if (s == 1) {
int x_start = first_column + a_dst_rect.left() * scale;
for (int row = first_row; row <= last_row; ++row) {
for (int row = first_row; row < last_row; ++row) {
ARGB32 const* sl = source.scanline((row + a_dst_rect.top() * scale) % source.physical_height());
for (int x = x_start; x < clipped_rect.width() + x_start; ++x) {
for (int x = x_start; x < clipped_rect.width() + x_start; ++x)
dst[x - x_start] = sl[x % source.physical_width()];
}
dst += dst_skip;
}
} else {
int x_start = first_column + a_dst_rect.left() * scale;
for (int row = first_row; row <= last_row; ++row) {
for (int row = first_row; row < last_row; ++row) {
ARGB32 const* sl = source.scanline(((row + a_dst_rect.top() * scale) / s) % source.physical_height());
for (int x = x_start; x < clipped_rect.width() + x_start; ++x) {
for (int x = x_start; x < clipped_rect.width() + x_start; ++x)
dst[x - x_start] = sl[(x / s) % source.physical_width()];
}
dst += dst_skip;
}
}
@ -1114,7 +1107,7 @@ void Painter::blit(IntPoint position, Gfx::Bitmap const& source, IntRect const&
if (source.format() == BitmapFormat::BGRx8888 || source.format() == BitmapFormat::BGRA8888) {
ARGB32 const* src = source.scanline(src_rect.top() + first_row) + src_rect.left() + first_column;
size_t const src_skip = source.pitch() / sizeof(ARGB32);
for (int row = first_row; row <= last_row; ++row) {
for (int row = first_row; row < last_row; ++row) {
memcpy(dst, src, sizeof(ARGB32) * clipped_rect.width());
dst += dst_skip;
src += src_skip;
@ -1125,7 +1118,7 @@ void Painter::blit(IntPoint position, Gfx::Bitmap const& source, IntRect const&
if (source.format() == BitmapFormat::RGBA8888) {
u32 const* src = source.scanline(src_rect.top() + first_row) + src_rect.left() + first_column;
size_t const src_skip = source.pitch() / sizeof(u32);
for (int row = first_row; row <= last_row; ++row) {
for (int row = first_row; row < last_row; ++row) {
for (int i = 0; i < clipped_rect.width(); ++i) {
u32 rgba = src[i];
u32 bgra = (rgba & 0xff00ff00)
@ -1200,9 +1193,9 @@ ALWAYS_INLINE static void do_draw_box_sampled_scaled_bitmap(Gfx::Bitmap& target,
return (intersected_right - intersected_left) * (intersected_bottom - intersected_top);
};
for (int y = clipped_rect.top(); y <= clipped_rect.bottom(); ++y) {
for (int y = clipped_rect.top(); y < clipped_rect.bottom(); ++y) {
auto* scanline = reinterpret_cast<Color*>(target.scanline(y));
for (int x = clipped_rect.left(); x <= clipped_rect.right(); ++x) {
for (int x = clipped_rect.left(); x < clipped_rect.right(); ++x) {
// Project the destination pixel in the source image
FloatRect const source_box = {
src_rect.left() + (x - dst_rect.x()) * source_pixel_width,
@ -1217,8 +1210,8 @@ ALWAYS_INLINE static void do_draw_box_sampled_scaled_bitmap(Gfx::Bitmap& target,
float green_accumulator = 0.f;
float blue_accumulator = 0.f;
float total_area = 0.f;
for (int sy = enclosing_source_box.y(); sy <= enclosing_source_box.bottom(); ++sy) {
for (int sx = enclosing_source_box.x(); sx <= enclosing_source_box.right(); ++sx) {
for (int sy = enclosing_source_box.y(); sy < enclosing_source_box.bottom(); ++sy) {
for (int sx = enclosing_source_box.x(); sx < enclosing_source_box.right(); ++sx) {
float area = float_rect_intersection_area_fixme(source_box, pixel_box.translated(sx, sy));
auto pixel = get_pixel(source, sx, sy);
@ -1281,11 +1274,11 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, IntRect con
i64 src_left = src_rect.left() * shift;
i64 src_top = src_rect.top() * shift;
for (int y = clipped_rect.top(); y <= clipped_rect.bottom(); ++y) {
for (int y = clipped_rect.top(); y < clipped_rect.bottom(); ++y) {
auto* scanline = reinterpret_cast<Color*>(target.scanline(y));
auto desired_y = (y - dst_rect.y()) * vscale + src_top;
for (int x = clipped_rect.left(); x <= clipped_rect.right(); ++x) {
for (int x = clipped_rect.left(); x < clipped_rect.right(); ++x) {
auto desired_x = (x - dst_rect.x()) * hscale + src_left;
Color src_pixel;
@ -1293,10 +1286,10 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, IntRect con
auto shifted_x = desired_x + bilinear_offset_x;
auto shifted_y = desired_y + bilinear_offset_y;
auto scaled_x0 = clamp(shifted_x >> 32, clipped_src_rect.left(), clipped_src_rect.right());
auto scaled_x1 = clamp((shifted_x >> 32) + 1, clipped_src_rect.left(), clipped_src_rect.right());
auto scaled_y0 = clamp(shifted_y >> 32, clipped_src_rect.top(), clipped_src_rect.bottom());
auto scaled_y1 = clamp((shifted_y >> 32) + 1, clipped_src_rect.top(), clipped_src_rect.bottom());
auto scaled_x0 = clamp(shifted_x >> 32, clipped_src_rect.left(), clipped_src_rect.right() - 1);
auto scaled_x1 = clamp((shifted_x >> 32) + 1, clipped_src_rect.left(), clipped_src_rect.right() - 1);
auto scaled_y0 = clamp(shifted_y >> 32, clipped_src_rect.top(), clipped_src_rect.bottom() - 1);
auto scaled_y1 = clamp((shifted_y >> 32) + 1, clipped_src_rect.top(), clipped_src_rect.bottom() - 1);
float x_ratio = (shifted_x & fractional_mask) / static_cast<float>(shift);
float y_ratio = (shifted_y & fractional_mask) / static_cast<float>(shift);
@ -1311,10 +1304,10 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, IntRect con
src_pixel = top.mixed_with(bottom, y_ratio);
} else if constexpr (scaling_mode == Painter::ScalingMode::SmoothPixels) {
auto scaled_x1 = clamp(desired_x >> 32, clipped_src_rect.left(), clipped_src_rect.right());
auto scaled_x0 = clamp(scaled_x1 - 1, clipped_src_rect.left(), clipped_src_rect.right());
auto scaled_y1 = clamp(desired_y >> 32, clipped_src_rect.top(), clipped_src_rect.bottom());
auto scaled_y0 = clamp(scaled_y1 - 1, clipped_src_rect.top(), clipped_src_rect.bottom());
auto scaled_x1 = clamp(desired_x >> 32, clipped_src_rect.left(), clipped_src_rect.right() - 1);
auto scaled_x0 = clamp(scaled_x1 - 1, clipped_src_rect.left(), clipped_src_rect.right() - 1);
auto scaled_y1 = clamp(desired_y >> 32, clipped_src_rect.top(), clipped_src_rect.bottom() - 1);
auto scaled_y0 = clamp(scaled_y1 - 1, clipped_src_rect.top(), clipped_src_rect.bottom() - 1);
float x_ratio = (desired_x & fractional_mask) / (float)shift;
float y_ratio = (desired_y & fractional_mask) / (float)shift;
@ -1332,8 +1325,8 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, IntRect con
src_pixel = top.mixed_with(bottom, scaled_y_ratio);
} else {
auto scaled_x = clamp(desired_x >> 32, clipped_src_rect.left(), clipped_src_rect.right());
auto scaled_y = clamp(desired_y >> 32, clipped_src_rect.top(), clipped_src_rect.bottom());
auto scaled_x = clamp(desired_x >> 32, clipped_src_rect.left(), clipped_src_rect.right() - 1);
auto scaled_y = clamp(desired_y >> 32, clipped_src_rect.top(), clipped_src_rect.bottom() - 1);
src_pixel = get_pixel(source, scaled_x, scaled_y);
}
@ -1556,7 +1549,7 @@ void draw_text_line(FloatRect const& a_rect, Utf8View const& text, Font const& f
case TextAlignment::TopRight:
case TextAlignment::CenterRight:
case TextAlignment::BottomRight:
rect.set_x(rect.right() - font.width(text));
rect.set_x(rect.right() - 1 - font.width(text));
break;
case TextAlignment::TopCenter:
case TextAlignment::BottomCenter:
@ -2043,16 +2036,16 @@ void Painter::draw_line(IntPoint a_p1, IntPoint a_p2, Color color, int thickness
// Special case: vertical line.
if (point1.x() == point2.x()) {
int const x = point1.x();
if (x < clip_rect.left() || x > clip_rect.right())
if (x < clip_rect.left() || x >= clip_rect.right())
return;
if (point1.y() > point2.y())
swap(point1, point2);
if (point1.y() > clip_rect.bottom())
if (point1.y() >= clip_rect.bottom())
return;
if (point2.y() < clip_rect.top())
return;
int min_y = max(point1.y(), clip_rect.top());
int max_y = min(point2.y(), clip_rect.bottom());
int max_y = min(point2.y(), clip_rect.bottom() - 1);
if (style == LineStyle::Dotted) {
for (int y = min_y; y <= max_y; y += thickness * 2)
draw_physical_pixel({ x, y }, color, thickness);
@ -2078,16 +2071,16 @@ void Painter::draw_line(IntPoint a_p1, IntPoint a_p2, Color color, int thickness
// Special case: horizontal line.
if (point1.y() == point2.y()) {
int const y = point1.y();
if (y < clip_rect.top() || y > clip_rect.bottom())
if (y < clip_rect.top() || y >= clip_rect.bottom())
return;
if (point1.x() > point2.x())
swap(point1, point2);
if (point1.x() > clip_rect.right())
if (point1.x() >= clip_rect.right())
return;
if (point2.x() < clip_rect.left())
return;
int min_x = max(point1.x(), clip_rect.left());
int max_x = min(point2.x(), clip_rect.right());
int max_x = min(point2.x(), clip_rect.right() - 1);
if (style == LineStyle::Dotted) {
for (int x = min_x; x <= max_x; x += thickness * 2)
draw_physical_pixel({ x, y }, color, thickness);
@ -2490,19 +2483,17 @@ void Painter::blit_tiled(IntRect const& dst_rect, Gfx::Bitmap const& bitmap, Int
{
auto tile_width = rect.width();
auto tile_height = rect.height();
auto dst_right = dst_rect.right();
auto dst_bottom = dst_rect.bottom();
auto dst_right = dst_rect.right() - 1;
auto dst_bottom = dst_rect.bottom() - 1;
for (int tile_y = dst_rect.top(); tile_y < dst_bottom; tile_y += tile_height) {
for (int tile_x = dst_rect.left(); tile_x < dst_right; tile_x += tile_width) {
IntRect tile_src_rect = rect;
auto tile_x_overflow = tile_x + tile_width - dst_right;
if (tile_x_overflow > 0) {
if (tile_x_overflow > 0)
tile_src_rect.set_width(tile_width - tile_x_overflow);
}
auto tile_y_overflow = tile_y + tile_height - dst_bottom;
if (tile_y_overflow > 0) {
if (tile_y_overflow > 0)
tile_src_rect.set_height(tile_height - tile_y_overflow);
}
blit(IntPoint(tile_x, tile_y), bitmap, tile_src_rect);
}
}
@ -2545,7 +2536,7 @@ void Gfx::Painter::draw_ui_text(Gfx::IntRect const& rect, StringView text, Gfx::
float width = 0;
for (auto it = utf8_view.begin(); it != utf8_view.end(); ++it) {
if (utf8_view.byte_offset_of(it) >= underline_offset.value()) {
int y = text_rect.bottom() + 1;
int y = text_rect.bottom();
int x1 = text_rect.left() + width;
int x2 = x1 + font.glyph_or_emoji_width(it);
draw_line({ x1, y }, { x2, y }, color);

View file

@ -15,8 +15,8 @@ namespace Gfx {
template<typename T>
void Point<T>::constrain(Rect<T> const& rect)
{
m_x = AK::clamp<T>(x(), rect.left(), rect.right());
m_y = AK::clamp<T>(y(), rect.top(), rect.bottom());
m_x = AK::clamp<T>(x(), rect.left(), rect.right() - 1);
m_y = AK::clamp<T>(y(), rect.top(), rect.bottom() - 1);
}
template<typename T>

View file

@ -1,7 +1,7 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
* Copyright (c) 2022-2023, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -9,6 +9,7 @@
#pragma once
#include <AK/Format.h>
#include <AK/Vector.h>
#include <LibGfx/AffineTransform.h>
#include <LibGfx/Line.h>
#include <LibGfx/Orientation.h>
@ -19,12 +20,6 @@
namespace Gfx {
template<typename T>
T abst(T value)
{
return value < 0 ? -value : value;
}
template<typename T>
class Rect {
public:
@ -291,17 +286,17 @@ public:
[[nodiscard]] bool contains_vertically(T y) const
{
return y >= top() && y <= bottom();
return y >= top() && y < bottom();
}
[[nodiscard]] bool contains_horizontally(T x) const
{
return x >= left() && x <= right();
return x >= left() && x < right();
}
[[nodiscard]] bool contains(T x, T y) const
{
return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom();
return contains_horizontally(x) && contains_vertically(y);
}
[[nodiscard]] ALWAYS_INLINE bool contains(Point<T> const& point) const
@ -354,29 +349,14 @@ public:
}
[[nodiscard]] ALWAYS_INLINE T left() const { return x(); }
[[nodiscard]] ALWAYS_INLINE T right() const { return x() + width() - 1; }
[[nodiscard]] ALWAYS_INLINE T right() const { return x() + width(); }
[[nodiscard]] ALWAYS_INLINE T top() const { return y(); }
[[nodiscard]] ALWAYS_INLINE T bottom() const { return y() + height() - 1; }
[[nodiscard]] ALWAYS_INLINE T bottom() const { return y() + height(); }
ALWAYS_INLINE void set_left(T left)
{
set_x(left);
}
ALWAYS_INLINE void set_top(T top)
{
set_y(top);
}
ALWAYS_INLINE void set_right(T right)
{
set_width(right - x() + 1);
}
ALWAYS_INLINE void set_bottom(T bottom)
{
set_height(bottom - y() + 1);
}
ALWAYS_INLINE void set_left(T left) { set_x(left); }
ALWAYS_INLINE void set_top(T top) { set_y(top); }
ALWAYS_INLINE void set_right(T right) { set_width(right - x()); }
ALWAYS_INLINE void set_bottom(T bottom) { set_height(bottom - y()); }
void set_right_without_resize(T new_right)
{
@ -392,20 +372,20 @@ public:
[[nodiscard]] bool intersects_vertically(Rect<T> const& other) const
{
return top() <= other.bottom() && other.top() <= bottom();
return top() < other.bottom() && other.top() < bottom();
}
[[nodiscard]] bool intersects_horizontally(Rect<T> const& other) const
{
return left() <= other.right() && other.left() <= right();
return left() < other.right() && other.left() < right();
}
[[nodiscard]] bool intersects(Rect<T> const& other) const
{
return left() <= other.right()
&& other.left() <= right()
&& top() <= other.bottom()
&& other.top() <= bottom();
return left() < other.right()
&& other.left() < right()
&& top() < other.bottom()
&& other.top() < bottom();
}
template<typename Container>
@ -445,25 +425,25 @@ public:
x(),
y(),
width(),
hammer.y() - y()
hammer.y() - y(),
};
Rect<T> bottom_shard {
x(),
hammer.y() + hammer.height(),
hammer.bottom(),
width(),
(y() + height()) - (hammer.y() + hammer.height())
bottom() - hammer.bottom(),
};
Rect<T> left_shard {
x(),
max(hammer.y(), y()),
hammer.x() - x(),
min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y())
min(hammer.bottom(), bottom()) - max(hammer.y(), y()),
};
Rect<T> right_shard {
hammer.x() + hammer.width(),
hammer.right(),
max(hammer.y(), y()),
right() - hammer.right(),
min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y())
min(hammer.bottom(), bottom()) - max(hammer.y(), y()),
};
if (!top_shard.is_empty())
pieces.unchecked_append(top_shard);
@ -505,10 +485,10 @@ public:
return;
}
m_location.set_x(l);
m_location.set_y(t);
m_size.set_width((r - l) + 1);
m_size.set_height((b - t) + 1);
set_x(l);
set_y(t);
set_right(r);
set_bottom(b);
}
[[nodiscard]] static Rect<T> centered_on(Point<T> const& center, Size<T> const& size)
@ -518,7 +498,7 @@ public:
[[nodiscard]] static Rect<T> from_two_points(Point<T> const& a, Point<T> const& b)
{
return { min(a.x(), b.x()), min(a.y(), b.y()), abst(a.x() - b.x()), abst(a.y() - b.y()) };
return { min(a.x(), b.x()), min(a.y(), b.y()), AK::abs(a.x() - b.x()), AK::abs(a.y() - b.y()) };
}
[[nodiscard]] static Rect<T> intersection(Rect<T> const& a, Rect<T> const& b)
@ -541,18 +521,18 @@ public:
if (auto point = line.intersected({ top_left(), top_right() }); point.has_value())
points.append({ point.value().x(), y() });
if (auto point = line.intersected({ bottom_left(), bottom_right() }); point.has_value()) {
points.append({ point.value().x(), bottom() });
points.append({ point.value().x(), bottom() - 1 });
if (points.size() == 2)
return points;
}
if (height() > 2) {
if (auto point = line.intersected({ { x(), y() + 1 }, { x(), bottom() - 1 } }); point.has_value()) {
if (auto point = line.intersected({ { x(), y() + 1 }, { x(), bottom() - 2 } }); point.has_value()) {
points.append({ x(), point.value().y() });
if (points.size() == 2)
return points;
}
if (auto point = line.intersected({ { right(), y() + 1 }, { right(), bottom() - 1 } }); point.has_value())
points.append({ right(), point.value().y() });
if (auto point = line.intersected({ { right() - 1, y() + 1 }, { right() - 1, bottom() - 2 } }); point.has_value())
points.append({ right() - 1, point.value().y() });
}
return points;
}
@ -560,11 +540,11 @@ public:
template<typename U = T>
[[nodiscard]] Gfx::Rect<U> interpolated_to(Gfx::Rect<T> const& to, float factor) const
{
VERIFY(factor >= 0.0f);
VERIFY(factor <= 1.0f);
if (factor == 0.0f)
VERIFY(factor >= 0.f);
VERIFY(factor <= 1.f);
if (factor == 0.f)
return *this;
if (factor == 1.0f)
if (factor == 1.f)
return to;
if (this == &to)
return *this;
@ -572,7 +552,7 @@ public:
auto interpolated_top = round_to<U>(mix<float>(y(), to.y(), factor));
auto interpolated_right = round_to<U>(mix<float>(right(), to.right(), factor));
auto interpolated_bottom = round_to<U>(mix<float>(bottom(), to.bottom(), factor));
return { interpolated_left, interpolated_top, interpolated_right - interpolated_left + 1, interpolated_bottom - interpolated_top + 1 };
return { interpolated_left, interpolated_top, interpolated_right - interpolated_left, interpolated_bottom - interpolated_top };
}
[[nodiscard]] float center_point_distance_to(Rect<T> const& other) const
@ -596,7 +576,7 @@ public:
{
auto points = closest_outside_center_points(other);
if (points.is_empty())
return 0.0;
return 0.f;
return Line { points[0], points[0] }.length();
}
@ -679,8 +659,8 @@ public:
check_distance({ top_left(), top_right() });
check_distance({ bottom_left(), bottom_right() });
if (height() > 2) {
check_distance({ { x(), y() + 1 }, { x(), bottom() - 1 } });
check_distance({ { right(), y() + 1 }, { right(), bottom() - 1 } });
check_distance({ { x(), y() + 1 }, { x(), bottom() - 2 } });
check_distance({ { right() - 1, y() + 1 }, { right() - 1, bottom() - 2 } });
}
VERIFY(closest_point.has_value());
VERIFY(side(closest_point.value()) != Side::None);
@ -699,23 +679,23 @@ public:
if (part.x() < other_rect.x()) {
if (part.y() < other_rect.y())
m_top_left = true;
if ((part.y() >= other_rect.y() && part.y() < other_rect.bottom()) || (part.y() <= other_rect.bottom() && part.bottom() > other_rect.y()))
if ((part.y() >= other_rect.y() && part.y() < other_rect.bottom() - 1) || (part.y() < other_rect.bottom() && part.bottom() - 1 > other_rect.y()))
m_left = true;
if (part.y() >= other_rect.bottom() || part.bottom() > other_rect.y())
if (part.y() >= other_rect.bottom() - 1 || part.bottom() - 1 > other_rect.y())
m_bottom_left = true;
}
if (part.x() >= other_rect.x() || part.right() > other_rect.x()) {
if (part.x() >= other_rect.x() || part.right() - 1 > other_rect.x()) {
if (part.y() < other_rect.y())
m_top = true;
if (part.y() >= other_rect.bottom() || part.bottom() > other_rect.bottom())
if (part.y() >= other_rect.bottom() - 1 || part.bottom() > other_rect.bottom())
m_bottom = true;
}
if (part.x() >= other_rect.right() || part.right() > other_rect.right()) {
if (part.x() >= other_rect.right() - 1 || part.right() > other_rect.right()) {
if (part.y() < other_rect.y())
m_top_right = true;
if ((part.y() >= other_rect.y() && part.y() < other_rect.bottom()) || (part.y() <= other_rect.bottom() && part.bottom() > other_rect.y()))
if ((part.y() >= other_rect.y() && part.y() < other_rect.bottom() - 1) || (part.y() < other_rect.bottom() && part.bottom() - 1 > other_rect.y()))
m_right = true;
if (part.y() >= other_rect.bottom() || part.bottom() > other_rect.y())
if (part.y() >= other_rect.bottom() - 1 || part.bottom() - 1 > other_rect.y())
m_bottom_right = true;
}
}
@ -763,9 +743,9 @@ public:
{
if (is_empty())
return Side::None;
if (point.y() == y() || point.y() == bottom())
return (point.x() >= x() && point.x() <= right()) ? (point.y() == y() ? Side::Top : Side::Bottom) : Side::None;
if (point.x() == x() || point.x() == right())
if (point.y() == y() || point.y() == bottom() - 1)
return (point.x() >= x() && point.x() < right()) ? (point.y() == y() ? Side::Top : Side::Bottom) : Side::None;
if (point.x() == x() || point.x() == right() - 1)
return (point.y() > y() && point.y() < bottom()) ? (point.x() == x() ? Side::Left : Side::Right) : Side::None;
return Side::None;
}
@ -778,7 +758,7 @@ public:
case Side::Left:
// Return the area in other that is to the left of this rect
if (other.x() < x()) {
if (other.right() >= x())
if (other.right() > x())
return { other.location(), { x() - other.x(), other.height() } };
else
return other;
@ -787,7 +767,7 @@ public:
case Side::Top:
// Return the area in other that is above this rect
if (other.y() < y()) {
if (other.bottom() >= y())
if (other.bottom() > y())
return { other.location(), { other.width(), y() - other.y() } };
else
return other;
@ -795,18 +775,18 @@ public:
break;
case Side::Right:
// Return the area in other that is to the right of this rect
if (other.right() >= x()) {
if (other.x() <= right())
return { { right() + 1, other.y() }, { other.width() - (right() - other.x()), other.height() } };
if (other.right() > x()) {
if (other.x() < right())
return { { right(), other.y() }, { other.width() - (right() - 1 - other.x()), other.height() } };
else
return other;
}
break;
case Side::Bottom:
// Return the area in other that is below this rect
if (other.bottom() >= y()) {
if (other.y() <= bottom())
return { { other.x(), bottom() + 1 }, { other.width(), other.height() - (bottom() - other.y()) } };
if (other.bottom() > y()) {
if (other.y() < bottom())
return { { other.x(), bottom() }, { other.width(), other.height() - (bottom() - 1 - other.y()) } };
else
return other;
}
@ -878,10 +858,10 @@ public:
return false;
if (intersects(other))
return false;
if (other.x() + other.width() == x() || other.x() == x() + width())
return max(top(), other.top()) <= min(bottom(), other.bottom());
if (other.y() + other.height() == y() || other.y() == y() + height())
return max(left(), other.left()) <= min(right(), other.right());
if (other.right() == x() || other.x() == right())
return max(top(), other.top()) < min(bottom(), other.bottom());
if (other.bottom() == y() || other.y() == bottom())
return max(left(), other.left()) < min(right(), other.right());
return false;
}
@ -923,7 +903,7 @@ public:
set_location(other.location());
return;
case TextAlignment::TopRight:
set_x(other.x() + other.width() - width());
set_x(other.right() - width());
set_y(other.y());
return;
case TextAlignment::CenterLeft:
@ -931,20 +911,20 @@ public:
center_vertically_within(other);
return;
case TextAlignment::CenterRight:
set_x(other.x() + other.width() - width());
set_x(other.right() - width());
center_vertically_within(other);
return;
case TextAlignment::BottomCenter:
center_horizontally_within(other);
set_y(other.y() + other.height() - height());
set_y(other.bottom() - height());
return;
case TextAlignment::BottomLeft:
set_x(other.x());
set_y(other.y() + other.height() - height());
set_y(other.bottom() - height());
return;
case TextAlignment::BottomRight:
set_x(other.x() + other.width() - width());
set_y(other.y() + other.height() - height());
set_x(other.right() - width());
set_y(other.bottom() - height());
return;
}
}
@ -1036,8 +1016,8 @@ using FloatRect = Rect<float>;
{
int x1 = floorf(float_rect.x());
int y1 = floorf(float_rect.y());
int x2 = ceilf(float_rect.x() + float_rect.width());
int y2 = ceilf(float_rect.y() + float_rect.height());
int x2 = ceilf(float_rect.right());
int y2 = ceilf(float_rect.bottom());
return Gfx::IntRect::from_two_points({ x1, y1 }, { x2, y2 });
}

View file

@ -29,7 +29,7 @@ public:
return adopt_ref(*new Typed2DBuffer(buffer));
}
void fill(T value, Gfx::IntRect const& rect) { m_buffer->fill(value, rect.left(), rect.right(), rect.top(), rect.bottom(), 0, 0); }
void fill(T value, Gfx::IntRect const& rect) { m_buffer->fill(value, rect.left(), rect.right(), rect.top(), rect.bottom(), 0, 1); }
ALWAYS_INLINE T* scanline(int y) { return m_buffer->buffer_pointer(0, y, 0); }
ALWAYS_INLINE T const* scanline(int y) const { return m_buffer->buffer_pointer(0, y, 0); }
@ -40,7 +40,7 @@ public:
int source_y = 0;
// NOTE: we are flipping the Y-coordinate here, which is OpenGL-specific: (0, 0) is considered the lower-left corner of the window
for (int y = target.bottom(); y >= target.top(); --y) {
for (int y = target.bottom() - 1; y >= target.top(); --y) {
auto const* buffer_scanline = scanline(source_y++);
auto* bitmap_scanline = bitmap.scanline(y);
memcpy(bitmap_scanline + target.left(), buffer_scanline, sizeof(u32) * target.width());

View file

@ -41,10 +41,10 @@ public:
void fill(T value, int x1, int x2, int y1, int y2, int z1, int z2)
{
for (auto z = z1; z <= z2; ++z) {
for (auto y = y1; y <= y2; ++y) {
for (auto z = z1; z < z2; ++z) {
for (auto y = y1; y < y2; ++y) {
auto* xline = buffer_pointer(0, y, z);
for (auto x = x1; x <= x2; ++x)
for (auto x = x1; x < x2; ++x)
xline[x] = value;
}
}

View file

@ -231,9 +231,9 @@ ALWAYS_INLINE void Device::rasterize(Gfx::IntRect& render_bounds, CB1 set_covera
// Quad bounds
auto const render_bounds_left = render_bounds.left();
auto const render_bounds_right = render_bounds.right();
auto const render_bounds_right = render_bounds.right() - 1;
auto const render_bounds_top = render_bounds.top();
auto const render_bounds_bottom = render_bounds.bottom();
auto const render_bounds_bottom = render_bounds.bottom() - 1;
auto const qx0 = render_bounds_left & ~1;
auto const qx1 = render_bounds_right & ~1;
auto const qy0 = render_bounds_top & ~1;
@ -678,9 +678,9 @@ void Device::rasterize_triangle(Triangle& triangle)
// Calculate render bounds based on the triangle's vertices
Gfx::IntRect render_bounds;
render_bounds.set_left(min(min(v0.x(), v1.x()), v2.x()) / subpixel_factor);
render_bounds.set_right(max(max(v0.x(), v1.x()), v2.x()) / subpixel_factor);
render_bounds.set_right(max(max(v0.x(), v1.x()), v2.x()) / subpixel_factor + 1);
render_bounds.set_top(min(min(v0.y(), v1.y()), v2.y()) / subpixel_factor);
render_bounds.set_bottom(max(max(v0.y(), v1.y()), v2.y()) / subpixel_factor);
render_bounds.set_bottom(max(max(v0.y(), v1.y()), v2.y()) / subpixel_factor + 1);
// Calculate depth of fragment for fog;
// OpenGL 1.5 chapter 3.10: "An implementation may choose to approximate the

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.

View file

@ -60,8 +60,8 @@ Gfx::FloatSize RadialGradientStyleValue::resolve_size(Layout::Node const& node,
auto const distance_from = [&](float v, float a, float b, auto distance_function) {
return distance_function(fabs(a - v), fabs(b - v));
};
auto x_dist = distance_from(center.x(), size.left(), size.right(), distance_function);
auto y_dist = distance_from(center.y(), size.top(), size.bottom(), distance_function);
auto x_dist = distance_from(center.x(), size.left(), size.right() - 1, distance_function);
auto y_dist = distance_from(center.y(), size.top(), size.bottom() - 1, distance_function);
if (m_properties.ending_shape == EndingShape::Circle) {
auto dist = distance_function(x_dist, y_dist);
return Gfx::FloatSize { dist, dist };
@ -80,20 +80,20 @@ Gfx::FloatSize RadialGradientStyleValue::resolve_size(Layout::Node const& node,
auto const corner_distance = [&](auto distance_compare, Gfx::FloatPoint& corner) {
auto top_left_distance = size.top_left().distance_from(center);
auto top_right_distance = size.top_right().distance_from(center);
auto bottom_right_distance = size.bottom_right().distance_from(center);
auto bottom_left_distance = size.bottom_left().distance_from(center);
auto top_right_distance = size.top_right().moved_left(1).distance_from(center);
auto bottom_right_distance = size.bottom_right().translated(-1).distance_from(center);
auto bottom_left_distance = size.bottom_left().moved_up(1).distance_from(center);
auto distance = top_left_distance;
if (distance_compare(top_right_distance, distance)) {
corner = size.top_right();
corner = size.top_right().translated(-1, 0);
distance = top_right_distance;
}
if (distance_compare(bottom_right_distance, distance)) {
corner = size.top_right();
corner = size.top_right().translated(-1, 0);
distance = bottom_right_distance;
}
if (distance_compare(bottom_left_distance, distance)) {
corner = size.top_right();
corner = size.top_right().translated(-1, 0);
distance = bottom_left_distance;
}
return distance;

View file

@ -706,7 +706,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_vertically
CSSPixels clearance_y_in_root = 0;
for (auto const& floating_box : float_side.current_boxes) {
auto floating_box_rect_in_root = margin_box_rect_in_ancestor_coordinate_space(floating_box.box, root(), m_state);
clearance_y_in_root = max(clearance_y_in_root, floating_box_rect_in_root.bottom() + 1);
clearance_y_in_root = max(clearance_y_in_root, floating_box_rect_in_root.bottom());
}
// Then, convert the clearance Y to a coordinate relative to the containing block of `child_box`.
@ -762,8 +762,8 @@ static void measure_scrollable_overflow(LayoutState const& state, Box const& box
auto child_rect = absolute_content_rect(box, state);
child_rect.inflate(child_state.border_box_top(), child_state.border_box_right(), child_state.border_box_bottom(), child_state.border_box_left());
bottom_edge = max(bottom_edge, child_rect.bottom());
right_edge = max(right_edge, child_rect.right());
bottom_edge = max(bottom_edge, child_rect.bottom() - 1);
right_edge = max(right_edge, child_rect.right() - 1);
if (box.computed_values().overflow_x() == CSS::Overflow::Hidden && box.computed_values().overflow_y() == CSS::Overflow::Hidden)
return;
@ -874,7 +874,9 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
// We're looking for the innermost preceding float that intersects vertically with `box`.
for (auto& preceding_float : side_data.current_boxes.in_reverse()) {
auto const preceding_float_rect = margin_box_rect_in_ancestor_coordinate_space(preceding_float.box, root(), m_state);
if (!preceding_float_rect.contains_vertically(y_in_root))
// FIXME: the line below is for compatibility with a fixed `Gfx::FloatRect` bug where `.bottom()` was subtracted by one;
// replace with !rect.contains_vertically() and update the test cases accordingly.
if (y_in_root < preceding_float_rect.top() || y_in_root > preceding_float_rect.bottom() - 1.f)
continue;
// We found a preceding float that intersects vertically with the current float.
// Now we need to find out if there's enough inline-axis space to stack them next to each other.
@ -1007,7 +1009,9 @@ BlockFormattingContext::SpaceUsedByFloats BlockFormattingContext::space_used_by_
auto const& floating_box_state = m_state.get(floating_box.box);
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box.box, root(), m_state);
if (rect.contains_vertically(y.value())) {
// FIXME: the line below is for compatibility with a fixed `Gfx::FloatRect` bug where `.bottom()` was subtracted by one;
// replace with rect.contains_vertically() and update the test cases accordingly.
if (y.value() >= rect.top() && y.value() <= rect.bottom() - 1.f) {
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
for (auto const* containing_block = floating_box.box->containing_block(); containing_block && containing_block != &root(); containing_block = containing_block->containing_block()) {
auto const& containing_block_state = m_state.get(*containing_block);
@ -1026,7 +1030,9 @@ BlockFormattingContext::SpaceUsedByFloats BlockFormattingContext::space_used_by_
auto const& floating_box_state = m_state.get(floating_box.box);
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box.box, root(), m_state);
if (rect.contains_vertically(y.value())) {
// FIXME: the line below is for compatibility with a fixed `Gfx::FloatRect` bug where `.bottom()` was subtracted by one;
// replace with rect.contains_vertically() and update the test cases accordingly.
if (y.value() >= rect.top() && y.value() <= rect.bottom() - 1.f) {
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
for (auto const* containing_block = floating_box.box->containing_block(); containing_block && containing_block != &root(); containing_block = containing_block->containing_block()) {
auto const& containing_block_state = m_state.get(*containing_block);

View file

@ -358,7 +358,7 @@ CSSPixels FormattingContext::compute_auto_height_for_block_formatting_context_ro
// NOTE: Floating box coordinates are relative to their own containing block,
// which may or may not be the BFC root.
auto margin_box = margin_box_rect_in_ancestor_coordinate_space(*floating_box, root, m_state);
CSSPixels floating_box_bottom_margin_edge = margin_box.bottom() + 1;
CSSPixels floating_box_bottom_margin_edge = margin_box.bottom();
if (!bottom.has_value() || floating_box_bottom_margin_edge > bottom.value())
bottom = floating_box_bottom_margin_edge;
}

View file

@ -329,7 +329,6 @@ bool InlineFormattingContext::any_floats_intrude_at_y(CSSPixels y) const
bool InlineFormattingContext::can_fit_new_line_at_y(CSSPixels y) const
{
auto top_intrusions = parent().intrusion_by_floats_into_box(containing_block(), y);
auto bottom_intrusions = parent().intrusion_by_floats_into_box(containing_block(), y + containing_block().line_height() - 1);

View file

@ -309,11 +309,11 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
image.resolve_for_size(layout_node, image_rect.size());
while (image_y <= css_clip_rect.bottom()) {
while (image_y < css_clip_rect.bottom()) {
image_rect.set_y(image_y);
auto image_x = initial_image_x;
while (image_x <= css_clip_rect.right()) {
while (image_x < css_clip_rect.right()) {
image_rect.set_x(image_x);
auto image_device_rect = context.rounded_device_rect(image_rect);
if (image_device_rect != last_image_device_rect && image_device_rect.intersects(context.device_viewport_rect()))

View file

@ -85,13 +85,13 @@ void paint_border(PaintContext& context, BorderEdge edge, DevicePixelRect const&
auto points_for_edge = [](BorderEdge edge, DevicePixelRect const& rect) -> Points {
switch (edge) {
case BorderEdge::Top:
return { rect.top_left(), rect.top_right() };
return { rect.top_left(), rect.top_right().moved_left(1) };
case BorderEdge::Right:
return { rect.top_right(), rect.bottom_right() };
return { rect.top_right().moved_left(1), rect.bottom_right().translated(-1) };
case BorderEdge::Bottom:
return { rect.bottom_left(), rect.bottom_right() };
return { rect.bottom_left().moved_up(1), rect.bottom_right().translated(-1) };
default: // Edge::Left
return { rect.top_left(), rect.bottom_left() };
return { rect.top_left(), rect.bottom_left().moved_up(1) };
}
};
@ -365,13 +365,13 @@ void paint_all_borders(PaintContext& context, CSSPixelRect const& bordered_rect,
blit_corner(border_rect.top_left().to_type<int>(), top_left.as_rect(), pick_corner_color(borders_data.top, borders_data.left));
if (top_right)
blit_corner(border_rect.top_right().to_type<int>().translated(-top_right.horizontal_radius + 1, 0), top_right.as_rect().translated(corner_mask_rect.width().value() - top_right.horizontal_radius, 0), pick_corner_color(borders_data.top, borders_data.right));
blit_corner(border_rect.top_right().to_type<int>().translated(-top_right.horizontal_radius, 0), top_right.as_rect().translated(corner_mask_rect.width().value() - top_right.horizontal_radius, 0), pick_corner_color(borders_data.top, borders_data.right));
if (bottom_right)
blit_corner(border_rect.bottom_right().to_type<int>().translated(-bottom_right.horizontal_radius + 1, -bottom_right.vertical_radius + 1), bottom_right.as_rect().translated(corner_mask_rect.width().value() - bottom_right.horizontal_radius, corner_mask_rect.height().value() - bottom_right.vertical_radius), pick_corner_color(borders_data.bottom, borders_data.right));
blit_corner(border_rect.bottom_right().to_type<int>().translated(-bottom_right.horizontal_radius, -bottom_right.vertical_radius), bottom_right.as_rect().translated(corner_mask_rect.width().value() - bottom_right.horizontal_radius, corner_mask_rect.height().value() - bottom_right.vertical_radius), pick_corner_color(borders_data.bottom, borders_data.right));
if (bottom_left)
blit_corner(border_rect.bottom_left().to_type<int>().translated(0, -bottom_left.vertical_radius + 1), bottom_left.as_rect().translated(0, corner_mask_rect.height().value() - bottom_left.vertical_radius), pick_corner_color(borders_data.bottom, borders_data.left));
blit_corner(border_rect.bottom_left().to_type<int>().translated(0, -bottom_left.vertical_radius), bottom_left.as_rect().translated(0, corner_mask_rect.height().value() - bottom_left.vertical_radius), pick_corner_color(borders_data.bottom, borders_data.left));
}
}

View file

@ -43,7 +43,7 @@ ErrorOr<BorderRadiusCornerClipper> BorderRadiusCornerClipper::create(PaintContex
.top_right = top_right,
.bottom_right = bottom_right,
.bottom_left = bottom_left },
.page_locations = { .top_left = border_rect.top_left(), .top_right = border_rect.top_right().translated(-top_right.horizontal_radius + 1, 0), .bottom_right = border_rect.bottom_right().translated(-bottom_right.horizontal_radius + 1, -bottom_right.vertical_radius + 1), .bottom_left = border_rect.bottom_left().translated(0, -bottom_left.vertical_radius + 1) },
.page_locations = { .top_left = border_rect.top_left(), .top_right = border_rect.top_right().translated(-top_right.horizontal_radius, 0), .bottom_right = border_rect.bottom_right().translated(-bottom_right.horizontal_radius, -bottom_right.vertical_radius), .bottom_left = border_rect.bottom_left().translated(0, -bottom_left.vertical_radius) },
.bitmap_locations = { .top_left = { 0, 0 }, .top_right = { corners_bitmap_size.width() - top_right.horizontal_radius, 0 }, .bottom_right = { corners_bitmap_size.width() - bottom_right.horizontal_radius, corners_bitmap_size.height() - bottom_right.vertical_radius }, .bottom_left = { 0, corners_bitmap_size.height() - bottom_left.vertical_radius } },
.corner_bitmap_size = corners_bitmap_size
};

View file

@ -450,16 +450,16 @@ static void paint_text_decoration(PaintContext& context, Gfx::Painter& painter,
return;
case CSS::TextDecorationLine::Underline:
line_start_point = context.rounded_device_point(fragment_box.top_left().translated(0, baseline + 2));
line_end_point = context.rounded_device_point(fragment_box.top_right().translated(0, baseline + 2));
line_end_point = context.rounded_device_point(fragment_box.top_right().translated(-1, baseline + 2));
break;
case CSS::TextDecorationLine::Overline:
line_start_point = context.rounded_device_point(fragment_box.top_left().translated(0, baseline - glyph_height));
line_end_point = context.rounded_device_point(fragment_box.top_right().translated(0, baseline - glyph_height));
line_end_point = context.rounded_device_point(fragment_box.top_right().translated(-1, baseline - glyph_height));
break;
case CSS::TextDecorationLine::LineThrough: {
auto x_height = font.x_height();
line_start_point = context.rounded_device_point(fragment_box.top_left().translated(0, baseline - x_height * 0.5f));
line_end_point = context.rounded_device_point(fragment_box.top_right().translated(0, baseline - x_height * 0.5f));
line_end_point = context.rounded_device_point(fragment_box.top_right().translated(-1, baseline - x_height * 0.5f));
break;
}
case CSS::TextDecorationLine::Blink:
@ -603,7 +603,7 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const
context.painter().draw_rect(context.enclosing_device_rect(fragment_absolute_rect).to_type<int>(), Color::Green);
context.painter().draw_line(
context.rounded_device_point(fragment_absolute_rect.top_left().translated(0, fragment.baseline())).to_type<int>(),
context.rounded_device_point(fragment_absolute_rect.top_right().translated(0, fragment.baseline())).to_type<int>(), Color::Red);
context.rounded_device_point(fragment_absolute_rect.top_right().translated(-1, fragment.baseline())).to_type<int>(), Color::Red);
}
if (is<Layout::TextNode>(fragment.layout_node()))
paint_text_fragment(context, static_cast<Layout::TextNode const&>(fragment.layout_node()), fragment, phase);
@ -715,7 +715,7 @@ Optional<HitTestResult> PaintableWithLines::hit_test(CSSPixelPoint position, Hit
// The best candidate is either the end of the line above, the beginning of the line below, or the beginning or end of the current line.
// We arbitrarily choose to consider the end of the line above and ignore the beginning of the line below.
// If we knew the direction of selection, we could make a better choice.
if (fragment_absolute_rect.bottom() <= position.y()) { // fully below the fragment
if (fragment_absolute_rect.bottom() - 1 <= position.y()) { // fully below the fragment
last_good_candidate = HitTestResult { const_cast<Paintable&>(*fragment.layout_node().paintable()), fragment.start() + fragment.length() };
} else if (fragment_absolute_rect.top() <= position.y()) { // vertically within the fragment
if (position.x() < fragment_absolute_rect.left()) { // left of the fragment

View file

@ -234,11 +234,10 @@ void paint_box_shadow(PaintContext& context, CSSPixelRect const& content_rect, B
auto top_start = inner_bounding_rect.top() - blurred_edge_thickness;
auto bottom_start = inner_bounding_rect.top() + inner_bounding_rect.height() + (blurred_edge_thickness - horizontal_edge_width);
// Note: The +1s in a few of the following translations are due to the -1s Gfx::Rect::right() and Gfx::Rect::bottom().
auto top_left_corner_blit_pos = inner_bounding_rect.top_left().translated(-blurred_edge_thickness, -blurred_edge_thickness);
auto top_right_corner_blit_pos = inner_bounding_rect.top_right().translated(-top_right_corner_size.width() + 1 + double_radius, -blurred_edge_thickness);
auto bottom_left_corner_blit_pos = inner_bounding_rect.bottom_left().translated(-blurred_edge_thickness, -bottom_left_corner_size.height() + 1 + double_radius);
auto bottom_right_corner_blit_pos = inner_bounding_rect.bottom_right().translated(-bottom_right_corner_size.width() + 1 + double_radius, -bottom_right_corner_size.height() + 1 + double_radius);
auto top_right_corner_blit_pos = inner_bounding_rect.top_right().translated(-top_right_corner_size.width() + double_radius, -blurred_edge_thickness);
auto bottom_left_corner_blit_pos = inner_bounding_rect.bottom_left().translated(-blurred_edge_thickness, -bottom_left_corner_size.height() + double_radius);
auto bottom_right_corner_blit_pos = inner_bounding_rect.bottom_right().translated(-bottom_right_corner_size.width() + double_radius, -bottom_right_corner_size.height() + double_radius);
auto paint_shadow = [&](DevicePixelRect clip_rect) {
Gfx::PainterStateSaver save { painter };
@ -253,15 +252,15 @@ void paint_box_shadow(PaintContext& context, CSSPixelRect const& content_rect, B
painter.blit(bottom_right_corner_blit_pos.to_type<int>(), shadow_bitmap, bottom_right_corner_rect.to_type<int>());
// Horizontal edges
for (auto x = inner_bounding_rect.left() + (bottom_left_corner_size.width() - double_radius); x <= inner_bounding_rect.right() - (bottom_right_corner_size.width() - double_radius); ++x)
for (auto x = inner_bounding_rect.left() + (bottom_left_corner_size.width() - double_radius); x < inner_bounding_rect.right() - (bottom_right_corner_size.width() - double_radius); ++x)
painter.blit({ x, bottom_start }, shadow_bitmap, bottom_edge_rect.to_type<int>());
for (auto x = inner_bounding_rect.left() + (top_left_corner_size.width() - double_radius); x <= inner_bounding_rect.right() - (top_right_corner_size.width() - double_radius); ++x)
for (auto x = inner_bounding_rect.left() + (top_left_corner_size.width() - double_radius); x < inner_bounding_rect.right() - (top_right_corner_size.width() - double_radius); ++x)
painter.blit({ x, top_start }, shadow_bitmap, top_edge_rect.to_type<int>());
// Vertical edges
for (auto y = inner_bounding_rect.top() + (top_right_corner_size.height() - double_radius); y <= inner_bounding_rect.bottom() - (bottom_right_corner_size.height() - double_radius); ++y)
for (auto y = inner_bounding_rect.top() + (top_right_corner_size.height() - double_radius); y < inner_bounding_rect.bottom() - (bottom_right_corner_size.height() - double_radius); ++y)
painter.blit({ right_start, y }, shadow_bitmap, right_edge_rect.to_type<int>());
for (auto y = inner_bounding_rect.top() + (top_left_corner_size.height() - double_radius); y <= inner_bounding_rect.bottom() - (bottom_left_corner_size.height() - double_radius); ++y)
for (auto y = inner_bounding_rect.top() + (top_left_corner_size.height() - double_radius); y < inner_bounding_rect.bottom() - (bottom_left_corner_size.height() - double_radius); ++y)
painter.blit({ left_start, y }, shadow_bitmap, left_edge_rect.to_type<int>());
};
@ -300,13 +299,13 @@ void paint_box_shadow(PaintContext& context, CSSPixelRect const& content_rect, B
paint_shadow({ 0, 0, really_large_number, device_content_rect.top() });
// Everything below content_rect, including sides
paint_shadow({ 0, device_content_rect.bottom() + 1, really_large_number, really_large_number });
paint_shadow({ 0, device_content_rect.bottom(), really_large_number, really_large_number });
// Everything directly to the left of content_rect
paint_shadow({ 0, device_content_rect.top(), device_content_rect.left(), device_content_rect.height() });
// Everything directly to the right of content_rect
paint_shadow({ device_content_rect.right() + 1, device_content_rect.top(), really_large_number, device_content_rect.height() });
paint_shadow({ device_content_rect.right(), device_content_rect.top(), really_large_number, device_content_rect.height() });
if (top_left_corner) {
// Inside the top left corner (the part outside the border radius)
@ -316,19 +315,19 @@ void paint_box_shadow(PaintContext& context, CSSPixelRect const& content_rect, B
if (top_right_corner) {
// Inside the top right corner (the part outside the border radius)
auto top_right = top_right_corner.as_rect().to_type<DevicePixels>().translated(device_content_rect.top_right().translated(-top_right_corner.horizontal_radius + 1, 0));
auto top_right = top_right_corner.as_rect().to_type<DevicePixels>().translated(device_content_rect.top_right().translated(-top_right_corner.horizontal_radius, 0));
paint_shadow(top_right);
}
if (bottom_right_corner) {
// Inside the bottom right corner (the part outside the border radius)
auto bottom_right = bottom_right_corner.as_rect().to_type<DevicePixels>().translated(device_content_rect.bottom_right().translated(-bottom_right_corner.horizontal_radius + 1, -bottom_right_corner.vertical_radius + 1));
auto bottom_right = bottom_right_corner.as_rect().to_type<DevicePixels>().translated(device_content_rect.bottom_right().translated(-bottom_right_corner.horizontal_radius, -bottom_right_corner.vertical_radius));
paint_shadow(bottom_right);
}
if (bottom_left_corner) {
// Inside the bottom left corner (the part outside the border radius)
auto bottom_left = bottom_left_corner.as_rect().to_type<DevicePixels>().translated(device_content_rect.bottom_left().translated(0, -bottom_left_corner.vertical_radius + 1));
auto bottom_left = bottom_left_corner.as_rect().to_type<DevicePixels>().translated(device_content_rect.bottom_left().translated(0, -bottom_left_corner.vertical_radius));
paint_shadow(bottom_left);
}
}