mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:17:44 +00:00
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.
This commit is contained in:
parent
ac238b3bd6
commit
88cfaf7bf0
48 changed files with 282 additions and 187 deletions
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue