Ported: Include the follow-viewport-transform into CanvasLayer transform calculations

The follow-viewport-transform was missing from several calculations
3.x version of #59682
- Sauermann
608cbd8296
This commit is contained in:
Relintai 2022-12-22 19:06:10 +01:00
parent eb219dbfb4
commit ce5e82d910
6 changed files with 27 additions and 7 deletions

View File

@ -289,7 +289,7 @@
<method name="get_canvas_transform" qualifiers="const">
<return type="Transform2D" />
<description>
Returns the transform matrix of this item's canvas.
Returns the transform from the coordinate system of the canvas, this item is in, to the [Viewport]s coordinate system.
</description>
</method>
<method name="get_global_mouse_position" qualifiers="const">
@ -307,7 +307,7 @@
<method name="get_global_transform_with_canvas" qualifiers="const">
<return type="Transform2D" />
<description>
Returns the global transform matrix of this item in relation to the canvas.
Returns the transform from the local coordinate system of this [CanvasItem] to the [Viewport]s coordinate system.
</description>
</method>
<method name="get_local_mouse_position" qualifiers="const">
@ -331,7 +331,7 @@
<method name="get_viewport_transform" qualifiers="const">
<return type="Transform2D" />
<description>
Returns this item's transform in relation to the viewport.
Returns the transform from the coordinate system of the canvas, this item is in, to the [Viewport]s embedders coordinate system.
</description>
</method>
<method name="get_world_2d" qualifiers="const">

View File

@ -18,6 +18,12 @@
Returns the RID of the canvas used by this layer.
</description>
</method>
<method name="get_final_transform" qualifiers="const">
<return type="Transform2D" />
<description>
Returns the transform from the [CanvasLayer]s coordinate system to the [Viewport]s coordinate system.
</description>
</method>
<method name="hide">
<return type="void" />
<description>

View File

@ -473,7 +473,7 @@ void CanvasItem::_update_callback() {
Transform2D CanvasItem::get_global_transform_with_canvas() const {
if (canvas_layer) {
return canvas_layer->get_transform() * get_global_transform();
return canvas_layer->get_final_transform() * get_global_transform();
} else if (is_inside_tree()) {
return get_world()->get_canvas_transform() * get_global_transform();
} else {
@ -1230,9 +1230,9 @@ Transform2D CanvasItem::get_viewport_transform() const {
if (canvas_layer) {
if (get_world()) {
return get_world()->get_final_transform() * canvas_layer->get_transform();
return get_world()->get_final_transform() * canvas_layer->get_final_transform();
} else {
return canvas_layer->get_transform();
return canvas_layer->get_final_transform();
}
} else {

View File

@ -80,6 +80,18 @@ void CanvasLayer::set_transform(const Transform2D &p_xform) {
}
}
Transform2D CanvasLayer::get_final_transform() const {
if (is_following_viewport()) {
Transform2D follow;
follow.scale(Vector2(get_follow_viewport_scale(), get_follow_viewport_scale()));
if (vp) {
follow = vp->get_canvas_transform() * follow;
}
return follow * transform;
}
return transform;
}
Transform2D CanvasLayer::get_transform() const {
return transform;
}
@ -302,6 +314,7 @@ void CanvasLayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_transform", "transform"), &CanvasLayer::set_transform);
ClassDB::bind_method(D_METHOD("get_transform"), &CanvasLayer::get_transform);
ClassDB::bind_method(D_METHOD("get_final_transform"), &CanvasLayer::get_final_transform);
ClassDB::bind_method(D_METHOD("set_offset", "offset"), &CanvasLayer::set_offset);
ClassDB::bind_method(D_METHOD("get_offset"), &CanvasLayer::get_offset);

View File

@ -76,6 +76,7 @@ public:
void set_transform(const Transform2D &p_xform);
Transform2D get_transform() const;
Transform2D get_final_transform() const;
void set_offset(const Vector2 &p_offset);
Vector2 get_offset() const;

View File

@ -537,7 +537,7 @@ void Viewport::_process_picking(bool p_ignore_paused) {
ObjectID canvas_layer_id;
if (E->get()) {
// A descendant CanvasLayer
canvas_transform = E->get()->get_transform();
canvas_transform = E->get()->get_final_transform();
canvas_layer_id = E->get()->get_instance_id();
} else {
// This Viewport's builtin canvas