Skip to content

Reformat Transform(2D) matrix display in the inspector

Aaron Franke requested to merge github/fork/aaronfranke/transform-editor into master

Previously the Transform editors in the inspector were a bit of a mess. Columns were displayed horizontally, rows displayed vertically, there was repeated information, updating the "Transform" values didn't update the "Matrix" values, and labels were non-unique.

This PR fixes all* of these problems, and fixes #10574 (closed) (and everything in my comment there). Here are some before and after screenshots, the left side is before, the right side is after:

spatial

The "Matrix" section has been renamed to "Raw Matrix" to better convey that this is how Godot works under-the-hood, and to slightly discourage users who don't know what it is from touching it. Editing the matrix of a transform directly is something users should know how it works before jumping in, or else they will get confused.

The items have been transposed to display columns vertically and rows horizontally (as it should be), except that the origin vector is not displayed, instead, only the Basis is displayed. This is because we don't need to duplicate information already present in "Transform" -> "Translation".

The names are such that "x.y" is equivalent to transform.basis.x.y, etc, meaning that the column is the left letter and the row is the right letter. This is much better than the previous ambiguous, repeated, non-unique "x", "y", and "z".

node2d

Previously, the transform matrix was not displayed at all for Node2D. The display now exists, and closely resembles the section for Spatial.

This is where the asterisk next to "all" comes in. Because there is no standalone "Basis2D" type, we have to display the entire Transform2D (unless there's some workaround I'm not aware of), so we still end up with some duplicated information (o.x/o.y and Position), but IMO it's better than not displaying the matrix at all for users who want to manipulate it. Figured out a way to hide it.

all

This is how they look as exported script variables. Transform2D and Basis look like the above. Transform, when exported by itself, should indeed show the origin, so it's a 4th column, as it should be. I decided to color it Cyan, rather than leave it gray, which I think looks better. This Cyan color also replaces gray in Quat and Plane (but of course we can change this back if desired).

Coloring is now done by a helper method in editor/editor_inspector.cpp. I also made everything else use these helpers methods, which helps avoid code duplication (and also, while I haven't benchmarked it, I'm fairly confident this will run faster since it's not re-calculating the same colors multiple times anywhere that uses the colors multiple times). There are three of these methods, since some things only need XY, some need XYZ, and some need four colors.

Merge request reports