From 6b17d51425f9215aec42b3e5ea97630ea5c22543 Mon Sep 17 00:00:00 2001 From: Mark DiBarry Date: Sat, 29 Jun 2024 09:58:59 -0400 Subject: [PATCH] Add alternative pixel rounding --- scene/2d/animated_sprite_2d.cpp | 2 +- scene/2d/sprite_2d.cpp | 4 ++-- scene/gui/rich_text_label.cpp | 2 +- servers/rendering/renderer_canvas_cull.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index 3506a0df2b2..b3f735e0440 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -267,7 +267,7 @@ void AnimatedSprite2D::_notification(int p_what) { } if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { - ofs = ofs.round(); + ofs = (ofs + Point2(0.5, 0.5)).floor(); } Rect2 dst_rect(ofs, s); diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp index efb5029ac47..2b5c40f212f 100644 --- a/scene/2d/sprite_2d.cpp +++ b/scene/2d/sprite_2d.cpp @@ -98,7 +98,7 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c } if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { - dest_offset = dest_offset.round(); + dest_offset = (dest_offset + Point2(0.5, 0.5)).floor(); } r_dst_rect = Rect2(dest_offset, frame_size); @@ -400,7 +400,7 @@ Rect2 Sprite2D::get_rect() const { } if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { - ofs = ofs.round(); + ofs = (ofs + Point2(0.5, 0.5)).floor(); } if (s == Size2(0, 0)) { diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 416a7fafb6a..8ffa0f8c631 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1249,7 +1249,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o } if (is_inside_tree() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { - fx_offset = fx_offset.round(); + fx_offset = (fx_offset + Point2(0.5, 0.5)).floor(); } Vector2 char_off = char_xform.get_origin(); diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp index e92050a3236..c4286dcc0c6 100644 --- a/servers/rendering/renderer_canvas_cull.cpp +++ b/servers/rendering/renderer_canvas_cull.cpp @@ -284,8 +284,8 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2 } if (snapping_2d_transforms_to_pixel) { - final_xform.columns[2] = final_xform.columns[2].round(); - parent_xform.columns[2] = parent_xform.columns[2].round(); + 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(); } final_xform = parent_xform * final_xform;