diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_properties.cpp | 92 | ||||
-rw-r--r-- | editor/editor_properties.h | 9 | ||||
-rw-r--r-- | editor/editor_spin_slider.cpp | 39 | ||||
-rw-r--r-- | editor/editor_spin_slider.h | 5 |
4 files changed, 136 insertions, 9 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index b66c1f6400..f6d67e1b44 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -969,6 +969,18 @@ void EditorPropertyVector2::update_property() { setting = false; } +void EditorPropertyVector2::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 2; i++) { + + Color c = base; + 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); + } + } +} + void EditorPropertyVector2::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector2::_value_changed); @@ -1022,7 +1034,17 @@ void EditorPropertyRect2::update_property() { spin[3]->set_value(val.size.y); setting = false; } +void EditorPropertyRect2::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 4; i++) { + Color c = base; + 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); + } + } +} void EditorPropertyRect2::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyRect2::_value_changed); @@ -1074,7 +1096,17 @@ void EditorPropertyVector3::update_property() { spin[2]->set_value(val.z); setting = false; } +void EditorPropertyVector3::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 3; i++) { + Color c = base; + 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); + } + } +} void EditorPropertyVector3::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector3::_value_changed); @@ -1128,7 +1160,17 @@ void EditorPropertyPlane::update_property() { spin[3]->set_value(val.d); setting = false; } +void EditorPropertyPlane::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 3; i++) { + Color c = base; + 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); + } + } +} void EditorPropertyPlane::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyPlane::_value_changed); @@ -1182,7 +1224,17 @@ void EditorPropertyQuat::update_property() { spin[3]->set_value(val.w); setting = false; } +void EditorPropertyQuat::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 3; i++) { + Color c = base; + 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); + } + } +} void EditorPropertyQuat::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyQuat::_value_changed); @@ -1243,7 +1295,17 @@ void EditorPropertyAABB::update_property() { setting = false; } +void EditorPropertyAABB::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 6; i++) { + Color c = base; + 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); + } + } +} void EditorPropertyAABB::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyAABB::_value_changed); @@ -1307,7 +1369,17 @@ void EditorPropertyTransform2D::update_property() { setting = false; } +void EditorPropertyTransform2D::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 6; i++) { + Color c = base; + 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); + } + } +} void EditorPropertyTransform2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyTransform2D::_value_changed); @@ -1376,7 +1448,17 @@ void EditorPropertyBasis::update_property() { setting = false; } +void EditorPropertyBasis::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 9; i++) { + Color c = base; + 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); + } + } +} void EditorPropertyBasis::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyBasis::_value_changed); @@ -1451,7 +1533,17 @@ void EditorPropertyTransform::update_property() { setting = false; } +void EditorPropertyTransform::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 12; i++) { + Color c = base; + 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); + } + } +} void EditorPropertyTransform::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyTransform::_value_changed); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 7c187d8036..0afb1bf955 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -315,6 +315,7 @@ class EditorPropertyVector2 : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -330,6 +331,7 @@ class EditorPropertyRect2 : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -345,6 +347,7 @@ class EditorPropertyVector3 : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -360,6 +363,7 @@ class EditorPropertyPlane : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -375,6 +379,7 @@ class EditorPropertyQuat : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -390,6 +395,7 @@ class EditorPropertyAABB : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -405,6 +411,7 @@ class EditorPropertyTransform2D : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -420,6 +427,7 @@ class EditorPropertyBasis : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -435,6 +443,7 @@ class EditorPropertyTransform : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index d0eef72382..79023a1f28 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -165,7 +165,8 @@ void EditorSpinSlider::_notification(int p_what) { draw_style_box(sb, Rect2(Vector2(), get_size())); } Ref<Font> font = get_font("font", "LineEdit"); - int sep = 4 * EDSCALE; + int sep_base = 4 * EDSCALE; + int sep = sep_base + sb->get_offset().x; //make it have the same margin on both sides, looks better int string_width = font->get_string_size(label).width; int number_width = get_size().width - sb->get_minimum_size().width - string_width - sep; @@ -176,18 +177,30 @@ void EditorSpinSlider::_notification(int p_what) { number_width -= updown->get_width(); } - if (has_focus()) { - Ref<StyleBox> focus = get_stylebox("focus", "LineEdit"); - draw_style_box(focus, Rect2(Vector2(), get_size())); - } - String numstr = get_text_value(); int vofs = (get_size().height - font->get_height()) / 2 + font->get_ascent(); Color fc = get_color("font_color", "LineEdit"); + Color lc; + if (use_custom_label_color) { + lc = custom_label_color; + } else { + lc = fc; + } + + if (flat && label != String()) { + Color label_bg_color = get_color("dark_color_3", "Editor"); + draw_rect(Rect2(Vector2(), Vector2(sb->get_offset().x * 2 + string_width, get_size().height)), label_bg_color); + } + + if (has_focus()) { + Ref<StyleBox> focus = get_stylebox("focus", "LineEdit"); + draw_style_box(focus, Rect2(Vector2(), get_size())); + } + + draw_string(font, Vector2(sb->get_offset().x, vofs), label, lc * Color(1, 1, 1, 0.5)); - draw_string(font, Vector2(sb->get_offset().x, vofs), label, fc * Color(1, 1, 1, 0.5)); draw_string(font, Vector2(sb->get_offset().x + string_width + sep, vofs), numstr, fc, number_width); if (get_step() == 1) { @@ -255,9 +268,11 @@ void EditorSpinSlider::_notification(int p_what) { update(); } if (p_what == NOTIFICATION_FOCUS_ENTER) { - if (!Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && !value_input_just_closed) { + /* Sorry, I dont like this, it makes navigating the different fields with arrows more difficult + * if (!Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && !value_input_just_closed) { _focus_entered(); - } + }*/ + value_input_just_closed = false; } } @@ -349,6 +364,11 @@ bool EditorSpinSlider::is_flat() const { return flat; } +void EditorSpinSlider::set_custom_label_color(bool p_use_custom_label_color, Color p_custom_label_color) { + use_custom_label_color = p_use_custom_label_color; + custom_label_color = p_custom_label_color; +} + void EditorSpinSlider::_focus_entered() { Rect2 gr = get_global_rect(); value_input->set_text(get_text_value()); @@ -415,4 +435,5 @@ EditorSpinSlider::EditorSpinSlider() { value_input_just_closed = false; hide_slider = false; read_only = false; + use_custom_label_color = false; } diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h index ad734c893c..fb32534ef4 100644 --- a/editor/editor_spin_slider.h +++ b/editor/editor_spin_slider.h @@ -70,6 +70,9 @@ class EditorSpinSlider : public Range { bool hide_slider; bool flat; + bool use_custom_label_color; + Color custom_label_color; + protected: void _notification(int p_what); void _gui_input(const Ref<InputEvent> &p_event); @@ -92,6 +95,8 @@ public: void set_flat(bool p_enable); bool is_flat() const; + void set_custom_label_color(bool p_use_custom_label_color, Color p_custom_label_color); + virtual Size2 get_minimum_size() const; EditorSpinSlider(); }; |