diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-03-19 11:35:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-19 11:35:14 +0100 |
commit | af0b7f90bcdf1fca334932be2888d30aaef7bb75 (patch) | |
tree | 1b888a4726fbb156922d3eab97250cb3ffdc573f | |
parent | 3b1c04550f9341856b1e94cda05a50eaebb3d35e (diff) | |
parent | 1c02906a6fa7ca1224345fe3ae19ab9879165a0a (diff) |
Merge pull request #37151 from nodj/fix_unstable_high_zoom
Editor 2D: Change pixel alignment strategy, fix jittering in high zoom
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 6e1166bb37..9f66672f4a 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -4306,10 +4306,20 @@ void CanvasItemEditor::_zoom_on_position(float p_zoom, Point2 p_position) { float prev_zoom = zoom; zoom = p_zoom; - Point2 ofs = p_position; - ofs = ofs / prev_zoom - ofs / zoom; - view_offset.x = Math::round(view_offset.x + ofs.x); - view_offset.y = Math::round(view_offset.y + ofs.y); + + view_offset += p_position / prev_zoom - p_position / zoom; + + // We want to align in-scene pixels to screen pixels, this prevents blurry rendering + // in small details (texts, lines). + // This correction adds a jitter movement when zooming, so we correct only when the + // zoom factor is an integer. (in the other cases, all pixels won't be aligned anyway) + float closest_zoom_factor = Math::round(zoom); + if (Math::is_zero_approx(zoom - closest_zoom_factor)) { + // make sure scene pixel at view_offset is aligned on a screen pixel + Vector2 view_offset_int = view_offset.floor(); + Vector2 view_offset_frac = view_offset - view_offset_int; + view_offset = view_offset_int + (view_offset_frac * closest_zoom_factor).round() / closest_zoom_factor; + } _update_zoom_label(); update_viewport(); |