1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Merge pull request #32068 from aaronfranke/transform-editor

Reformat Transform(2D) matrix display in the inspector
This commit is contained in:
Rémi Verschelde
2021-09-15 13:06:25 +02:00
committed by GitHub
4 changed files with 95 additions and 99 deletions

View File

@@ -815,6 +815,19 @@ void EditorProperty::unhandled_key_input(const Ref<InputEvent> &p_event) {
} }
} }
const Color *EditorProperty::_get_property_colors() {
const Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
const float saturation = base.get_s() * 0.75;
const float value = base.get_v();
static Color c[4];
c[0].set_hsv(0.0 / 3.0 + 0.05, saturation, value);
c[1].set_hsv(1.0 / 3.0 + 0.05, saturation, value);
c[2].set_hsv(2.0 / 3.0 + 0.05, saturation, value);
c[3].set_hsv(1.5 / 3.0 + 0.05, saturation, value);
return c;
}
void EditorProperty::set_label_reference(Control *p_control) { void EditorProperty::set_label_reference(Control *p_control) {
label_reference = p_control; label_reference = p_control;
} }

View File

@@ -123,6 +123,7 @@ protected:
virtual void gui_input(const Ref<InputEvent> &p_event) override; virtual void gui_input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override; virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
const Color *_get_property_colors();
public: public:
void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false); void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false);

View File

@@ -1510,11 +1510,9 @@ void EditorPropertyVector2::update_property() {
void EditorPropertyVector2::_notification(int p_what) { void EditorPropertyVector2::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i]);
c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -1603,11 +1601,9 @@ void EditorPropertyRect2::update_property() {
void EditorPropertyRect2::_notification(int p_what) { void EditorPropertyRect2::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i % 2]);
c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -1731,11 +1727,9 @@ Vector3 EditorPropertyVector3::get_vector() {
void EditorPropertyVector3::_notification(int p_what) { void EditorPropertyVector3::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i]);
c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -1820,11 +1814,9 @@ void EditorPropertyVector2i::update_property() {
void EditorPropertyVector2i::_notification(int p_what) { void EditorPropertyVector2i::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i]);
c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -1913,11 +1905,9 @@ void EditorPropertyRect2i::update_property() {
void EditorPropertyRect2i::_notification(int p_what) { void EditorPropertyRect2i::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i % 2]);
c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -2014,11 +2004,9 @@ void EditorPropertyVector3i::update_property() {
void EditorPropertyVector3i::_notification(int p_what) { void EditorPropertyVector3i::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i]);
c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -2106,11 +2094,9 @@ void EditorPropertyPlane::update_property() {
void EditorPropertyPlane::_notification(int p_what) { void EditorPropertyPlane::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 4; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i]);
c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -2199,11 +2185,9 @@ void EditorPropertyQuaternion::update_property() {
void EditorPropertyQuaternion::_notification(int p_what) { void EditorPropertyQuaternion::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 4; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i]);
c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -2295,11 +2279,9 @@ void EditorPropertyAABB::update_property() {
void EditorPropertyAABB::_notification(int p_what) { void EditorPropertyAABB::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i % 3]);
c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -2354,10 +2336,10 @@ void EditorPropertyTransform2D::_value_changed(double val, const String &p_name)
Transform2D p; Transform2D p;
p[0][0] = spin[0]->get_value(); p[0][0] = spin[0]->get_value();
p[0][1] = spin[1]->get_value(); p[1][0] = spin[1]->get_value();
p[1][0] = spin[2]->get_value(); p[2][0] = spin[2]->get_value();
p[1][1] = spin[3]->get_value(); p[0][1] = spin[3]->get_value();
p[2][0] = spin[4]->get_value(); p[1][1] = spin[4]->get_value();
p[2][1] = spin[5]->get_value(); p[2][1] = spin[5]->get_value();
emit_changed(get_edited_property(), p, p_name); emit_changed(get_edited_property(), p, p_name);
@@ -2367,10 +2349,10 @@ void EditorPropertyTransform2D::update_property() {
Transform2D val = get_edited_object()->get(get_edited_property()); Transform2D val = get_edited_object()->get(get_edited_property());
setting = true; setting = true;
spin[0]->set_value(val[0][0]); spin[0]->set_value(val[0][0]);
spin[1]->set_value(val[0][1]); spin[1]->set_value(val[1][0]);
spin[2]->set_value(val[1][0]); spin[2]->set_value(val[2][0]);
spin[3]->set_value(val[1][1]); spin[3]->set_value(val[0][1]);
spin[4]->set_value(val[2][0]); spin[4]->set_value(val[1][1]);
spin[5]->set_value(val[2][1]); spin[5]->set_value(val[2][1]);
setting = false; setting = false;
@@ -2378,11 +2360,14 @@ void EditorPropertyTransform2D::update_property() {
void EditorPropertyTransform2D::_notification(int p_what) { void EditorPropertyTransform2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
Color c = base; // For Transform2D, use the 4th color (cyan) for the origin vector.
c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); if (i % 3 == 2) {
spin[i]->set_custom_label_color(true, c); spin[i]->set_custom_label_color(true, colors[3]);
} else {
spin[i]->set_custom_label_color(true, colors[i % 3]);
}
} }
} }
} }
@@ -2402,17 +2387,19 @@ void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step,
} }
} }
EditorPropertyTransform2D::EditorPropertyTransform2D() { EditorPropertyTransform2D::EditorPropertyTransform2D(bool p_include_origin) {
GridContainer *g = memnew(GridContainer); GridContainer *g = memnew(GridContainer);
g->set_columns(2); g->set_columns(p_include_origin ? 3 : 2);
add_child(g); add_child(g);
static const char *desc[6] = { "x", "y", "x", "y", "x", "y" }; static const char *desc[6] = { "xx", "xy", "xo", "yx", "yy", "yo" };
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
spin[i] = memnew(EditorSpinSlider); spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]); spin[i]->set_label(desc[i]);
spin[i]->set_flat(true); spin[i]->set_flat(true);
if (p_include_origin || i % 3 != 2) {
g->add_child(spin[i]); g->add_child(spin[i]);
}
spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
add_focusable(spin[i]); add_focusable(spin[i]);
spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyTransform2D::_value_changed), varray(desc[i])); spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyTransform2D::_value_changed), varray(desc[i]));
@@ -2436,13 +2423,13 @@ void EditorPropertyBasis::_value_changed(double val, const String &p_name) {
Basis p; Basis p;
p[0][0] = spin[0]->get_value(); p[0][0] = spin[0]->get_value();
p[1][0] = spin[1]->get_value(); p[0][1] = spin[1]->get_value();
p[2][0] = spin[2]->get_value(); p[0][2] = spin[2]->get_value();
p[0][1] = spin[3]->get_value(); p[1][0] = spin[3]->get_value();
p[1][1] = spin[4]->get_value(); p[1][1] = spin[4]->get_value();
p[2][1] = spin[5]->get_value(); p[1][2] = spin[5]->get_value();
p[0][2] = spin[6]->get_value(); p[2][0] = spin[6]->get_value();
p[1][2] = spin[7]->get_value(); p[2][1] = spin[7]->get_value();
p[2][2] = spin[8]->get_value(); p[2][2] = spin[8]->get_value();
emit_changed(get_edited_property(), p, p_name); emit_changed(get_edited_property(), p, p_name);
@@ -2452,13 +2439,13 @@ void EditorPropertyBasis::update_property() {
Basis val = get_edited_object()->get(get_edited_property()); Basis val = get_edited_object()->get(get_edited_property());
setting = true; setting = true;
spin[0]->set_value(val[0][0]); spin[0]->set_value(val[0][0]);
spin[1]->set_value(val[1][0]); spin[1]->set_value(val[0][1]);
spin[2]->set_value(val[2][0]); spin[2]->set_value(val[0][2]);
spin[3]->set_value(val[0][1]); spin[3]->set_value(val[1][0]);
spin[4]->set_value(val[1][1]); spin[4]->set_value(val[1][1]);
spin[5]->set_value(val[2][1]); spin[5]->set_value(val[1][2]);
spin[6]->set_value(val[0][2]); spin[6]->set_value(val[2][0]);
spin[7]->set_value(val[1][2]); spin[7]->set_value(val[2][1]);
spin[8]->set_value(val[2][2]); spin[8]->set_value(val[2][2]);
setting = false; setting = false;
@@ -2466,11 +2453,9 @@ void EditorPropertyBasis::update_property() {
void EditorPropertyBasis::_notification(int p_what) { void EditorPropertyBasis::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i % 3]);
c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -2495,7 +2480,7 @@ EditorPropertyBasis::EditorPropertyBasis() {
g->set_columns(3); g->set_columns(3);
add_child(g); add_child(g);
static const char *desc[9] = { "x", "y", "z", "x", "y", "z", "x", "y", "z" }; static const char *desc[9] = { "xx", "xy", "xz", "yx", "yy", "yz", "zx", "zy", "zz" };
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
spin[i] = memnew(EditorSpinSlider); spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]); spin[i]->set_label(desc[i]);
@@ -2524,16 +2509,16 @@ void EditorPropertyTransform3D::_value_changed(double val, const String &p_name)
Transform3D p; Transform3D p;
p.basis[0][0] = spin[0]->get_value(); p.basis[0][0] = spin[0]->get_value();
p.basis[1][0] = spin[1]->get_value(); p.basis[0][1] = spin[1]->get_value();
p.basis[2][0] = spin[2]->get_value(); p.basis[0][2] = spin[2]->get_value();
p.basis[0][1] = spin[3]->get_value(); p.origin[0] = spin[3]->get_value();
p.basis[1][1] = spin[4]->get_value(); p.basis[1][0] = spin[4]->get_value();
p.basis[2][1] = spin[5]->get_value(); p.basis[1][1] = spin[5]->get_value();
p.basis[0][2] = spin[6]->get_value(); p.basis[1][2] = spin[6]->get_value();
p.basis[1][2] = spin[7]->get_value(); p.origin[1] = spin[7]->get_value();
p.basis[2][2] = spin[8]->get_value(); p.basis[2][0] = spin[8]->get_value();
p.origin[0] = spin[9]->get_value(); p.basis[2][1] = spin[9]->get_value();
p.origin[1] = spin[10]->get_value(); p.basis[2][2] = spin[10]->get_value();
p.origin[2] = spin[11]->get_value(); p.origin[2] = spin[11]->get_value();
emit_changed(get_edited_property(), p, p_name); emit_changed(get_edited_property(), p, p_name);
@@ -2546,27 +2531,25 @@ void EditorPropertyTransform3D::update_property() {
void EditorPropertyTransform3D::update_using_transform(Transform3D p_transform) { void EditorPropertyTransform3D::update_using_transform(Transform3D p_transform) {
setting = true; setting = true;
spin[0]->set_value(p_transform.basis[0][0]); spin[0]->set_value(p_transform.basis[0][0]);
spin[1]->set_value(p_transform.basis[1][0]); spin[1]->set_value(p_transform.basis[0][1]);
spin[2]->set_value(p_transform.basis[2][0]); spin[2]->set_value(p_transform.basis[0][2]);
spin[3]->set_value(p_transform.basis[0][1]); spin[3]->set_value(p_transform.origin[0]);
spin[4]->set_value(p_transform.basis[1][1]); spin[4]->set_value(p_transform.basis[1][0]);
spin[5]->set_value(p_transform.basis[2][1]); spin[5]->set_value(p_transform.basis[1][1]);
spin[6]->set_value(p_transform.basis[0][2]); spin[6]->set_value(p_transform.basis[1][2]);
spin[7]->set_value(p_transform.basis[1][2]); spin[7]->set_value(p_transform.origin[1]);
spin[8]->set_value(p_transform.basis[2][2]); spin[8]->set_value(p_transform.basis[2][0]);
spin[9]->set_value(p_transform.origin[0]); spin[9]->set_value(p_transform.basis[2][1]);
spin[10]->set_value(p_transform.origin[1]); spin[10]->set_value(p_transform.basis[2][2]);
spin[11]->set_value(p_transform.origin[2]); spin[11]->set_value(p_transform.origin[2]);
setting = false; setting = false;
} }
void EditorPropertyTransform3D::_notification(int p_what) { void EditorPropertyTransform3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
Color base = get_theme_color(SNAME("accent_color"), SNAME("Editor")); const Color *colors = _get_property_colors();
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
Color c = base; spin[i]->set_custom_label_color(true, colors[i % 4]);
c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
spin[i]->set_custom_label_color(true, c);
} }
} }
} }
@@ -2588,10 +2571,10 @@ void EditorPropertyTransform3D::setup(double p_min, double p_max, double p_step,
EditorPropertyTransform3D::EditorPropertyTransform3D() { EditorPropertyTransform3D::EditorPropertyTransform3D() {
GridContainer *g = memnew(GridContainer); GridContainer *g = memnew(GridContainer);
g->set_columns(3); g->set_columns(4);
add_child(g); add_child(g);
static const char *desc[12] = { "x", "y", "z", "x", "y", "z", "x", "y", "z", "x", "y", "z" }; static const char *desc[12] = { "xx", "xy", "xz", "xo", "yx", "yy", "yz", "yo", "zx", "zy", "zz", "zo" };
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
spin[i] = memnew(EditorSpinSlider); spin[i] = memnew(EditorSpinSlider);
spin[i]->set_label(desc[i]); spin[i]->set_label(desc[i]);
@@ -3448,7 +3431,6 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
return editor; return editor;
} break; } break;
case Variant::PLANE: { case Variant::PLANE: {
EditorPropertyPlane *editor = memnew(EditorPropertyPlane(p_wide)); EditorPropertyPlane *editor = memnew(EditorPropertyPlane(p_wide));

View File

@@ -554,7 +554,7 @@ protected:
public: public:
virtual void update_property() override; virtual void update_property() override;
void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String());
EditorPropertyTransform2D(); EditorPropertyTransform2D(bool p_include_origin = true);
}; };
class EditorPropertyBasis : public EditorProperty { class EditorPropertyBasis : public EditorProperty {