From 21222fb478bc510a6c3ec49ef8f6b453ad8892f0 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 6 Sep 2019 16:04:07 +0200 Subject: [PATCH] Make editor inspector easing lines use the accent color when dragged This makes their visual feedback more consistent with other controls. This also makes easing lines slightly more subtle by decreasing their opacity by 10%. --- editor/editor_properties.cpp | 53 ++++++++++++++++++++++++++---------- editor/editor_properties.h | 1 + 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 30fb561fbe1..f456cf72330 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -922,16 +922,29 @@ EditorPropertyFloat::EditorPropertyFloat() { void EditorPropertyEasing::_drag_easing(const Ref &p_ev) { - Ref mb = p_ev; - if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) { - preset->set_global_position(easing_draw->get_global_transform().xform(mb->get_position())); - preset->popup(); - } - if (mb.is_valid() && mb->is_doubleclick() && mb->get_button_index() == BUTTON_LEFT) { - _setup_spin(); + const Ref mb = p_ev; + if (mb.is_valid()) { + if (mb->is_doubleclick() && mb->get_button_index() == BUTTON_LEFT) { + _setup_spin(); + } + + if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) { + preset->set_global_position(easing_draw->get_global_transform().xform(mb->get_position())); + preset->popup(); + + // Ensure the easing doesn't appear as being dragged + dragging = false; + easing_draw->update(); + } + + if (mb->get_button_index() == BUTTON_LEFT) { + dragging = mb->is_pressed(); + // Update to display the correct dragging color + easing_draw->update(); + } } - Ref mm = p_ev; + const Ref mm = p_ev; if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) { @@ -969,13 +982,19 @@ void EditorPropertyEasing::_draw_easing() { Rect2 r(Point2(), s); r = r.grow(3); - int points = 48; + const int points = 48; float prev = 1.0; - float exp = get_edited_object()->get(get_edited_property()); + const float exp = get_edited_object()->get(get_edited_property()); - Ref f = get_font("font", "Label"); - Color color = get_color("font_color", "Label"); + const Ref f = get_font("font", "Label"); + const Color font_color = get_color("font_color", "Label"); + Color line_color; + if (dragging) { + line_color = get_color("accent_color", "Editor"); + } else { + line_color = get_color("font_color", "Label") * Color(1, 1, 1, 0.9); + } Vector lines; for (int i = 1; i <= points; i++) { @@ -983,7 +1002,7 @@ void EditorPropertyEasing::_draw_easing() { float ifl = i / float(points); float iflp = (i - 1) / float(points); - float h = 1.0 - Math::ease(ifl, exp); + const float h = 1.0 - Math::ease(ifl, exp); if (flip) { ifl = 1.0 - ifl; @@ -995,8 +1014,8 @@ void EditorPropertyEasing::_draw_easing() { prev = h; } - easing_draw->draw_multiline(lines, color, 1.0, true); - f->draw(ci, Point2(10, 10 + f->get_ascent()), String::num(exp, 2), color); + easing_draw->draw_multiline(lines, line_color, 1.0, true); + f->draw(ci, Point2(10, 10 + f->get_ascent()), String::num(exp, 2), font_color); } void EditorPropertyEasing::update_property() { @@ -1033,6 +1052,9 @@ void EditorPropertyEasing::_spin_value_changed(double p_value) { void EditorPropertyEasing::_spin_focus_exited() { spin->hide(); + // Ensure the easing doesn't appear as being dragged + dragging = false; + easing_draw->update(); } void EditorPropertyEasing::setup(bool p_full, bool p_flip) { @@ -1095,6 +1117,7 @@ EditorPropertyEasing::EditorPropertyEasing() { spin->hide(); add_child(spin); + dragging = false; flip = false; full = false; } diff --git a/editor/editor_properties.h b/editor/editor_properties.h index adf7779dc4e..b8d6aa00c2a 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -311,6 +311,7 @@ class EditorPropertyEasing : public EditorProperty { EditorSpinSlider *spin; bool setting; + bool dragging; bool full; bool flip;