diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2021-04-12 11:47:09 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-02 22:48:06 +0200 |
commit | 88cfaf7bf0ad2d5d3adb2654a5f7cc5b810a3ccd (patch) | |
tree | 47ec61dc9f8fb3ef9867be1cda3db5568e9b6686 /Userland | |
parent | ac238b3bd63e47a334c6859ddb6570b89f7be3dc (diff) | |
download | serenity-88cfaf7bf0ad2d5d3adb2654a5f7cc5b810a3ccd.zip |
LibGfx: Unify Rect, Point, and Size
This commit unifies methods and method/param names between the above
classes, as well as adds [[nodiscard]] and ALWAYS_INLINE where
appropriate. It also renamed the various move_by methods to
translate_by, as that more closely matches the transformation
terminology.
Diffstat (limited to 'Userland')
48 files changed, 280 insertions, 185 deletions
diff --git a/Userland/Applications/Piano/KeysWidget.cpp b/Userland/Applications/Piano/KeysWidget.cpp index c27d18cb50..35d621dd45 100644 --- a/Userland/Applications/Piano/KeysWidget.cpp +++ b/Userland/Applications/Piano/KeysWidget.cpp @@ -242,7 +242,7 @@ int KeysWidget::note_for_event_position(const Gfx::IntPoint& a_point) const return -1; auto point = a_point; - point.move_by(-frame_thickness(), -frame_thickness()); + point.translate_by(-frame_thickness(), -frame_thickness()); int white_keys = point.x() / white_key_width; int note = note_from_white_keys(white_keys); diff --git a/Userland/Applications/Piano/RollWidget.cpp b/Userland/Applications/Piano/RollWidget.cpp index f4c5e36f8b..2416405a74 100644 --- a/Userland/Applications/Piano/RollWidget.cpp +++ b/Userland/Applications/Piano/RollWidget.cpp @@ -112,7 +112,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event) const char* note_name = note_names[note % notes_per_octave]; background_painter.draw_text(note_name_rect, note_name, Gfx::TextAlignment::CenterLeft); - note_name_rect.move_by(Gfx::FontDatabase::default_font().width(note_name) + 2, 0); + note_name_rect.translate_by(Gfx::FontDatabase::default_font().width(note_name) + 2, 0); if (note % notes_per_octave == 0) background_painter.draw_text(note_name_rect, String::formatted("{}", note / notes_per_octave + 1), Gfx::TextAlignment::CenterLeft); } diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 1f1496128d..e904f4c7d1 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -162,7 +162,7 @@ GUI::MouseEvent ImageEditor::event_with_pan_and_scale_applied(const GUI::MouseEv GUI::MouseEvent ImageEditor::event_adjusted_for_layer(const GUI::MouseEvent& event, const Layer& layer) const { auto image_position = editor_position_to_image_position(event.position()); - image_position.move_by(-layer.location().x(), -layer.location().y()); + image_position.translate_by(-layer.location().x(), -layer.location().y()); return { static_cast<GUI::Event::Type>(event.type()), Gfx::IntPoint(image_position.x(), image_position.y()), diff --git a/Userland/Applications/PixelPaint/LayerListWidget.cpp b/Userland/Applications/PixelPaint/LayerListWidget.cpp index efd03f5133..4bc1b019bf 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.cpp +++ b/Userland/Applications/PixelPaint/LayerListWidget.cpp @@ -71,7 +71,7 @@ void LayerListWidget::paint_event(GUI::PaintEvent& event) auto adjusted_rect = gadget.rect; if (gadget.is_moving) { - adjusted_rect.move_by(0, gadget.movement_delta.y()); + adjusted_rect.translate_by(0, gadget.movement_delta.y()); } if (gadget.is_moving) { diff --git a/Userland/Applications/PixelPaint/MoveTool.cpp b/Userland/Applications/PixelPaint/MoveTool.cpp index f708ae458a..39d71d329b 100644 --- a/Userland/Applications/PixelPaint/MoveTool.cpp +++ b/Userland/Applications/PixelPaint/MoveTool.cpp @@ -66,16 +66,16 @@ void MoveTool::on_keydown(GUI::KeyEvent& event) switch (event.key()) { case Key_Up: - new_location.move_by(0, -1); + new_location.translate_by(0, -1); break; case Key_Down: - new_location.move_by(0, 1); + new_location.translate_by(0, 1); break; case Key_Left: - new_location.move_by(-1, 0); + new_location.translate_by(-1, 0); break; case Key_Right: - new_location.move_by(1, 0); + new_location.translate_by(1, 0); break; default: return; diff --git a/Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp b/Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp index 9becc27188..205fecc1c1 100644 --- a/Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp +++ b/Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp @@ -96,10 +96,10 @@ void TreeMapWidget::paint_cell_frame(GUI::Painter& painter, const TreeMapNode& n painter.clear_clip_rect(); painter.add_clip_rect(cell_rect); Gfx::IntRect text_rect = remainder; - text_rect.move_by(2, 2); + text_rect.translate_by(2, 2); painter.draw_text(text_rect, node.name(), font(), Gfx::TextAlignment::TopLeft, Color::Black); if (node_is_leaf(node)) { - text_rect.move_by(0, font().presentation_size() + 1); + text_rect.translate_by(0, font().presentation_size() + 1); painter.draw_text(text_rect, human_readable_size(node.area()), font(), Gfx::TextAlignment::TopLeft, Color::Black); } painter.clear_clip_rect(); diff --git a/Userland/Games/Solitaire/CardStack.cpp b/Userland/Games/Solitaire/CardStack.cpp index e1b830977b..d859678507 100644 --- a/Userland/Games/Solitaire/CardStack.cpp +++ b/Userland/Games/Solitaire/CardStack.cpp @@ -164,9 +164,9 @@ void CardStack::push(NonnullRefPtr<Card> card) if (size && size % m_rules.step == 0) { if (peek().is_upside_down()) - top_most_position.move_by(m_rules.shift_x, m_rules.shift_y_upside_down); + top_most_position.translate_by(m_rules.shift_x, m_rules.shift_y_upside_down); else - top_most_position.move_by(m_rules.shift_x, m_rules.shift_y); + top_most_position.translate_by(m_rules.shift_x, m_rules.shift_y); } if (m_type == Stock) diff --git a/Userland/Games/Solitaire/SolitaireWidget.cpp b/Userland/Games/Solitaire/SolitaireWidget.cpp index 2e6f740b4d..f42cab19a1 100644 --- a/Userland/Games/Solitaire/SolitaireWidget.cpp +++ b/Userland/Games/Solitaire/SolitaireWidget.cpp @@ -256,7 +256,7 @@ void SolitaireWidget::mousemove_event(GUI::MouseEvent& event) for (auto& to_intersect : m_focused_cards) { mark_intersecting_stacks_dirty(to_intersect); - to_intersect.rect().move_by(dx, dy); + to_intersect.rect().translate_by(dx, dy); } m_mouse_down_location = click_location; diff --git a/Userland/Games/Solitaire/SolitaireWidget.h b/Userland/Games/Solitaire/SolitaireWidget.h index eeef14b963..a7d0b95553 100644 --- a/Userland/Games/Solitaire/SolitaireWidget.h +++ b/Userland/Games/Solitaire/SolitaireWidget.h @@ -46,9 +46,9 @@ private: if (m_animation_card->position().y() + Card::height + m_y_velocity > SolitaireWidget::height + 1 && m_y_velocity > 0) { m_y_velocity = min((m_y_velocity * -m_bouncyness), -8.f); m_animation_card->rect().set_y(SolitaireWidget::height - Card::height); - m_animation_card->rect().move_by(m_x_velocity, 0); + m_animation_card->rect().translate_by(m_x_velocity, 0); } else { - m_animation_card->rect().move_by(m_x_velocity, m_y_velocity); + m_animation_card->rect().translate_by(m_x_velocity, m_y_velocity); } } diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index 3c9b81d825..1b78ce29c5 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -188,7 +188,7 @@ void Application::tooltip_show_timer_did_fire() const int margin = 30; Gfx::IntPoint adjusted_pos = WindowServerConnection::the().send_sync<Messages::WindowServer::GetGlobalCursorPosition>()->position(); - adjusted_pos.move_by(0, 18); + adjusted_pos.translate_by(0, 18); if (adjusted_pos.x() + m_tooltip_window->width() >= desktop_rect.width() - margin) { adjusted_pos = adjusted_pos.translated(-m_tooltip_window->width(), 0); diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp index 6d4346f976..7b7aa662c4 100644 --- a/Userland/Libraries/LibGUI/Button.cpp +++ b/Userland/Libraries/LibGUI/Button.cpp @@ -62,7 +62,7 @@ void Button::paint_event(PaintEvent& event) painter.blit_filtered(icon_location.translated(1, 1), *m_icon, m_icon->rect(), [&shadow_color](auto) { return shadow_color; }); - icon_location.move_by(-1, -1); + icon_location.translate_by(-1, -1); } if (m_icon) { @@ -77,7 +77,7 @@ void Button::paint_event(PaintEvent& event) } auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font(); if (m_icon && !text().is_empty()) { - content_rect.move_by(m_icon->width() + icon_spacing(), 0); + content_rect.translate_by(m_icon->width() + icon_spacing(), 0); content_rect.set_width(content_rect.width() - m_icon->width() - icon_spacing()); } diff --git a/Userland/Libraries/LibGUI/HeaderView.cpp b/Userland/Libraries/LibGUI/HeaderView.cpp index a53f75a496..5ff11ce4a4 100644 --- a/Userland/Libraries/LibGUI/HeaderView.cpp +++ b/Userland/Libraries/LibGUI/HeaderView.cpp @@ -246,7 +246,7 @@ void HeaderView::paint_horizontal(Painter& painter) } auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0); if (pressed) - text_rect.move_by(1, 1); + text_rect.translate_by(1, 1); painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text()); x_offset += section_width + m_table_view.horizontal_padding() * 2; } @@ -274,7 +274,7 @@ void HeaderView::paint_vertical(Painter& painter) String text = String::number(section); auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0); if (pressed) - text_rect.move_by(1, 1); + text_rect.translate_by(1, 1); painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text()); y_offset += section_size; } diff --git a/Userland/Libraries/LibGUI/IconView.cpp b/Userland/Libraries/LibGUI/IconView.cpp index 2506fb190b..54d2651045 100644 --- a/Userland/Libraries/LibGUI/IconView.cpp +++ b/Userland/Libraries/LibGUI/IconView.cpp @@ -381,7 +381,7 @@ void IconView::update_item_rects(int item_index, ItemData& item_data) const { auto item_rect = this->item_rect(item_index); item_data.icon_rect.center_within(item_rect); - item_data.icon_rect.move_by(0, item_data.icon_offset_y); + item_data.icon_rect.translate_by(0, item_data.icon_offset_y); item_data.text_rect.center_horizontally_within(item_rect); item_data.text_rect.set_top(item_rect.y() + item_data.text_offset_y); } @@ -418,7 +418,7 @@ void IconView::get_item_rects(int item_index, ItemData& item_data, const Gfx::Fo item_data.icon_rect = { 0, 0, 32, 32 }; item_data.icon_rect.center_within(item_rect); item_data.icon_offset_y = -font.glyph_height() - 6; - item_data.icon_rect.move_by(0, item_data.icon_offset_y); + item_data.icon_rect.translate_by(0, item_data.icon_offset_y); int unwrapped_text_width = font.width(item_data.text); int available_width = item_rect.width() - 6; diff --git a/Userland/Libraries/LibGUI/Label.cpp b/Userland/Libraries/LibGUI/Label.cpp index 886c2c5491..2231373662 100644 --- a/Userland/Libraries/LibGUI/Label.cpp +++ b/Userland/Libraries/LibGUI/Label.cpp @@ -79,7 +79,7 @@ Gfx::IntRect Label::text_rect(size_t line) const if (frame_thickness() > 0) indent = font().glyph_width('x') / 2; auto rect = frame_inner_rect(); - rect.move_by(indent, line * (font().glyph_height() + 1)); + rect.translate_by(indent, line * (font().glyph_height() + 1)); rect.set_width(rect.width() - indent * 2); return rect; } diff --git a/Userland/Libraries/LibGUI/ListView.cpp b/Userland/Libraries/LibGUI/ListView.cpp index 62f798b7b8..50a869f78c 100644 --- a/Userland/Libraries/LibGUI/ListView.cpp +++ b/Userland/Libraries/LibGUI/ListView.cpp @@ -127,7 +127,7 @@ void ListView::paint_list_item(Painter& painter, int row_index, int painted_item else text_color = index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); auto text_rect = row_rect; - text_rect.move_by(horizontal_padding(), 0); + text_rect.translate_by(horizontal_padding(), 0); text_rect.set_width(text_rect.width() - horizontal_padding() * 2); auto text_alignment = index.data(ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); painter.draw_text(text_rect, data.to_string(), font, text_alignment, text_color); diff --git a/Userland/Libraries/LibGUI/ScrollableWidget.cpp b/Userland/Libraries/LibGUI/ScrollableWidget.cpp index ca75a7e99d..8d586b499e 100644 --- a/Userland/Libraries/LibGUI/ScrollableWidget.cpp +++ b/Userland/Libraries/LibGUI/ScrollableWidget.cpp @@ -225,16 +225,16 @@ Gfx::IntRect ScrollableWidget::widget_inner_rect() const Gfx::IntPoint ScrollableWidget::to_content_position(const Gfx::IntPoint& widget_position) const { auto content_position = widget_position; - content_position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value()); - content_position.move_by(-frame_thickness(), -frame_thickness()); + content_position.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value()); + content_position.translate_by(-frame_thickness(), -frame_thickness()); return content_position; } Gfx::IntPoint ScrollableWidget::to_widget_position(const Gfx::IntPoint& content_position) const { auto widget_position = content_position; - widget_position.move_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value()); - widget_position.move_by(frame_thickness(), frame_thickness()); + widget_position.translate_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value()); + widget_position.translate_by(frame_thickness(), frame_thickness()); return widget_position; } diff --git a/Userland/Libraries/LibGUI/Scrollbar.cpp b/Userland/Libraries/LibGUI/Scrollbar.cpp index ca26d7e179..bf2d277ea9 100644 --- a/Userland/Libraries/LibGUI/Scrollbar.cpp +++ b/Userland/Libraries/LibGUI/Scrollbar.cpp @@ -201,14 +201,14 @@ void Scrollbar::paint_event(PaintEvent& event) if (length(orientation()) > default_button_size()) { auto decrement_location = decrement_button_rect().location().translated(3, 3); if (decrement_pressed) - decrement_location.move_by(1, 1); + decrement_location.translate_by(1, 1); if (!has_scrubber() || !is_enabled()) painter.draw_bitmap(decrement_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, palette().threed_highlight()); painter.draw_bitmap(decrement_location, orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1()); auto increment_location = increment_button_rect().location().translated(3, 3); if (increment_pressed) - increment_location.move_by(1, 1); + increment_location.translate_by(1, 1); if (!has_scrubber() || !is_enabled()) painter.draw_bitmap(increment_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, palette().threed_highlight()); painter.draw_bitmap(increment_location, orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1()); diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp index bc6bf51843..646d07e55b 100644 --- a/Userland/Libraries/LibGUI/TabWidget.cpp +++ b/Userland/Libraries/LibGUI/TabWidget.cpp @@ -197,7 +197,7 @@ void TabWidget::paint_event(PaintEvent& event) if (!icon) return; Gfx::IntRect icon_rect { button_rect.x(), button_rect.y(), 16, 16 }; - icon_rect.move_by(4, 3); + icon_rect.translate_by(4, 3); painter.draw_scaled_bitmap(icon_rect, *icon, icon->rect()); text_rect.set_x(icon_rect.right() + 1 + 4); text_rect.intersect(button_rect); @@ -281,13 +281,13 @@ Gfx::IntRect TabWidget::button_rect(int index) const } Gfx::IntRect rect { x_offset, 0, m_uniform_tabs ? uniform_tab_width() : m_tabs[index].width(font()), bar_height() }; if (m_tabs[index].widget != m_active_widget) { - rect.move_by(0, m_tab_position == TabPosition::Top ? 2 : 0); + rect.translate_by(0, m_tab_position == TabPosition::Top ? 2 : 0); rect.set_height(rect.height() - 2); } else { - rect.move_by(-2, 0); + rect.translate_by(-2, 0); rect.set_width(rect.width() + 4); } - rect.move_by(bar_rect().location()); + rect.translate_by(bar_rect().location()); return rect; } diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index b6ab495466..68dff0002e 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -134,7 +134,7 @@ TextPosition TextEditor::text_position_at_content_position(const Gfx::IntPoint& { auto position = content_position; if (is_single_line() && icon()) - position.move_by(-(icon_size() + icon_padding()), 0); + position.translate_by(-(icon_size() + icon_padding()), 0); size_t line_index = 0; @@ -194,9 +194,9 @@ TextPosition TextEditor::text_position_at_content_position(const Gfx::IntPoint& TextPosition TextEditor::text_position_at(const Gfx::IntPoint& widget_position) const { auto content_position = widget_position; - content_position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value()); - content_position.move_by(-(m_horizontal_content_padding + ruler_width()), 0); - content_position.move_by(-frame_thickness(), -frame_thickness()); + content_position.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value()); + content_position.translate_by(-(m_horizontal_content_padding + ruler_width()), 0); + content_position.translate_by(-frame_thickness(), -frame_thickness()); return text_position_at_content_position(content_position); } @@ -435,8 +435,8 @@ void TextEditor::paint_event(PaintEvent& event) height() - height_occupied_by_horizontal_scrollbar() }; if (m_ruler_visible) - text_clip_rect.move_by(-ruler_width(), 0); - text_clip_rect.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value()); + text_clip_rect.translate_by(-ruler_width(), 0); + text_clip_rect.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value()); painter.add_clip_rect(text_clip_rect); size_t span_index = 0; @@ -507,7 +507,7 @@ void TextEditor::paint_event(PaintEvent& event) if (underline) { painter.draw_line(span_rect.bottom_left().translated(0, 1), span_rect.bottom_right().translated(0, 1), color); } - span_rect.move_by(span_rect.width(), 0); + span_rect.translate_by(span_rect.width(), 0); }; for (;;) { if (span_index >= document().spans().size()) { @@ -1015,8 +1015,8 @@ Gfx::IntRect TextEditor::line_widget_rect(size_t line_index) const auto rect = line_content_rect(line_index); rect.set_x(frame_thickness()); rect.set_width(frame_inner_rect().width()); - rect.move_by(0, -(vertical_scrollbar().value())); - rect.move_by(0, frame_thickness()); + rect.translate_by(0, -(vertical_scrollbar().value())); + rect.translate_by(0, frame_thickness()); rect.intersect(frame_inner_rect()); return rect; } @@ -1567,7 +1567,7 @@ void TextEditor::for_each_visual_line(size_t line_index, Callback callback) cons if (is_single_line()) { visual_line_rect.center_vertically_within(editor_visible_text_rect); if (m_icon) - visual_line_rect.move_by(icon_size() + icon_padding(), 0); + visual_line_rect.translate_by(icon_size() + icon_padding(), 0); } if (callback(visual_line_rect, visual_line_view, start_of_line, visual_line_index == visual_data.visual_line_breaks.size() - 1) == IterationDecision::Break) break; diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index a869252713..8f1bb2aeaa 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -575,7 +575,7 @@ Gfx::IntRect Widget::window_relative_rect() const { auto rect = relative_rect(); for (auto* parent = parent_widget(); parent; parent = parent->parent_widget()) { - rect.move_by(parent->relative_position()); + rect.translate_by(parent->relative_position()); } return rect; } @@ -957,7 +957,7 @@ void Widget::set_content_margins(const Margins& margins) Gfx::IntRect Widget::content_rect() const { auto rect = relative_rect(); - rect.move_by(m_content_margins.left(), m_content_margins.top()); + rect.translate_by(m_content_margins.left(), m_content_margins.top()); rect.set_width(rect.width() - (m_content_margins.left() + m_content_margins.right())); rect.set_height(rect.height() - (m_content_margins.top() + m_content_margins.bottom())); return rect; diff --git a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp index 84dd0af819..6509350f58 100644 --- a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp +++ b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp @@ -319,7 +319,7 @@ void ClassicStylePainter::paint_progressbar(Painter& painter, const IntRect& rec float progress_height = progress * rect.height(); hole_rect = { 0, 0, rect.width(), (int)(rect.height() - progress_height) }; } - hole_rect.move_by(rect.location()); + hole_rect.translate_by(rect.location()); hole_rect.set_right_without_resize(rect.right()); PainterStateSaver saver(painter); painter.fill_rect(hole_rect, palette.base()); diff --git a/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp b/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp index 0fd2aab5e1..9c3ea5e7ba 100644 --- a/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp +++ b/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp @@ -36,7 +36,7 @@ Gfx::IntRect ClassicWindowTheme::titlebar_icon_rect(WindowType window_type, cons 16, }; icon_rect.center_vertically_within(titlebar_rect); - icon_rect.move_by(0, 1); + icon_rect.translate_by(0, 1); return icon_rect; } diff --git a/Userland/Libraries/LibGfx/DisjointRectSet.cpp b/Userland/Libraries/LibGfx/DisjointRectSet.cpp index 4a17e35166..e2a4a0b181 100644 --- a/Userland/Libraries/LibGfx/DisjointRectSet.cpp +++ b/Userland/Libraries/LibGfx/DisjointRectSet.cpp @@ -56,7 +56,7 @@ void DisjointRectSet::shatter() void DisjointRectSet::move_by(int dx, int dy) { for (auto& r : m_rects) - r.move_by(dx, dy); + r.translate_by(dx, dy); } bool DisjointRectSet::contains(const IntRect& rect) const diff --git a/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h b/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h index 11854e5a40..b82a4cd0be 100644 --- a/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h +++ b/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h @@ -95,7 +95,7 @@ public: // TODO: We probably don't need the entire source_rect, we could inflate // the target_rect appropriately apply_cache.m_target = Gfx::Bitmap::create(source.format(), source_rect.size()); - target_rect.move_by(-target_rect.location()); + target_rect.translate_by(-target_rect.location()); } Bitmap* render_target_bitmap = (&target != &source) ? &target : apply_cache.m_target.ptr(); diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index d98e8a45f1..ff4e31f603 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1070,28 +1070,28 @@ void draw_text_line(const IntRect& a_rect, const TextType& text, const Font& fon if (is_vertically_centered_text_alignment(alignment)) { int distance_from_baseline_to_bottom = (font.glyph_height() - 1) - font.baseline(); - rect.move_by(0, distance_from_baseline_to_bottom / 2); + rect.translate_by(0, distance_from_baseline_to_bottom / 2); } auto point = rect.location(); int space_width = font.glyph_width(' ') + font.glyph_spacing(); if (direction == TextDirection::RTL) { - point.move_by(rect.width(), 0); // Start drawing from the end - space_width = -space_width; // Draw spaces backwards + point.translate_by(rect.width(), 0); // Start drawing from the end + space_width = -space_width; // Draw spaces backwards } for (u32 code_point : final_text) { if (code_point == ' ') { - point.move_by(space_width, 0); + point.translate_by(space_width, 0); continue; } IntSize glyph_size(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), font.glyph_height()); if (direction == TextDirection::RTL) - point.move_by(-glyph_size.width(), 0); // If we are drawing right to left, we have to move backwards before drawing the glyph + point.translate_by(-glyph_size.width(), 0); // If we are drawing right to left, we have to move backwards before drawing the glyph draw_glyph({ point, glyph_size }, code_point); if (direction == TextDirection::LTR) - point.move_by(glyph_size.width(), 0); + point.translate_by(glyph_size.width(), 0); } } @@ -1414,7 +1414,7 @@ void Painter::set_pixel(const IntPoint& p, Color color) VERIFY(scale() == 1); // FIXME: Add scaling support. auto point = p; - point.move_by(state().translation); + point.translate_by(state().translation); if (!clip_rect().contains(point)) return; m_target->scanline(point.y())[point.x()] = color.value(); diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h index f0f4fbb658..774076a21c 100644 --- a/Userland/Libraries/LibGfx/Painter.h +++ b/Userland/Libraries/LibGfx/Painter.h @@ -100,7 +100,7 @@ public: void clear_clip_rect(); void translate(int dx, int dy) { translate({ dx, dy }); } - void translate(const IntPoint& delta) { state().translation.move_by(delta); } + void translate(const IntPoint& delta) { state().translation.translate_by(delta); } Gfx::Bitmap* target() { return m_target.ptr(); } diff --git a/Userland/Libraries/LibGfx/Path.cpp b/Userland/Libraries/LibGfx/Path.cpp index 46fb6f6db9..4f6fb916f4 100644 --- a/Userland/Libraries/LibGfx/Path.cpp +++ b/Userland/Libraries/LibGfx/Path.cpp @@ -50,7 +50,7 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d } // Move the endpoint by a small amount to avoid division by zero. - next_point.move_by(0.01f, 0.01f); + next_point.translate_by(0.01f, 0.01f); } // Find (cx, cy), theta_1, theta_delta diff --git a/Userland/Libraries/LibGfx/Point.h b/Userland/Libraries/LibGfx/Point.h index 3a8b3eedf6..e6b239deef 100644 --- a/Userland/Libraries/LibGfx/Point.h +++ b/Userland/Libraries/LibGfx/Point.h @@ -8,6 +8,7 @@ #include <AK/Format.h> #include <AK/StdLibExtras.h> +#include <LibGfx/AffineTransform.h> #include <LibGfx/Forward.h> #include <LibGfx/Orientation.h> #include <LibIPC/Forward.h> @@ -19,7 +20,7 @@ namespace Gfx { template<typename T> class Point { public: - Point() { } + Point() = default; Point(T x, T y) : m_x(x) @@ -41,41 +42,74 @@ public: { } - T x() const { return m_x; } - T y() const { return m_y; } + [[nodiscard]] ALWAYS_INLINE T x() const { return m_x; } + [[nodiscard]] ALWAYS_INLINE T y() const { return m_y; } - void set_x(T x) { m_x = x; } - void set_y(T y) { m_y = y; } + ALWAYS_INLINE void set_x(T x) { m_x = x; } + ALWAYS_INLINE void set_y(T y) { m_y = y; } - void move_by(T dx, T dy) + [[nodiscard]] ALWAYS_INLINE bool is_null() const { return !m_x && !m_y; } + [[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_x <= 0 && m_y <= 0; } + + void translate_by(T dx, T dy) { m_x += dx; m_y += dy; } - void move_by(const Point<T>& delta) + ALWAYS_INLINE void translate_by(T dboth) { translate_by(dboth, dboth); } + ALWAYS_INLINE void translate_by(const Point<T>& delta) { translate_by(delta.x(), delta.y()); } + + void scale_by(T dx, T dy) { - move_by(delta.x(), delta.y()); + m_x *= dx; + m_y *= dy; } + ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); } + ALWAYS_INLINE void scale_by(const Point<T>& delta) { scale_by(delta.x(), delta.y()); } + + void transform_by(const AffineTransform& transform) { *this = transform.map(*this); } + Point<T> translated(const Point<T>& delta) const { Point<T> point = *this; - point.move_by(delta); + point.translate_by(delta); return point; } Point<T> translated(T dx, T dy) const { Point<T> point = *this; - point.move_by(dx, dy); + point.translate_by(dx, dy); return point; } Point<T> translated(T dboth) const { Point<T> point = *this; - point.move_by(dboth, dboth); + point.translate_by(dboth, dboth); + return point; + } + + Point<T> scaled(const Point<T>& delta) const + { + Point<T> point = *this; + point.scale_by(delta); + return point; + } + + Point<T> scaled(T sx, T sy) const + { + Point<T> point = *this; + point.scale_by(sx, sy); + return point; + } + + Point<T> transformed(const AffineTransform& transform) const + { + Point<T> point = *this; + point.transform_by(transform); return point; } @@ -87,6 +121,11 @@ public: return point; } + Point<T> moved_left(T amount) const { return { x() - amount, y() }; } + Point<T> moved_right(T amount) const { return { x() + amount, y() }; } + Point<T> moved_up(T amount) const { return { x(), y() - amount }; } + Point<T> moved_down(T amount) const { return { x(), y() + amount }; } + template<class U> bool operator==(const Point<U>& other) const { @@ -137,8 +176,6 @@ public: return *this; } - bool is_null() const { return !m_x && !m_y; } - T primary_offset_for_orientation(Orientation orientation) const { return orientation == Orientation::Vertical ? y() : x(); diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index f0d72c447a..9b4138d12a 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -7,6 +7,7 @@ #pragma once #include <AK/Format.h> +#include <LibGfx/AffineTransform.h> #include <LibGfx/Orientation.h> #include <LibGfx/Point.h> #include <LibGfx/Size.h> @@ -24,7 +25,7 @@ T abst(T value) template<typename T> class Rect { public: - Rect() { } + Rect() = default; Rect(T x, T y, T width, T height) : m_location(x, y) @@ -59,37 +60,47 @@ public: { } - bool is_null() const - { - return width() == 0 && height() == 0; - } + [[nodiscard]] ALWAYS_INLINE T x() const { return location().x(); } + [[nodiscard]] ALWAYS_INLINE T y() const { return location().y(); } + [[nodiscard]] ALWAYS_INLINE T width() const { return m_size.width(); } + [[nodiscard]] ALWAYS_INLINE T height() const { return m_size.height(); } - bool is_empty() const - { - return width() <= 0 || height() <= 0; - } + ALWAYS_INLINE void set_x(T x) { m_location.set_x(x); } + ALWAYS_INLINE void set_y(T y) { m_location.set_y(y); } + ALWAYS_INLINE void set_width(T width) { m_size.set_width(width); } + ALWAYS_INLINE void set_height(T height) { m_size.set_height(height); } - void move_by(T dx, T dy) - { - m_location.move_by(dx, dy); - } + [[nodiscard]] ALWAYS_INLINE const Point<T>& location() const { return m_location; } + [[nodiscard]] ALWAYS_INLINE const Size<T>& size() const { return m_size; } - void move_by(const Point<T>& delta) + [[nodiscard]] ALWAYS_INLINE bool is_null() const { return width() == 0 && height() == 0; } + [[nodiscard]] ALWAYS_INLINE bool is_empty() const { return width() <= 0 || height() <= 0; } + + ALWAYS_INLINE void translate_by(T dx, T dy) { m_location.translate_by(dx, dy); } + ALWAYS_INLINE void translate_by(T dboth) { m_location.translate_by(dboth); } + ALWAYS_INLINE void translate_by(const Point<T>& delta) { m_location.translate_by(delta); } + + ALWAYS_INLINE void scale_by(T dx, T dy) { - m_location.move_by(delta); + m_location.scale_by(dx, dy); + m_size.scale_by(dx, dy); } + ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); } + ALWAYS_INLINE void scale_by(const Point<T>& delta) { scale_by(delta.x(), delta.y()); } + + void transform_by(const AffineTransform& transform) { *this = transform.map(*this); } Point<T> center() const { return { x() + width() / 2, y() + height() / 2 }; } - void set_location(const Point<T>& location) + ALWAYS_INLINE void set_location(const Point<T>& location) { m_location = location; } - void set_size(const Size<T>& size) + ALWAYS_INLINE void set_size(const Size<T>& size) { m_size = size; } @@ -134,45 +145,66 @@ public: set_height(height() - size.height()); } - Rect<T> shrunken(T w, T h) const + Rect<T> translated(T dx, T dy) const { Rect<T> rect = *this; - rect.shrink(w, h); + rect.translate_by(dx, dy); return rect; } - Rect<T> shrunken(const Size<T>& size) const + Rect<T> translated(const Point<T>& delta) const { Rect<T> rect = *this; - rect.shrink(size); + rect.translate_by(delta); return rect; } - Rect<T> inflated(T w, T h) const + Rect<T> scaled(T sx, T sy) const { Rect<T> rect = *this; - rect.inflate(w, h); + rect.scale_by(sx, sy); return rect; } - Rect<T> inflated(const Size<T>& size) const + Rect<T> scaled(const Point<T>& s) const { Rect<T> rect = *this; - rect.inflate(size); + rect.scale_by(s); return rect; } - Rect<T> translated(T dx, T dy) const + Rect<T> transformed(const AffineTransform& transform) const { Rect<T> rect = *this; - rect.move_by(dx, dy); + rect.transform_by(transform); return rect; } - Rect<T> translated(const Point<T>& delta) const + Rect<T> shrunken(T w, T h) const { Rect<T> rect = *this; - rect.move_by(delta); + rect.shrink(w, h); + return rect; + } + + Rect<T> shrunken(const Size<T>& size) const + { + Rect<T> rect = *this; + rect.shrink(size); + return rect; + } + + Rect<T> inflated(T w, T h) const + { + Rect<T> rect = *this; + rect.inflate(w, h); + return rect; + } + + Rect<T> inflated(const Size<T>& size) const + { + Rect<T> rect = *this; + rect.inflate(size); return rect; } @@ -235,7 +267,7 @@ public: return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom(); } - bool contains(const Point<T>& point) const + ALWAYS_INLINE bool contains(const Point<T>& point) const { return contains(point.x(), point.y()); } @@ -260,15 +292,15 @@ public: return have_any; } - int primary_offset_for_orientation(Orientation orientation) const { return m_location.primary_offset_for_orientation(orientation); } - void set_primary_offset_for_orientation(Orientation orientation, int value) { m_location.set_primary_offset_for_orientation(orientation, value); } - int secondary_offset_for_orientation(Orientation orientation) const { return m_location.secondary_offset_for_orientation(orientation); } - void set_secondary_offset_for_orientation(Orientation orientation, int value) { m_location.set_secondary_offset_for_orientation(orientation, value); } + ALWAYS_INLINE int primary_offset_for_orientation(Orientation orientation) const { return m_location.primary_offset_for_orientation(orientation); } + ALWAYS_INLINE void set_primary_offset_for_orientation(Orientation orientation, int value) { m_location.set_primary_offset_for_orientation(orientation, value); } + ALWAYS_INLINE int secondary_offset_for_orientation(Orientation orientation) const { return m_location.secondary_offset_for_orientation(orientation); } + ALWAYS_INLINE void set_secondary_offset_for_orientation(Orientation orientation, int value) { m_location.set_secondary_offset_for_orientation(orientation, value); } - int primary_size_for_orientation(Orientation orientation) const { return m_size.primary_size_for_orientation(orientation); } - int secondary_size_for_orientation(Orientation orientation) const { return m_size.secondary_size_for_orientation(orientation); } - void set_primary_size_for_orientation(Orientation orientation, int value) { m_size.set_primary_size_for_orientation(orientation, value); } - void set_secondary_size_for_orientation(Orientation orientation, int value) { m_size.set_secondary_size_for_orientation(orientation, value); } + ALWAYS_INLINE int primary_size_for_orientation(Orientation orientation) const { return m_size.primary_size_for_orientation(orientation); } + ALWAYS_INLINE int secondary_size_for_orientation(Orientation orientation) const { return m_size.secondary_size_for_orientation(orientation); } + ALWAYS_INLINE void set_primary_size_for_orientation(Orientation orientation, int value) { m_size.set_primary_size_for_orientation(orientation, value); } + ALWAYS_INLINE void set_secondary_size_for_orientation(Orientation orientation, int value) { m_size.set_secondary_size_for_orientation(orientation, value); } T first_edge_for_orientation(Orientation orientation) const { @@ -284,27 +316,27 @@ public: return right(); } - T left() const { return x(); } - T right() const { return x() + width() - 1; } - T top() const { return y(); } - T bottom() const { return y() + height() - 1; } + [[nodiscard]] ALWAYS_INLINE T left() const { return x(); } + [[nodiscard]] ALWAYS_INLINE T right() const { return x() + width() - 1; } + [[nodiscard]] ALWAYS_INLINE T top() const { return y(); } + [[nodiscard]] ALWAYS_INLINE T bottom() const { return y() + height() - 1; } - void set_left(T left) + ALWAYS_INLINE void set_left(T left) { set_x(left); } - void set_top(T top) + ALWAYS_INLINE void set_top(T top) { set_y(top); } - void set_right(T right) + ALWAYS_INLINE void set_right(T right) { set_width(right - x() + 1); } - void set_bottom(T bottom) + ALWAYS_INLINE void set_bottom(T bottom) { set_height(bottom - y() + 1); } @@ -312,13 +344,13 @@ public: void set_right_without_resize(T new_right) { int delta = new_right - right(); - move_by(delta, 0); + translate_by(delta, 0); } void set_bottom_without_resize(T new_bottom) { int delta = new_bottom - bottom(); - move_by(0, delta); + translate_by(0, delta); } bool intersects_vertically(const Rect<T>& other) const @@ -365,19 +397,6 @@ public: return IterationDecision::Continue; } - T x() const { return location().x(); } - T y() const { return location().y(); } - T width() const { return m_size.width(); } - T height() const { return m_size.height(); } - - void set_x(T x) { m_location.set_x(x); } - void set_y(T y) { m_location.set_y(y); } - void set_width(T width) { m_size.set_width(width); } - void set_height(T height) { m_size.set_height(height); } - - const Point<T>& location() const { return m_location; } - const Size<T>& size() const { return m_size; } - Vector<Rect<T>, 4> shatter(const Rect<T>& hammer) const; template<class U> @@ -415,7 +434,7 @@ public: return r; } - Rect<T> intersected(const Rect<T>& other) const + ALWAYS_INLINE Rect<T> intersected(const Rect<T>& other) const { return intersection(*this, other); } @@ -446,7 +465,7 @@ public: } template<typename U> - Rect<U> to() const + ALWAYS_INLINE Rect<U> to_type() const { return Rect<U>(*this); } diff --git a/Userland/Libraries/LibGfx/Size.h b/Userland/Libraries/LibGfx/Size.h index f2c52c1740..958f80d7de 100644 --- a/Userland/Libraries/LibGfx/Size.h +++ b/Userland/Libraries/LibGfx/Size.h @@ -8,6 +8,7 @@ #include <AK/Format.h> #include <LibGfx/Orientation.h> +#include <LibGfx/Point.h> #include <LibIPC/Forward.h> namespace Gfx { @@ -15,7 +16,7 @@ namespace Gfx { template<typename T> class Size { public: - Size() { } + Size() = default; Size(T w, T h) : m_width(w) @@ -37,16 +38,54 @@ public: { } - bool is_null() const { return !m_width && !m_height; } - bool is_empty() const { return m_width <= 0 || m_height <= 0; } + [[nodiscard]] ALWAYS_INLINE T width() const { return m_width; } + [[nodiscard]] ALWAYS_INLINE T height() const { return m_height; } + [[nodiscard]] ALWAYS_INLINE T area() const { return width() * height(); } - T width() const { return m_width; } - T height() const { return m_height; } + ALWAYS_INLINE void set_width(T w) { m_width = w; } + ALWAYS_INLINE void set_height(T h) { m_height = h; } - T area() const { return width() * height(); } + [[nodiscard]] ALWAYS_INLINE bool is_null() const { return !m_width && !m_height; } + [[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_width <= 0 || m_height <= 0; } - void set_width(T w) { m_width = w; } - void set_height(T h) { m_height = h; } + void scale_by(T dx, T dy) + { + m_width *= dx; + m_height *= dy; + } + + void transform_by(const AffineTransform& transform) { *this = transform.map(*this); } + + ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); } + ALWAYS_INLINE void scale_by(const Point<T>& s) { scale_by(s.x(), s.y()); } + + Size scaled_by(T dx, T dy) const + { + Size<T> size = *this; + size.scale_by(dx, dy); + return size; + } + + Size scaled_by(T dboth) const + { + Size<T> size = *this; + size.scale_by(dboth); + return size; + } + + Size scaled_by(const Point<T>& s) const + { + Size<T> size = *this; + size.scale_by(s); + return size; + } + + Size transformed_by(const AffineTransform& transform) const + { + Size<T> size = *this; + size.transform_by(transform); + return size; + } template<typename U> bool contains(const Size<U>& other) const @@ -118,7 +157,7 @@ public: } template<typename U> - Size<U> to_type() const + ALWAYS_INLINE Size<U> to_type() const { return Size<U>(*this); } diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index ba33075fae..6050649d3f 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -157,7 +157,7 @@ void CanvasRenderingContext2D::fill_text(const String& text, float x, float y, O auto text_rect = Gfx::IntRect(x, y, max_width.has_value() ? max_width.value() : painter->font().width(text), painter->font().glyph_height()); auto transformed_rect = m_transform.map(text_rect); painter->draw_text(transformed_rect, text, Gfx::TextAlignment::TopLeft, m_fill_style); - did_draw(transformed_rect.to<float>()); + did_draw(transformed_rect.to_type<float>()); } void CanvasRenderingContext2D::begin_path() diff --git a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp index 79a6c1e855..6682dbb8de 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp @@ -142,7 +142,7 @@ bool BlockBox::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsi if (!is_scrollable()) return false; auto new_offset = m_scroll_offset; - new_offset.move_by(0, wheel_delta); + new_offset.translate_by(0, wheel_delta); set_scroll_offset(new_offset); return true; diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index a93207c9c0..815f2bf6bc 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -550,7 +550,7 @@ static Gfx::FloatRect rect_in_coordinate_space(const Box& box, const Box& contex for (auto* ancestor = box.parent(); ancestor; ancestor = ancestor->parent()) { if (is<Box>(*ancestor)) { auto offset = downcast<Box>(*ancestor).effective_offset(); - rect.move_by(offset); + rect.translate_by(offset); } if (ancestor == &context_box) break; diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index fbeb4723f7..523bad3dae 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -154,7 +154,7 @@ const Gfx::FloatRect Box::absolute_rect() const { Gfx::FloatRect rect { effective_offset(), size() }; for (auto* block = containing_block(); block; block = block->containing_block()) { - rect.move_by(block->effective_offset()); + rect.translate_by(block->effective_offset()); } return rect; } diff --git a/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp b/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp index af5eb88344..614f4bcada 100644 --- a/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp @@ -49,7 +49,7 @@ void ButtonBox::paint(PaintContext& context, PaintPhase phase) auto text_rect = enclosing_int_rect(absolute_rect()); if (m_being_pressed) - text_rect.move_by(1, 1); + text_rect.translate_by(1, 1); context.painter().draw_text(text_rect, dom_node().value(), font(), Gfx::TextAlignment::Center, context.palette().button_text()); } } diff --git a/Userland/Libraries/LibWeb/Layout/FrameBox.cpp b/Userland/Libraries/LibWeb/Layout/FrameBox.cpp index bf1439b91d..092aa61d37 100644 --- a/Userland/Libraries/LibWeb/Layout/FrameBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/FrameBox.cpp @@ -60,7 +60,7 @@ void FrameBox::paint(PaintContext& context, PaintPhase phase) if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) { if (dom_node().content_frame()->is_focused_frame()) { - context.painter().draw_rect(absolute_rect().to<int>(), Color::Cyan); + context.painter().draw_rect(absolute_rect().to_type<int>(), Color::Cyan); } } } diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp index 1cd544847c..c358c08d66 100644 --- a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp @@ -110,7 +110,7 @@ bool ImageBox::renders_as_alt_text() const void ImageBox::frame_did_set_viewport_rect(const Gfx::IntRect& viewport_rect) { - m_image_loader.set_visible_in_viewport(viewport_rect.to<float>().intersects(absolute_rect())); + m_image_loader.set_visible_in_viewport(viewport_rect.to_type<float>().intersects(absolute_rect())); } } diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 5790643d37..535541a97a 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -154,7 +154,7 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode) // Shift subsequent sibling fragments to the right to adjust for change in width. for (size_t j = i + 1; j < line_box.fragments().size(); ++j) { auto offset = line_box.fragments()[j].offset(); - offset.move_by(diff, 0); + offset.translate_by(diff, 0); line_box.fragments()[j].set_offset(offset); } } diff --git a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp index b039148155..856e5849a0 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -48,7 +48,7 @@ const Gfx::FloatRect LineBoxFragment::absolute_rect() const { Gfx::FloatRect rect { {}, size() }; rect.set_location(m_layout_node.containing_block()->absolute_position()); - rect.move_by(offset()); + rect.translate_by(offset()); return rect; } diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 51b5b82601..c51945b225 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -319,7 +319,7 @@ bool Node::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned if (!containing_block->is_scrollable()) return false; auto new_offset = containing_block->scroll_offset(); - new_offset.move_by(0, wheel_delta); + new_offset.translate_by(0, wheel_delta); containing_block->set_scroll_offset(new_offset); return true; } diff --git a/Userland/Libraries/LibWeb/Page/Frame.cpp b/Userland/Libraries/LibWeb/Page/Frame.cpp index aea48fcb07..99c0e111b3 100644 --- a/Userland/Libraries/LibWeb/Page/Frame.cpp +++ b/Userland/Libraries/LibWeb/Page/Frame.cpp @@ -182,7 +182,7 @@ void Frame::scroll_to_anchor(const String& fragment) if (is<Layout::Box>(layout_node)) { auto& layout_box = downcast<Layout::Box>(layout_node); auto padding_box = layout_box.box_model().padding_box(); - float_rect.move_by(-padding_box.left, -padding_box.top); + float_rect.translate_by(-padding_box.left, -padding_box.top); } if (m_page) @@ -206,7 +206,7 @@ Gfx::IntPoint Frame::to_main_frame_position(const Gfx::IntPoint& a_position) return {}; if (!ancestor->host_element()->layout_node()) return {}; - position.move_by(ancestor->host_element()->layout_node()->box_type_agnostic_position().to_type<int>()); + position.translate_by(ancestor->host_element()->layout_node()->box_type_agnostic_position().to_type<int>()); } return position; } diff --git a/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp b/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp index a2151bef8e..a5c68f1c36 100644 --- a/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp @@ -72,20 +72,20 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect& if (gfx_line_style != Gfx::Painter::LineStyle::Solid) { switch (edge) { case BorderEdge::Top: - p1.move_by(int_width / 2, int_width / 2); - p2.move_by(-int_width / 2, int_width / 2); + p1.translate_by(int_width / 2, int_width / 2); + p2.translate_by(-int_width / 2, int_width / 2); break; case BorderEdge::Right: - p1.move_by(-int_width / 2, int_width / 2); - p2.move_by(-int_width / 2, -int_width / 2); + p1.translate_by(-int_width / 2, int_width / 2); + p2.translate_by(-int_width / 2, -int_width / 2); break; case BorderEdge::Bottom: - p1.move_by(int_width / 2, -int_width / 2); - p2.move_by(-int_width / 2, -int_width / 2); + p1.translate_by(int_width / 2, -int_width / 2); + p2.translate_by(-int_width / 2, -int_width / 2); break; case BorderEdge::Left: - p1.move_by(int_width / 2, int_width / 2); - p2.move_by(int_width / 2, -int_width / 2); + p1.translate_by(int_width / 2, int_width / 2); + p2.translate_by(int_width / 2, -int_width / 2); break; } context.painter().draw_line({ (int)p1.x(), (int)p1.y() }, { (int)p2.x(), (int)p2.y() }, color, int_width, gfx_line_style); @@ -105,8 +105,8 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect& p2_step = style.border_right().width / (float)int_width; for (int i = 0; i < int_width; ++i) { draw_line(p1, p2); - p1.move_by(p1_step, 1); - p2.move_by(-p2_step, 1); + p1.translate_by(p1_step, 1); + p2.translate_by(-p2_step, 1); } break; case BorderEdge::Right: @@ -114,8 +114,8 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect& p2_step = style.border_bottom().width / (float)int_width; for (int i = int_width - 1; i >= 0; --i) { draw_line(p1, p2); - p1.move_by(-1, p1_step); - p2.move_by(-1, -p2_step); + p1.translate_by(-1, p1_step); + p2.translate_by(-1, -p2_step); } break; case BorderEdge::Bottom: @@ -123,8 +123,8 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect& p2_step = style.border_right().width / (float)int_width; for (int i = int_width - 1; i >= 0; --i) { draw_line(p1, p2); - p1.move_by(p1_step, -1); - p2.move_by(-p2_step, -1); + p1.translate_by(p1_step, -1); + p2.translate_by(-p2_step, -1); } break; case BorderEdge::Left: @@ -132,8 +132,8 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect& p2_step = style.border_bottom().width / (float)int_width; for (int i = 0; i < int_width; ++i) { draw_line(p1, p2); - p1.move_by(1, p1_step); - p2.move_by(1, -p2_step); + p1.translate_by(1, p1_step); + p2.translate_by(1, -p2_step); } break; } diff --git a/Userland/Services/Taskbar/TaskbarButton.cpp b/Userland/Services/Taskbar/TaskbarButton.cpp index ec5f925023..22143a2458 100644 --- a/Userland/Services/Taskbar/TaskbarButton.cpp +++ b/Userland/Services/Taskbar/TaskbarButton.cpp @@ -80,7 +80,7 @@ static void paint_custom_progressbar(GUI::Painter& painter, const Gfx::IntRect& } Gfx::IntRect hole_rect { (int)progress_width, 0, (int)(rect.width() - progress_width), rect.height() }; - hole_rect.move_by(rect.location()); + hole_rect.translate_by(rect.location()); hole_rect.set_right_without_resize(rect.right()); Gfx::PainterStateSaver saver(painter); painter.add_clip_rect(hole_rect); @@ -109,7 +109,7 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event) icon_location.set_x(content_rect.x()); if (!text().is_empty()) { - content_rect.move_by(icon.width() + 4, 0); + content_rect.translate_by(icon.width() + 4, 0); content_rect.set_width(content_rect.width() - icon.width() - 4); } @@ -119,8 +119,8 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event) text_rect.align_within(content_rect, text_alignment()); if (is_being_pressed() || is_checked()) { - text_rect.move_by(1, 1); - icon_location.move_by(1, 1); + text_rect.translate_by(1, 1); + icon_location.translate_by(1, 1); } if (window.progress().has_value()) { diff --git a/Userland/Services/WindowServer/Compositor.cpp b/Userland/Services/WindowServer/Compositor.cpp index b28e1288ce..dca1002d3f 100644 --- a/Userland/Services/WindowServer/Compositor.cpp +++ b/Userland/Services/WindowServer/Compositor.cpp @@ -138,7 +138,7 @@ void Compositor::compose() auto invalidate_rect = dirty_rect.intersected(frame_rect); if (!invalidate_rect.is_empty()) { auto inner_rect_offset = window.rect().location() - frame_rect.location(); - invalidate_rect.move_by(-(frame_rect.location() + inner_rect_offset)); + invalidate_rect.translate_by(-(frame_rect.location() + inner_rect_offset)); window.invalidate_no_notify(invalidate_rect); m_invalidated_window = true; } @@ -449,7 +449,7 @@ void Compositor::compose() if (!wm.dnd_text().is_empty()) { auto text_rect = dnd_rect; if (wm.dnd_bitmap()) - text_rect.move_by(wm.dnd_bitmap()->width() + 8, 0); + text_rect.translate_by(wm.dnd_bitmap()->width() + 8, 0); back_painter.draw_text(text_rect, wm.dnd_text(), Gfx::TextAlignment::CenterLeft, wm.palette().selection_text()); } if (wm.dnd_bitmap()) { diff --git a/Userland/Services/WindowServer/Menu.cpp b/Userland/Services/WindowServer/Menu.cpp index 01a938fd5f..3b05d96e08 100644 --- a/Userland/Services/WindowServer/Menu.cpp +++ b/Userland/Services/WindowServer/Menu.cpp @@ -133,7 +133,7 @@ Window& Menu::ensure_menu_window() else if (item.type() == MenuItem::Separator) height = 8; item.set_rect({ next_item_location, { width - frame_thickness() * 2, height } }); - next_item_location.move_by(0, height); + next_item_location.translate_by(0, height); } int window_height_available = Screen::the().height() - frame_thickness() * 2; @@ -236,7 +236,7 @@ void Menu::draw() painter.blit_filtered(icon_rect.location().translated(1, 1), *item.icon(), item.icon()->rect(), [&shadow_color](auto) { return shadow_color; }); - icon_rect.move_by(-1, -1); + icon_rect.translate_by(-1, -1); } if (item.is_enabled()) painter.blit(icon_rect.location(), *item.icon(), item.icon()->rect()); diff --git a/Userland/Services/WindowServer/Screen.cpp b/Userland/Services/WindowServer/Screen.cpp index 381581f5fd..bc94fa5a7f 100644 --- a/Userland/Services/WindowServer/Screen.cpp +++ b/Userland/Services/WindowServer/Screen.cpp @@ -123,7 +123,7 @@ void Screen::on_receive_mouse_data(const MousePacket& packet) { auto prev_location = m_physical_cursor_location / m_scale_factor; if (packet.is_relative) { - m_physical_cursor_location.move_by(packet.x * m_acceleration_factor, packet.y * m_acceleration_factor); + m_physical_cursor_location.translate_by(packet.x * m_acceleration_factor, packet.y * m_acceleration_factor); dbgln_if(WSSCREEN_DEBUG, "Screen: New Relative mouse point @ {}", m_physical_cursor_location); } else { m_physical_cursor_location = { packet.x * physical_width() / 0xffff, packet.y * physical_height() / 0xffff }; diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index 8ffc784d5e..c1e9c9dd7d 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -541,7 +541,7 @@ bool Window::invalidate_no_notify(const Gfx::IntRect& rect, bool with_frame) auto outer_rect = frame().render_rect(); auto inner_rect = rect; - inner_rect.move_by(position()); + inner_rect.translate_by(position()); // FIXME: This seems slightly wrong; the inner rect shouldn't intersect the border part of the outer rect. inner_rect.intersect(outer_rect); if (inner_rect.is_empty()) @@ -976,7 +976,7 @@ void Window::set_menubar(Menubar* menubar) m_menubar->for_each_menu([&](Menu& menu) { int text_width = wm.font().width(Gfx::parse_ampersand_string(menu.name())); menu.set_rect_in_window_menubar({ next_menu_location.x(), 0, text_width + menubar_menu_margin, menubar_rect.height() }); - next_menu_location.move_by(menu.rect_in_window_menubar().width(), 0); + next_menu_location.translate_by(menu.rect_in_window_menubar().width(), 0); return IterationDecision::Continue; }); } diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index 167890fef2..67ee92d342 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -301,7 +301,7 @@ void WindowFrame::paint_menubar(Gfx::Painter& painter) auto text_rect = menu.rect_in_window_menubar(); Color text_color = palette.window_text(); if (MenuManager::the().is_open(menu)) - text_rect.move_by(1, 1); + text_rect.translate_by(1, 1); bool paint_as_pressed = MenuManager::the().is_open(menu); bool paint_as_hovered = !paint_as_pressed && &menu == MenuManager::the().hovered_menu(); if (paint_as_pressed || paint_as_hovered) { @@ -546,7 +546,7 @@ void WindowFrame::invalidate(Gfx::IntRect relative_rect) { auto frame_rect = rect(); auto window_rect = m_window.rect(); - relative_rect.move_by(frame_rect.x() - window_rect.x(), frame_rect.y() - window_rect.y()); + relative_rect.translate_by(frame_rect.x() - window_rect.x(), frame_rect.y() - window_rect.y()); m_dirty = true; m_window.invalidate(relative_rect, true); } |