diff options
Diffstat (limited to 'editor/editor_spin_slider.cpp')
-rw-r--r-- | editor/editor_spin_slider.cpp | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 0ede0a3b7a..2c115c66cb 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -29,8 +29,9 @@ /*************************************************************************/ #include "editor_spin_slider.h" + +#include "core/input/input_filter.h" #include "core/math/expression.h" -#include "core/os/input.h" #include "editor_node.h" #include "editor_scale.h" @@ -67,7 +68,7 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { grabbing_spinner_dist_cache = 0; pre_grab_value = get_value(); grabbing_spinner = false; - grabbing_spinner_mouse_pos = Input::get_singleton()->get_mouse_position(); + grabbing_spinner_mouse_pos = InputFilter::get_singleton()->get_mouse_position(); } } else { @@ -75,8 +76,8 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { if (grabbing_spinner) { - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); - Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos); + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); + InputFilter::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos); update(); } else { _focus_entered(); @@ -105,7 +106,7 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { grabbing_spinner_dist_cache += diff_x; if (!grabbing_spinner && ABS(grabbing_spinner_dist_cache) > 4 * EDSCALE) { - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_CAPTURED); grabbing_spinner = true; } @@ -176,11 +177,11 @@ void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) { void EditorSpinSlider::_notification(int p_what) { - if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT || - p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN || + if (p_what == NOTIFICATION_WM_FOCUS_OUT || + p_what == NOTIFICATION_WM_FOCUS_IN || p_what == NOTIFICATION_EXIT_TREE) { if (grabbing_spinner) { - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); grabbing_spinner = false; grabbing_spinner_attempt = false; } @@ -191,30 +192,30 @@ void EditorSpinSlider::_notification(int p_what) { // when it's edited. The LineEdit "focus" stylebox uses the "normal" stylebox's // default margins. Ref<StyleBoxFlat> stylebox = - EditorNode::get_singleton()->get_theme_base()->get_stylebox("normal", "LineEdit")->duplicate(); + EditorNode::get_singleton()->get_theme_base()->get_theme_stylebox("normal", "LineEdit")->duplicate(); // EditorSpinSliders with a label have more space on the left, so add an // higher margin to match the location where the text begins. // The margin values below were determined by empirical testing. stylebox->set_default_margin(MARGIN_LEFT, (get_label() != String() ? 23 : 16) * EDSCALE); - value_input->add_style_override("normal", stylebox); + value_input->add_theme_style_override("normal", stylebox); } if (p_what == NOTIFICATION_DRAW) { updown_offset = -1; - Ref<StyleBox> sb = get_stylebox("normal", "LineEdit"); + Ref<StyleBox> sb = get_theme_stylebox("normal", "LineEdit"); if (!flat) { draw_style_box(sb, Rect2(Vector2(), get_size())); } - Ref<Font> font = get_font("font", "LineEdit"); + Ref<Font> font = get_theme_font("font", "LineEdit"); 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; - Ref<Texture2D> updown = get_icon("updown", "SpinBox"); + Ref<Texture2D> updown = get_theme_icon("updown", "SpinBox"); if (get_step() == 1) { number_width -= updown->get_width(); @@ -224,7 +225,7 @@ void EditorSpinSlider::_notification(int p_what) { int vofs = (get_size().height - font->get_height()) / 2 + font->get_ascent(); - Color fc = get_color("font_color", "LineEdit"); + Color fc = get_theme_color("font_color", "LineEdit"); Color lc; if (use_custom_label_color) { lc = custom_label_color; @@ -233,12 +234,12 @@ void EditorSpinSlider::_notification(int p_what) { } if (flat && label != String()) { - Color label_bg_color = get_color("dark_color_3", "Editor"); + Color label_bg_color = get_theme_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"); + Ref<StyleBox> focus = get_theme_stylebox("focus", "LineEdit"); draw_style_box(focus, Rect2(Vector2(), get_size())); } @@ -247,7 +248,7 @@ void EditorSpinSlider::_notification(int p_what) { draw_string(font, Vector2(Math::round(sb->get_offset().x + string_width + sep), vofs), numstr, fc, number_width); if (get_step() == 1) { - Ref<Texture2D> updown2 = get_icon("updown", "SpinBox"); + Ref<Texture2D> updown2 = get_theme_icon("updown", "SpinBox"); int updown_vofs = (get_size().height - updown2->get_height()) / 2; updown_offset = get_size().width - sb->get_margin(MARGIN_RIGHT) - updown2->get_width(); Color c(1, 1, 1); @@ -272,7 +273,7 @@ void EditorSpinSlider::_notification(int p_what) { Rect2 grabber_rect = Rect2(ofs + gofs, svofs + 1, grabber_w, 2 * EDSCALE); draw_rect(grabber_rect, c); - bool display_grabber = (mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !value_input->is_visible(); + bool display_grabber = (mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !value_input_popup->is_visible(); if (grabber->is_visible() != display_grabber) { if (display_grabber) { grabber->show(); @@ -284,9 +285,9 @@ void EditorSpinSlider::_notification(int p_what) { if (display_grabber) { Ref<Texture2D> grabber_tex; if (mouse_over_grabber) { - grabber_tex = get_icon("grabber_highlight", "HSlider"); + grabber_tex = get_theme_icon("grabber_highlight", "HSlider"); } else { - grabber_tex = get_icon("grabber", "HSlider"); + grabber_tex = get_theme_icon("grabber", "HSlider"); } if (grabber->get_texture() != grabber_tex) { @@ -297,7 +298,7 @@ void EditorSpinSlider::_notification(int p_what) { grabber->set_position(get_global_position() + grabber_rect.position + grabber_rect.size * 0.5 - grabber->get_size() * 0.5); if (mousewheel_over_grabber) { - Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); + InputFilter::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); } grabber_range = width; @@ -316,12 +317,7 @@ void EditorSpinSlider::_notification(int p_what) { update(); } if (p_what == NOTIFICATION_FOCUS_ENTER) { - /* Sorry, I don't like this, it makes navigating the different fields with arrows more difficult. - * Just press enter to edit. - * if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && !value_input_just_closed) { - _focus_entered(); - }*/ - if ((Input::get_singleton()->is_action_pressed("ui_focus_next") || Input::get_singleton()->is_action_pressed("ui_focus_prev")) && !value_input_just_closed) { + if ((InputFilter::get_singleton()->is_action_pressed("ui_focus_next") || InputFilter::get_singleton()->is_action_pressed("ui_focus_prev")) && !value_input_just_closed) { _focus_entered(); } value_input_just_closed = false; @@ -330,8 +326,8 @@ void EditorSpinSlider::_notification(int p_what) { Size2 EditorSpinSlider::get_minimum_size() const { - Ref<StyleBox> sb = get_stylebox("normal", "LineEdit"); - Ref<Font> font = get_font("font", "LineEdit"); + Ref<StyleBox> sb = get_theme_stylebox("normal", "LineEdit"); + Ref<Font> font = get_theme_font("font", "LineEdit"); Size2 ms = sb->get_minimum_size(); ms.height += font->get_height(); @@ -375,7 +371,7 @@ void EditorSpinSlider::_evaluate_input_text() { //text_entered signal void EditorSpinSlider::_value_input_entered(const String &p_text) { value_input_just_closed = true; - value_input->hide(); + value_input_popup->hide(); } //modal_closed signal @@ -398,7 +394,7 @@ void EditorSpinSlider::_value_focus_exited() { // -> modal_close was not called // -> need to close/hide manually if (!value_input_just_closed) { //value_input_just_closed should do the same - value_input->hide(); + value_input_popup->hide(); //tab was pressed } else { //enter, click, esc @@ -441,11 +437,11 @@ void EditorSpinSlider::set_custom_label_color(bool p_use_custom_label_color, Col } void EditorSpinSlider::_focus_entered() { - Rect2 gr = get_global_rect(); + Rect2 gr = get_screen_rect(); value_input->set_text(get_text_value()); - value_input->set_position(gr.position); - value_input->set_size(gr.size); - value_input->call_deferred("show_modal"); + value_input_popup->set_position(gr.position); + value_input_popup->set_size(gr.size); + value_input_popup->call_deferred("popup"); value_input->call_deferred("grab_focus"); value_input->call_deferred("select_all"); value_input->set_focus_next(find_next_valid_focus()->get_path()); @@ -492,11 +488,13 @@ EditorSpinSlider::EditorSpinSlider() { mousewheel_over_grabber = false; grabbing_grabber = false; grabber_range = 1; + value_input_popup = memnew(Popup); + add_child(value_input_popup); value_input = memnew(LineEdit); - add_child(value_input); - value_input->set_as_toplevel(true); - value_input->hide(); - value_input->connect("modal_closed", callable_mp(this, &EditorSpinSlider::_value_input_closed)); + value_input_popup->add_child(value_input); + value_input_popup->set_wrap_controls(true); + value_input->set_anchors_and_margins_preset(PRESET_WIDE); + value_input_popup->connect("popup_hide", callable_mp(this, &EditorSpinSlider::_value_input_closed)); value_input->connect("text_entered", callable_mp(this, &EditorSpinSlider::_value_input_entered)); value_input->connect("focus_exited", callable_mp(this, &EditorSpinSlider::_value_focus_exited)); value_input_just_closed = false; |