diff options
Diffstat (limited to 'editor/editor_spin_slider.cpp')
-rw-r--r-- | editor/editor_spin_slider.cpp | 73 |
1 files changed, 46 insertions, 27 deletions
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index ec90af1bcc..cd28a65c7b 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -39,9 +39,9 @@ String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { if (grabber->is_visible()) { #ifdef OSX_ENABLED - const int key = KEY_META; + Key key = Key::META; #else - const int key = KEY_CTRL; + Key key = Key::CTRL; #endif return TS->format_number(rtos(get_value())) + "\n\n" + vformat(TTR("Hold %s to round to integers. Hold Shift for more precise changes."), find_keycode_name(key)); } @@ -61,7 +61,7 @@ void EditorSpinSlider::gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb->get_button_index() == MouseButton::LEFT) { if (mb->is_pressed()) { if (updown_offset != -1 && mb->get_position().x > updown_offset) { //there is an updown, so use it. @@ -92,7 +92,7 @@ void EditorSpinSlider::gui_input(const Ref<InputEvent> &p_event) { grabbing_spinner_attempt = false; } } - } else if (mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP || mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) { + } else if (mb->get_button_index() == MouseButton::WHEEL_UP || mb->get_button_index() == MouseButton::WHEEL_DOWN) { if (grabber->is_visible()) { call_deferred(SNAME("update")); } @@ -154,17 +154,17 @@ void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) { if (grabbing_grabber) { if (mb.is_valid()) { - if (mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) { + if (mb->get_button_index() == MouseButton::WHEEL_UP) { set_value(get_value() + get_step()); mousewheel_over_grabber = true; - } else if (mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) { + } else if (mb->get_button_index() == MouseButton::WHEEL_DOWN) { set_value(get_value() - get_step()); mousewheel_over_grabber = true; } } } - if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT) { if (mb->is_pressed()) { grabbing_grabber = true; if (!mousewheel_over_grabber) { @@ -212,9 +212,9 @@ void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) { step *= 0.1; } - uint32_t code = k->get_keycode(); + Key code = k->get_keycode(); switch (code) { - case KEY_UP: { + case Key::UP: { _evaluate_input_text(); double last_value = get_value(); @@ -225,9 +225,10 @@ void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) { set_value(last_value + real_step); } - value_input->set_text(get_text_value()); + value_input_dirty = true; + set_process_internal(true); } break; - case KEY_DOWN: { + case Key::DOWN: { _evaluate_input_text(); double last_value = get_value(); @@ -238,8 +239,11 @@ void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) { set_value(last_value - real_step); } - value_input->set_text(get_text_value()); + value_input_dirty = true; + set_process_internal(true); } break; + default: + break; } } } @@ -258,9 +262,9 @@ void EditorSpinSlider::_update_value_input_stylebox() { // The margin values below were determined by empirical testing. if (is_layout_rtl()) { stylebox->set_default_margin(SIDE_LEFT, 0); - stylebox->set_default_margin(SIDE_RIGHT, (get_label() != String() ? 23 : 16) * EDSCALE); + stylebox->set_default_margin(SIDE_RIGHT, (!get_label().is_empty() ? 23 : 16) * EDSCALE); } else { - stylebox->set_default_margin(SIDE_LEFT, (get_label() != String() ? 23 : 16) * EDSCALE); + stylebox->set_default_margin(SIDE_LEFT, (!get_label().is_empty() ? 23 : 16) * EDSCALE); stylebox->set_default_margin(SIDE_RIGHT, 0); } @@ -304,7 +308,7 @@ void EditorSpinSlider::_draw_spin_slider() { lc = fc; } - if (flat && label != String()) { + if (flat && !label.is_empty()) { Color label_bg_color = get_theme_color(SNAME("dark_color_3"), SNAME("Editor")); if (rtl) { draw_rect(Rect2(Vector2(size.width - (sb->get_offset().x * 2 + label_width), 0), Vector2(sb->get_offset().x * 2 + label_width, size.height)), label_bg_color); @@ -319,9 +323,9 @@ void EditorSpinSlider::_draw_spin_slider() { } if (rtl) { - draw_string(font, Vector2(Math::round(size.width - sb->get_offset().x - label_width), vofs), label, HALIGN_RIGHT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + draw_string(font, Vector2(Math::round(size.width - sb->get_offset().x - label_width), vofs), label, HORIZONTAL_ALIGNMENT_RIGHT, -1, font_size, lc * Color(1, 1, 1, 0.5)); } else { - draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, HALIGN_LEFT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, lc * Color(1, 1, 1, 0.5)); } int suffix_start = numstr.length(); @@ -367,17 +371,24 @@ void EditorSpinSlider::_draw_spin_slider() { grabber->hide(); } } else if (!hide_slider) { - int grabber_w = 4 * EDSCALE; - int width = size.width - sb->get_minimum_size().width - grabber_w; - int ofs = sb->get_offset().x; - int svofs = (size.height + vofs) / 2 - 1; + const int grabber_w = 4 * EDSCALE; + const int width = size.width - sb->get_minimum_size().width - grabber_w; + const int ofs = sb->get_offset().x; + const int svofs = (size.height + vofs) / 2 - 1; Color c = fc; - c.a = 0.2; + // Draw the horizontal slider's background. + c.a = 0.2; draw_rect(Rect2(ofs, svofs + 1, width, 2 * EDSCALE), c); - int gofs = get_as_ratio() * width; + + // Draw the horizontal slider's filled part on the left. + const int gofs = get_as_ratio() * width; + c.a = 0.45; + draw_rect(Rect2(ofs, svofs + 1, gofs, 2 * EDSCALE), c); + + // Draw the horizontal slider's grabber. c.a = 0.9; - Rect2 grabber_rect = Rect2(ofs + gofs, svofs + 1, grabber_w, 2 * EDSCALE); + const Rect2 grabber_rect = Rect2(ofs + gofs, svofs, grabber_w, 4 * EDSCALE); draw_rect(grabber_rect, c); grabbing_spinner_mouse_pos = get_global_position() + grabber_rect.get_center(); @@ -405,7 +416,7 @@ void EditorSpinSlider::_draw_spin_slider() { Vector2 scale = get_global_transform_with_canvas().get_scale(); grabber->set_scale(scale); - grabber->set_size(Size2(0, 0)); + grabber->reset_size(); grabber->set_position(get_global_position() + (grabber_rect.get_center() - grabber->get_size() * 0.5) * scale); if (mousewheel_over_grabber) { @@ -424,6 +435,14 @@ void EditorSpinSlider::_notification(int p_what) { _update_value_input_stylebox(); break; + case NOTIFICATION_INTERNAL_PROCESS: + if (value_input_dirty) { + value_input_dirty = false; + value_input->set_text(get_text_value()); + } + set_process_internal(false); + break; + case NOTIFICATION_DRAW: _draw_spin_slider(); break; |