Merge pull request #43813 from lawnjelly/snap_2d_round

Change 2d transform snapping from floor to round
This commit is contained in:
Rémi Verschelde 2021-03-01 08:54:41 +01:00 committed by GitHub
commit 4fcd8483d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 5 deletions

View file

@ -453,6 +453,8 @@ void AnimatedSprite::_notification(int p_what) {
ofs -= s / 2;
if (Engine::get_singleton()->get_snap_2d_transforms()) {
ofs = ofs.round();
} else if (Engine::get_singleton()->get_use_pixel_snap()) {
ofs = ofs.floor();
}
Rect2 dst_rect(ofs, s);

View file

@ -99,7 +99,10 @@ void Sprite::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_cli
Point2 dest_offset = offset;
if (centered)
dest_offset -= frame_size / 2;
if (Engine::get_singleton()->get_use_pixel_snap()) {
if (Engine::get_singleton()->get_snap_2d_transforms()) {
dest_offset = dest_offset.round();
} else if (Engine::get_singleton()->get_use_pixel_snap()) {
dest_offset = dest_offset.floor();
}
@ -378,7 +381,9 @@ Rect2 Sprite::get_rect() const {
Point2 ofs = offset;
if (centered)
ofs -= Size2(s) / 2;
if (Engine::get_singleton()->get_use_pixel_snap()) {
if (Engine::get_singleton()->get_snap_2d_transforms()) {
ofs = ofs.round();
} else if (Engine::get_singleton()->get_use_pixel_snap()) {
ofs = ofs.floor();
}

View file

@ -100,7 +100,7 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor
Rect2 rect = ci->get_rect();
Transform2D xform = ci->xform;
if (snap_2d_transforms) {
xform.elements[2] = xform.elements[2].floor();
xform.elements[2] = xform.elements[2].round();
}
xform = p_transform * xform;

View file

@ -47,7 +47,7 @@ static Transform2D _canvas_get_transform(VisualServerViewport::Viewport *p_viewp
Transform2D c_xform = p_viewport->canvas_map[p_canvas->parent].transform;
if (snap) {
c_xform.elements[2] = c_xform.elements[2].floor();
c_xform.elements[2] = c_xform.elements[2].round();
}
xf = xf * c_xform;
scale = p_canvas->parent_scale;
@ -55,7 +55,7 @@ static Transform2D _canvas_get_transform(VisualServerViewport::Viewport *p_viewp
Transform2D c_xform = p_canvas_data->transform;
if (snap) {
c_xform.elements[2] = c_xform.elements[2].floor();
c_xform.elements[2] = c_xform.elements[2].round();
}
xf = xf * c_xform;