Skip to content

Commit

Permalink
Update rect calculation (tmp commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleonc committed Aug 17, 2024
1 parent bde040c commit eed9669
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions servers/rendering/renderer_canvas_cull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,6 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2
ci->repeat_source_item = repeat_source_item;
}

if (repeat_size.x || repeat_size.y) {
Size2 scale = final_xform.get_scale();
rect.size += repeat_size * repeat_times / scale;
rect.position -= repeat_size / scale * (repeat_times / 2);
}

if (snapping_2d_transforms_to_pixel) {
final_xform.columns[2] = (final_xform.columns[2] + Point2(0.5, 0.5)).floor();
parent_xform.columns[2] = (parent_xform.columns[2] + Point2(0.5, 0.5)).floor();
Expand All @@ -298,6 +292,27 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2
final_xform = parent_xform * final_xform;

Rect2 global_rect = final_xform.xform(rect);
if (repeat_source_item && (repeat_size.x || repeat_size.y)) {
Size2 repeat_size_x_offset = repeat_source_item->final_transform.basis_xform(Size2(repeat_size.x, 0));
Size2 repeat_size_y_offset = repeat_source_item->final_transform.basis_xform(Size2(0, repeat_size.y));

// Top-left repeated rect.
Rect2 corner_rect = global_rect;
corner_rect.position -= (repeat_times / 2) * (repeat_size_x_offset + repeat_size_y_offset);
global_rect = corner_rect;

// Plus top-right repeated rect.
corner_rect.position += repeat_size_x_offset;
global_rect = global_rect.merge(corner_rect);

// Plus bottom-right repeated rect.
corner_rect.position += repeat_size_y_offset;
global_rect = global_rect.merge(corner_rect);

// Plus bottom-left repeated rect.
corner_rect.position -= repeat_size_x_offset;
global_rect = global_rect.merge(corner_rect);
}
global_rect.position += p_clip_rect.position;

if (ci->use_parent_material && p_material_owner) {
Expand Down

0 comments on commit eed9669

Please sign in to comment.