diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/base_button.cpp | 8 | ||||
-rw-r--r-- | scene/gui/label.cpp | 2 | ||||
-rw-r--r-- | scene/gui/menu_button.cpp | 11 | ||||
-rw-r--r-- | scene/gui/menu_button.h | 3 | ||||
-rw-r--r-- | scene/gui/split_container.cpp | 66 | ||||
-rw-r--r-- | scene/gui/split_container.h | 4 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 40 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 4 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 52 | ||||
-rw-r--r-- | scene/gui/tree.h | 8 |
10 files changed, 125 insertions, 73 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 148277f2dd..a67fe2aeeb 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -450,11 +450,11 @@ String BaseButton::get_tooltip(const Point2 &p_pos) const { String tooltip = Control::get_tooltip(p_pos); if (shortcut.is_valid() && shortcut->is_valid()) { - if (tooltip.find("$sc") != -1) { - tooltip = tooltip.replace_first("$sc", "(" + shortcut->get_as_text() + ")"); - } else { - tooltip += " (" + shortcut->get_as_text() + ")"; + String text = shortcut->get_name() + " (" + shortcut->get_as_text() + ")"; + if (shortcut->get_name().nocasecmp_to(tooltip) != 0) { + text += "\n" + tooltip; } + tooltip = text; } return tooltip; } diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index e1f77594da..51a25c60a1 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -207,7 +207,7 @@ void Label::_notification(int p_what) { } break; } - int y_ofs = style->get_offset().y; + float y_ofs = style->get_offset().y; y_ofs += (line - lines_skipped) * font_h + font->get_ascent(); y_ofs += vbegin + line * vsep; diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index d850553957..1d18c6504c 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -33,6 +33,9 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) { + if (disable_shortcuts) + return; + if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) { if (!get_parent() || !is_visible_in_tree() || is_disabled()) @@ -98,14 +101,22 @@ void MenuButton::_bind_methods() { ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &MenuButton::_unhandled_key_input); ClassDB::bind_method(D_METHOD("_set_items"), &MenuButton::_set_items); ClassDB::bind_method(D_METHOD("_get_items"), &MenuButton::_get_items); + ClassDB::bind_method(D_METHOD("set_disable_shortcuts", "disabled"), &MenuButton::set_disable_shortcuts); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_items", "_get_items"); ADD_SIGNAL(MethodInfo("about_to_show")); } + +void MenuButton::set_disable_shortcuts(bool p_disabled) { + + disable_shortcuts = p_disabled; +} + MenuButton::MenuButton() { set_flat(true); + set_disable_shortcuts(false); set_enabled_focus_mode(FOCUS_NONE); popup = memnew(PopupMenu); popup->hide(); diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h index c7f1d976ff..08a8a43f55 100644 --- a/scene/gui/menu_button.h +++ b/scene/gui/menu_button.h @@ -40,6 +40,7 @@ class MenuButton : public Button { GDCLASS(MenuButton, Button); bool clicked; + bool disable_shortcuts; PopupMenu *popup; virtual void pressed(); @@ -54,6 +55,8 @@ protected: public: PopupMenu *get_popup(); + void set_disable_shortcuts(bool p_disabled); + MenuButton(); ~MenuButton(); }; diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 4420a936d2..1c15953517 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -61,7 +61,7 @@ Control *SplitContainer::_getch(int p_idx) const { void SplitContainer::_resort() { - /** First pass, determine minimum size AND amount of stretchable elements */ + /* First pass, determine minimum size AND amount of stretchable elements */ int axis = vertical ? 1 : 0; @@ -114,10 +114,8 @@ void SplitContainer::_resort() { Size2 ms_second = second->get_combined_minimum_size(); if (vertical) { - minimum = ms_first.height + ms_second.height; } else { - minimum = ms_first.width + ms_second.width; } @@ -141,12 +139,10 @@ void SplitContainer::_resort() { } else if (expand_first_mode) { middle_sep = get_size()[axis] - ms_second[axis] - sep; - } else { middle_sep = ms_first[axis]; } - } else if (ratiomode) { int first_ratio = first->get_stretch_ratio(); @@ -160,23 +156,19 @@ void SplitContainer::_resort() { expand_ofs = (available * (1.0 - ratio)); middle_sep = ms_first[axis] + available * ratio + expand_ofs; - } else if (expand_first_mode) { if (expand_ofs > 0) expand_ofs = 0; - - if (expand_ofs < -available) + else if (expand_ofs < -available) expand_ofs = -available; middle_sep = get_size()[axis] - ms_second[axis] - sep + expand_ofs; - } else { if (expand_ofs < 0) expand_ofs = 0; - - if (expand_ofs > available) + else if (expand_ofs > available) expand_ofs = available; middle_sep = ms_first[axis] + expand_ofs; @@ -187,7 +179,6 @@ void SplitContainer::_resort() { fit_child_in_rect(first, Rect2(Point2(0, 0), Size2(get_size().width, middle_sep))); int sofs = middle_sep + sep; fit_child_in_rect(second, Rect2(Point2(0, sofs), Size2(get_size().width, get_size().height - sofs))); - } else { fit_child_in_rect(first, Rect2(Point2(0, 0), Size2(middle_sep, get_size().height))); @@ -246,10 +237,12 @@ void SplitContainer::_notification(int p_what) { _resort(); } break; case NOTIFICATION_MOUSE_ENTER: { + mouse_inside = true; update(); } break; case NOTIFICATION_MOUSE_EXIT: { + mouse_inside = false; update(); } break; @@ -260,22 +253,17 @@ void SplitContainer::_notification(int p_what) { if (collapsed || (!mouse_inside && get_constant("autohide"))) return; + int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0; Ref<Texture> tex = get_icon("grabber"); Size2 size = get_size(); - if (vertical) { + if (dragger_visibility == DRAGGER_VISIBLE) { - //draw_style_box( get_stylebox("bg"), Rect2(0,middle_sep,get_size().width,sep)); - if (dragger_visibility == DRAGGER_VISIBLE) + if (vertical) draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2)); - - } else { - - //draw_style_box( get_stylebox("bg"), Rect2(middle_sep,0,sep,get_size().height)); - if (dragger_visibility == DRAGGER_VISIBLE) + else draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2)); } - } break; } } @@ -292,11 +280,13 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { if (mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { + int sep = get_constant("separation"); if (vertical) { if (mb->get_position().y > middle_sep && mb->get_position().y < middle_sep + sep) { + dragging = true; drag_from = mb->get_position().y; drag_ofs = expand_ofs; @@ -304,6 +294,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { } else { if (mb->get_position().x > middle_sep && mb->get_position().x < middle_sep + sep) { + dragging = true; drag_from = mb->get_position().x; drag_ofs = expand_ofs; @@ -318,36 +309,31 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> mm = p_event; - if (mm.is_valid()) { - - if (dragging) { + if (mm.is_valid() && dragging) { - expand_ofs = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from); - queue_sort(); - emit_signal("dragged", get_split_offset()); - } + expand_ofs = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from); + queue_sort(); + emit_signal("dragged", get_split_offset()); } } Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const { - if (collapsed) - return Control::get_cursor_shape(p_pos); - if (dragging) return (vertical ? CURSOR_VSIZE : CURSOR_HSIZE); - int sep = get_constant("separation"); + if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) { - if (vertical) { + int sep = get_constant("separation"); - if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) { - return CURSOR_VSIZE; - } - } else { + if (vertical) { - if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep) { - return CURSOR_HSIZE; + if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) + return CURSOR_VSIZE; + } else { + + if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep) + return CURSOR_HSIZE; } } @@ -358,6 +344,7 @@ void SplitContainer::set_split_offset(int p_offset) { if (expand_ofs == p_offset) return; + expand_ofs = p_offset; queue_sort(); } @@ -371,6 +358,7 @@ void SplitContainer::set_collapsed(bool p_collapsed) { if (collapsed == p_collapsed) return; + collapsed = p_collapsed; queue_sort(); } diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h index c7a484c4c5..40a58d4b32 100644 --- a/scene/gui/split_container.h +++ b/scene/gui/split_container.h @@ -88,7 +88,7 @@ class HSplitContainer : public SplitContainer { public: HSplitContainer() : - SplitContainer(false) { set_default_cursor_shape(CURSOR_HSPLIT); } + SplitContainer(false) {} }; class VSplitContainer : public SplitContainer { @@ -97,7 +97,7 @@ class VSplitContainer : public SplitContainer { public: VSplitContainer() : - SplitContainer(true) { set_default_cursor_shape(CURSOR_VSPLIT); } + SplitContainer(true) {} }; #endif // SPLIT_CONTAINER_H diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 07f1bdf8e5..b2a5317f09 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1973,6 +1973,31 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (mb->get_button_index() == BUTTON_RIGHT && context_menu_enabled) { + _reset_caret_blink_timer(); + + int row, col; + update_line_scroll_pos(); + _get_mouse_pos(Point2i(mb->get_position().x, mb->get_position().y), row, col); + + if (is_right_click_moving_caret()) { + if (is_selection_active()) { + + int from_line = get_selection_from_line(); + int to_line = get_selection_to_line(); + int from_column = get_selection_from_column(); + int to_column = get_selection_to_column(); + + if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) { + // Right click is outside the seleted text + deselect(); + } + } + if (!is_selection_active()) { + cursor_set_line(row, true, false); + cursor_set_column(col); + } + } + menu->set_position(get_global_transform().xform(get_local_mouse_position())); menu->set_size(Vector2(1, 1)); menu->popup(); @@ -3708,6 +3733,14 @@ bool TextEdit::cursor_is_block_mode() const { return block_caret; } +void TextEdit::set_right_click_moves_caret(bool p_enable) { + right_click_moves_caret = p_enable; +} + +bool TextEdit::is_right_click_moving_caret() const { + return right_click_moves_caret; +} + void TextEdit::_v_scroll_input() { scrolling = false; } @@ -5457,6 +5490,9 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("cursor_set_block_mode", "enable"), &TextEdit::cursor_set_block_mode); ClassDB::bind_method(D_METHOD("cursor_is_block_mode"), &TextEdit::cursor_is_block_mode); + ClassDB::bind_method(D_METHOD("set_right_click_moves_caret", "enable"), &TextEdit::set_right_click_moves_caret); + ClassDB::bind_method(D_METHOD("is_right_click_moving_caret"), &TextEdit::is_right_click_moving_caret); + ClassDB::bind_method(D_METHOD("set_readonly", "enable"), &TextEdit::set_readonly); ClassDB::bind_method(D_METHOD("is_readonly"), &TextEdit::is_readonly); @@ -5492,7 +5528,7 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_hiding_enabled", "enable"), &TextEdit::set_hiding_enabled); ClassDB::bind_method(D_METHOD("is_hiding_enabled"), &TextEdit::is_hiding_enabled); ClassDB::bind_method(D_METHOD("set_line_as_hidden", "line", "enable"), &TextEdit::set_line_as_hidden); - ClassDB::bind_method(D_METHOD("is_line_hidden"), &TextEdit::is_line_hidden); + ClassDB::bind_method(D_METHOD("is_line_hidden", "line"), &TextEdit::is_line_hidden); ClassDB::bind_method(D_METHOD("fold_all_lines"), &TextEdit::fold_all_lines); ClassDB::bind_method(D_METHOD("unhide_all_lines"), &TextEdit::unhide_all_lines); ClassDB::bind_method(D_METHOD("fold_line", "line"), &TextEdit::fold_line); @@ -5540,6 +5576,7 @@ void TextEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled"); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.1"), "cursor_set_blink_speed", "cursor_get_blink_speed"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_moving_by_right_click"), "set_right_click_moves_caret", "is_right_click_moving_caret"); ADD_SIGNAL(MethodInfo("cursor_changed")); ADD_SIGNAL(MethodInfo("text_changed")); @@ -5617,6 +5654,7 @@ TextEdit::TextEdit() { caret_blink_timer->set_wait_time(0.65); caret_blink_timer->connect("timeout", this, "_toggle_draw_caret"); cursor_set_blink_enabled(false); + right_click_moves_caret = true; idle_detect = memnew(Timer); add_child(idle_detect); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 836d5c7388..f18eaa85cb 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -246,6 +246,7 @@ class TextEdit : public Control { bool draw_caret; bool window_has_focus; bool block_caret; + bool right_click_moves_caret; bool setting_row; bool wrap; @@ -481,6 +482,9 @@ public: void cursor_set_block_mode(const bool p_enable); bool cursor_is_block_mode() const; + void set_right_click_moves_caret(bool p_enable); + bool is_right_click_moving_caret() const; + void set_readonly(bool p_readonly); bool is_readonly() const; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index b5b42e8f29..51ad22e271 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1775,7 +1775,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool case TreeItem::CELL_MODE_STRING: { //nothing in particular - if (select_mode == SELECT_MULTI && (get_tree()->get_last_event_id() == focus_in_id || !already_cursor)) { + if (select_mode == SELECT_MULTI && (get_tree()->get_event_count() == focus_in_id || !already_cursor)) { bring_up_editor = false; } @@ -1863,7 +1863,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } else { editor_text = String::num(p_item->cells[col].val, Math::step_decimals(p_item->cells[col].step)); - if (select_mode == SELECT_MULTI && get_tree()->get_last_event_id() == focus_in_id) + if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) bring_up_editor = false; } } @@ -2786,7 +2786,7 @@ void Tree::_notification(int p_what) { if (p_what == NOTIFICATION_FOCUS_ENTER) { - focus_in_id = get_tree()->get_last_event_id(); + focus_in_id = get_tree()->get_event_count(); } if (p_what == NOTIFICATION_MOUSE_EXIT) { @@ -2950,43 +2950,51 @@ Size2 Tree::get_minimum_size() const { return Size2(1, 1); } -TreeItem *Tree::create_item(TreeItem *p_parent) { +TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) { ERR_FAIL_COND_V(blocked > 0, NULL); - TreeItem *ti = memnew(TreeItem(this)); - - ERR_FAIL_COND_V(!ti, NULL); - ti->cells.resize(columns.size()); + TreeItem *ti = NULL; if (p_parent) { - /* Always append at the end */ + // Append or insert a new item to the given parent. + ti = memnew(TreeItem(this)); + ERR_FAIL_COND_V(!ti, NULL); + ti->cells.resize(columns.size()); - TreeItem *last = 0; + TreeItem *prev = NULL; TreeItem *c = p_parent->childs; + int idx = 0; while (c) { - - last = c; + if (idx++ == p_idx) { + ti->next = c; + break; + } + prev = c; c = c->next; } - if (last) { - - last->next = ti; - } else { - + if (prev) + prev->next = ti; + else p_parent->childs = ti; - } ti->parent = p_parent; } else { - if (root) - ti->childs = root; + if (!root) { + // No root exists, make the given item the new root. + ti = memnew(TreeItem(this)); + ERR_FAIL_COND_V(!ti, NULL); + ti->cells.resize(columns.size()); - root = ti; + root = ti; + } else { + // Root exists, append or insert to root. + ti = create_item(root, p_idx); + } } return ti; @@ -3723,7 +3731,7 @@ void Tree::_bind_methods() { ClassDB::bind_method(D_METHOD("_scroll_moved"), &Tree::_scroll_moved); ClassDB::bind_method(D_METHOD("clear"), &Tree::clear); - ClassDB::bind_method(D_METHOD("create_item", "parent"), &Tree::_create_item, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("create_item", "parent", "idx"), &Tree::_create_item, DEFVAL(Variant()), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("get_root"), &Tree::get_root); ClassDB::bind_method(D_METHOD("set_column_min_width", "column", "min_width"), &Tree::set_column_min_width); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 112de3165f..b8d94bcffb 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -359,7 +359,7 @@ private: LineEdit *text_editor; HSlider *value_editor; bool updating_value_editor; - uint32_t focus_in_id; + int64_t focus_in_id; PopupMenu *popup_menu; Vector<ColumnInfo> columns; @@ -511,8 +511,8 @@ protected: static void _bind_methods(); //bind helpers - Object *_create_item(Object *p_parent) { - return create_item(Object::cast_to<TreeItem>(p_parent)); + Object *_create_item(Object *p_parent, int p_idx = -1) { + return create_item(Object::cast_to<TreeItem>(p_parent), p_idx); } TreeItem *_get_next_selected(Object *p_item) { @@ -532,7 +532,7 @@ public: void clear(); - TreeItem *create_item(TreeItem *p_parent = 0); + TreeItem *create_item(TreeItem *p_parent = 0, int p_idx = -1); TreeItem *get_root(); TreeItem *get_last_item(); |