diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/light.cpp | 1 | ||||
-rw-r--r-- | scene/gui/base_button.cpp | 16 | ||||
-rw-r--r-- | scene/gui/base_button.h | 4 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 8 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 61 | ||||
-rw-r--r-- | scene/resources/animation.h | 1 | ||||
-rw-r--r-- | scene/resources/font.cpp | 33 | ||||
-rw-r--r-- | scene/resources/font.h | 1 |
8 files changed, 114 insertions, 11 deletions
diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index ed533ee7a4..2377068ede 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -152,6 +152,7 @@ PoolVector<Face3> Light::get_faces(uint32_t p_usage_flags) const { void Light::set_bake_mode(BakeMode p_mode) { bake_mode = p_mode; + VS::get_singleton()->light_set_use_gi(light, p_mode != BAKE_DISABLED); } Light::BakeMode Light::get_bake_mode() const { diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index f808d6c234..e95781c181 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -376,7 +376,7 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const { bool pressing; if (status.press_attempt) { - pressing = status.pressing_inside; + pressing = (status.pressing_inside || keep_pressed_outside); if (status.pressed) pressing = !pressing; } else { @@ -446,6 +446,16 @@ Control::FocusMode BaseButton::get_enabled_focus_mode() const { return enabled_focus_mode; } +void BaseButton::set_keep_pressed_outside(bool p_on) { + + keep_pressed_outside = p_on; +} + +bool BaseButton::is_keep_pressed_outside() const { + + return keep_pressed_outside; +} + void BaseButton::set_shortcut(const Ref<ShortCut> &p_shortcut) { if (shortcut.is_null() == p_shortcut.is_null()) @@ -528,6 +538,8 @@ void BaseButton::_bind_methods() { ClassDB::bind_method(D_METHOD("get_draw_mode"), &BaseButton::get_draw_mode); ClassDB::bind_method(D_METHOD("set_enabled_focus_mode", "mode"), &BaseButton::set_enabled_focus_mode); ClassDB::bind_method(D_METHOD("get_enabled_focus_mode"), &BaseButton::get_enabled_focus_mode); + ClassDB::bind_method(D_METHOD("set_keep_pressed_outside", "enabled"), &BaseButton::set_keep_pressed_outside); + ClassDB::bind_method(D_METHOD("is_keep_pressed_outside"), &BaseButton::is_keep_pressed_outside); ClassDB::bind_method(D_METHOD("set_shortcut", "shortcut"), &BaseButton::set_shortcut); ClassDB::bind_method(D_METHOD("get_shortcut"), &BaseButton::get_shortcut); @@ -549,6 +561,7 @@ void BaseButton::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "action_mode", PROPERTY_HINT_ENUM, "Button Press,Button Release"), "set_action_mode", "get_action_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask", PROPERTY_HINT_FLAGS, "Mouse Left, Mouse Right, Mouse Middle"), "set_button_mask", "get_button_mask"); ADD_PROPERTY(PropertyInfo(Variant::INT, "enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_enabled_focus_mode", "get_enabled_focus_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_pressed_outside"), "set_keep_pressed_outside", "is_keep_pressed_outside"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "ShortCut"), "set_shortcut", "get_shortcut"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "group", PROPERTY_HINT_RESOURCE_TYPE, "ButtonGroup"), "set_button_group", "get_button_group"); @@ -566,6 +579,7 @@ BaseButton::BaseButton() { toggle_mode = false; shortcut_in_tooltip = true; + keep_pressed_outside = false; status.pressed = false; status.press_attempt = false; status.hovering = false; diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index 9a00cc79f2..22a8f6d8fe 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -52,6 +52,7 @@ private: int button_mask; bool toggle_mode; bool shortcut_in_tooltip; + bool keep_pressed_outside; FocusMode enabled_focus_mode; Ref<ShortCut> shortcut; @@ -110,6 +111,9 @@ public: void set_action_mode(ActionMode p_mode); ActionMode get_action_mode() const; + void set_keep_pressed_outside(bool p_on); + bool is_keep_pressed_outside() const; + void set_button_mask(int p_mask); int get_button_mask() const; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 8825891807..e77ee8c744 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -93,14 +93,14 @@ Size2 PopupMenu::get_minimum_size() const { if (items[i].submenu != "") size.width += get_icon("submenu")->get_width(); - if (has_check) - size.width += check_w; - max_w = MAX(max_w, size.width + icon_w); + max_w = MAX(max_w, size.width); minsize.height += size.height; } - minsize.width += max_w + accel_max_w; + minsize.width += max_w + icon_w + accel_max_w; + if (has_check) + minsize.width += check_w; return minsize; } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index fbf6550362..9ab30b1976 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -825,6 +825,9 @@ void TextEdit::_notification(int p_what) { // get the highlighted words String highlighted_text = get_selection_text(); + // check if highlighted words contains only whitespaces (tabs or spaces) + bool only_whitespaces_highlighted = highlighted_text.strip_edges() == String(); + String line_num_padding = line_numbers_zero_padded ? "0" : " "; int cursor_wrap_index = get_cursor_wrap_index(); @@ -1123,7 +1126,7 @@ void TextEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + char_w + ofs_x - 1, ofs_y), Size2i(1, get_row_height())), border_color); } - if (highlight_all_occurrences) { + if (highlight_all_occurrences && !only_whitespaces_highlighted) { if (highlighted_text_col != -1) { // if we are at the end check for new word on same line @@ -1557,8 +1560,7 @@ void TextEdit::_consume_pair_symbol(CharType ch) { } if ((ch == '\'' || ch == '"') && - cursor_get_column() > 0 && - _is_text_char(text[cursor.line][cursor_get_column() - 1])) { + cursor_get_column() > 0 && _is_text_char(text[cursor.line][cursor_get_column() - 1]) && !_is_pair_right_symbol(text[cursor.line][cursor_get_column()])) { insert_text_at_cursor(ch_single); cursor_set_column(cursor_position_to_move); return; @@ -2594,6 +2596,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } FALLTHROUGH; } +#ifdef APPLE_STYLE_KEYS + case KEY_B: { + if (!k->get_control()) { + scancode_handled = false; + break; + } + FALLTHROUGH; + } +#endif case KEY_LEFT: { if (k->get_shift()) @@ -2607,9 +2618,22 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { #ifdef APPLE_STYLE_KEYS if (k->get_command()) { - cursor_set_column(0); + // Start at first column (it's slightly faster that way) and look for the first non-whitespace character. + int new_cursor_pos = 0; + for (int i = 0; i < text[cursor.line].length(); ++i) { + if (!_is_whitespace(text[cursor.line][i])) { + new_cursor_pos = i; + break; + } + } + if (new_cursor_pos == cursor.column) { + // We're already at the first text character, so move to the very beginning of the line. + cursor_set_column(0); + } else { + // We're somewhere to the right of the first text character; move to the first one. + cursor_set_column(new_cursor_pos); + } } else if (k->get_alt()) { - #else if (k->get_alt()) { scancode_handled = false; @@ -2657,6 +2681,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } FALLTHROUGH; } +#ifdef APPLE_STYLE_KEYS + case KEY_F: { + if (!k->get_control()) { + scancode_handled = false; + break; + } + FALLTHROUGH; + } +#endif case KEY_RIGHT: { if (k->get_shift()) @@ -2718,6 +2751,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } FALLTHROUGH; } +#ifdef APPLE_STYLE_KEYS + case KEY_P: { + if (!k->get_control()) { + scancode_handled = false; + break; + } + FALLTHROUGH; + } +#endif case KEY_UP: { if (k->get_alt()) { @@ -2771,6 +2813,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } FALLTHROUGH; } +#ifdef APPLE_STYLE_KEYS + case KEY_N: { + if (!k->get_control()) { + scancode_handled = false; + break; + } + FALLTHROUGH; + } +#endif case KEY_DOWN: { if (k->get_alt()) { diff --git a/scene/resources/animation.h b/scene/resources/animation.h index b66ae184e9..3d38a8902f 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -93,7 +93,6 @@ private: template <class T> struct TKey : public Key { - float time; T value; }; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index c72ccc97db..128db3f109 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -96,6 +96,7 @@ void Font::_bind_methods() { ClassDB::bind_method(D_METHOD("get_height"), &Font::get_height); ClassDB::bind_method(D_METHOD("is_distance_field_hint"), &Font::is_distance_field_hint); ClassDB::bind_method(D_METHOD("get_string_size", "string"), &Font::get_string_size); + ClassDB::bind_method(D_METHOD("get_wordwrap_string_size", "string", "p_width"), &Font::get_wordwrap_string_size); ClassDB::bind_method(D_METHOD("has_outline"), &Font::has_outline); ClassDB::bind_method(D_METHOD("draw_char", "canvas_item", "position", "char", "next", "modulate", "outline"), &Font::draw_char, DEFVAL(-1), DEFVAL(Color(1, 1, 1)), DEFVAL(false)); ClassDB::bind_method(D_METHOD("update_changes"), &Font::update_changes); @@ -495,6 +496,38 @@ Size2 Font::get_string_size(const String &p_string) const { return Size2(w, get_height()); } + +Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) const { + + ERR_FAIL_COND_V(p_width <= 0, Vector2(0, get_height())); + + int l = p_string.length(); + if (l == 0) + return Size2(p_width, get_height()); + + float line_w = 0; + float h = 0; + float space_w = get_char_size(' ').width; + Vector<String> lines = p_string.split("\n"); + for (int i = 0; i < lines.size(); i++) { + h += get_height(); + String t = lines[i]; + line_w = 0; + Vector<String> words = t.split(" "); + for (int j = 0; j < words.size(); j++) { + line_w += get_string_size(words[j]).x; + if (line_w > p_width) { + h += get_height(); + line_w = get_string_size(words[j]).x; + } else { + line_w += space_w; + } + } + } + + return Size2(p_width, h); +} + void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) { ERR_FAIL_COND(p_fallback == this); diff --git a/scene/resources/font.h b/scene/resources/font.h index 6bc8d9b792..def2c2285a 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -53,6 +53,7 @@ public: virtual Size2 get_char_size(CharType p_char, CharType p_next = 0) const = 0; Size2 get_string_size(const String &p_string) const; + Size2 get_wordwrap_string_size(const String &p_string, float p_width) const; virtual bool is_distance_field_hint() const = 0; |