summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/button.h3
-rw-r--r--scene/gui/color_picker.cpp18
-rw-r--r--scene/gui/color_picker.h4
-rw-r--r--scene/gui/menu_button.cpp28
-rw-r--r--scene/gui/menu_button.h5
-rw-r--r--scene/gui/option_button.cpp77
-rw-r--r--scene/gui/option_button.h2
-rw-r--r--scene/gui/split_container.cpp66
-rw-r--r--scene/gui/split_container.h4
-rw-r--r--scene/gui/text_edit.cpp58
-rw-r--r--scene/gui/text_edit.h4
-rw-r--r--scene/gui/tree.cpp52
-rw-r--r--scene/gui/tree.h8
13 files changed, 185 insertions, 144 deletions
diff --git a/scene/gui/button.h b/scene/gui/button.h
index 35488582de..5c5a73bae3 100644
--- a/scene/gui/button.h
+++ b/scene/gui/button.h
@@ -56,7 +56,6 @@ private:
float _internal_margin[4];
protected:
- virtual Size2 get_minimum_size() const;
void _set_internal_margin(Margin p_margin, float p_value);
void _notification(int p_what);
static void _bind_methods();
@@ -64,6 +63,8 @@ protected:
public:
//
+ virtual Size2 get_minimum_size() const;
+
void set_text(const String &p_text);
String get_text() const;
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index cb6283507e..446676e80d 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -39,33 +39,32 @@ void ColorPicker::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
- //sample->set_texture(get_icon("color_sample"));
+
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
bt_add_preset->set_icon(get_icon("add_preset"));
_update_controls();
} break;
-
case NOTIFICATION_ENTER_TREE: {
+
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
bt_add_preset->set_icon(get_icon("add_preset"));
_update_color();
} break;
-
case NOTIFICATION_PARENTED: {
+
for (int i = 0; i < 4; i++)
set_margin((Margin)i, get_constant("margin"));
} break;
-
case NOTIFICATION_VISIBILITY_CHANGED: {
Popup *p = Object::cast_to<Popup>(get_parent());
if (p)
p->set_size(Size2(get_combined_minimum_size().width + get_constant("margin") * 2, get_combined_minimum_size().height + get_constant("margin") * 2));
} break;
-
case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: {
+
if (screen != NULL) {
if (screen->is_visible()) {
screen->hide();
@@ -523,7 +522,6 @@ ColorPicker::ColorPicker() :
add_child(hb_edit);
w_edit = memnew(Control);
- //w_edit->set_ignore_mouse(false);
w_edit->set_custom_minimum_size(Size2(get_constant("h_width"), 0));
w_edit->set_h_size_flags(SIZE_FILL);
w_edit->set_v_size_flags(SIZE_EXPAND_FILL);
@@ -589,7 +587,6 @@ ColorPicker::ColorPicker() :
c_text->set_h_size_flags(SIZE_EXPAND_FILL);
_update_controls();
- //_update_color();
updating = false;
set_pick_color(Color(1, 1, 1));
@@ -599,7 +596,6 @@ ColorPicker::ColorPicker() :
preset = memnew(TextureRect);
bbc->add_child(preset);
- //preset->set_ignore_mouse(false);
preset->connect("gui_input", this, "_preset_input");
preset->connect("draw", this, "_update_presets");
@@ -660,11 +656,13 @@ bool ColorPickerButton::is_editing_alpha() const {
return picker->is_editing_alpha();
}
-ColorPicker *ColorPickerButton::get_picker() {
+ColorPicker *ColorPickerButton::get_picker() const {
+
return picker;
}
-PopupPanel *ColorPickerButton::get_popup() {
+PopupPanel *ColorPickerButton::get_popup() const {
+
return popup;
}
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index c02cdc8608..2bae279ed5 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -129,8 +129,8 @@ public:
void set_edit_alpha(bool p_show);
bool is_editing_alpha() const;
- ColorPicker *get_picker();
- PopupPanel *get_popup();
+ ColorPicker *get_picker() const;
+ PopupPanel *get_popup() const;
ColorPickerButton();
};
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index d850553957..c235797bef 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())
@@ -60,25 +63,10 @@ void MenuButton::pressed() {
void MenuButton::_gui_input(Ref<InputEvent> p_event) {
- /*if (p_event.type==InputEvent::MOUSE_BUTTON && p_event->get_button_index()==BUTTON_LEFT) {
- clicked=p_event->is_pressed();
- }
- if (clicked && p_event.type==InputEvent::MOUSE_MOTION && popup->is_visible_in_tree()) {
-
- Point2 gt = Point2(p_event.mouse_motion.x,p_event.mouse_motion.y);
- gt = get_global_transform().xform(gt);
- Point2 lt = popup->get_transform().affine_inverse().xform(gt);
- if (popup->has_point(lt)) {
- //print_line("HAS POINT!!!");
- popup->call_deferred("grab_click_focus");
- }
-
- }*/
-
BaseButton::_gui_input(p_event);
}
-PopupMenu *MenuButton::get_popup() {
+PopupMenu *MenuButton::get_popup() const {
return popup;
}
@@ -98,14 +86,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..1bd9b155b2 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();
@@ -53,7 +54,9 @@ protected:
static void _bind_methods();
public:
- PopupMenu *get_popup();
+ PopupMenu *get_popup() const;
+ void set_disable_shortcuts(bool p_disabled);
+
MenuButton();
~MenuButton();
};
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 70f3d9ca83..6f784b56de 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -42,38 +42,35 @@ Size2 OptionButton::get_minimum_size() const {
void OptionButton::_notification(int p_what) {
- switch (p_what) {
-
- case NOTIFICATION_DRAW: {
-
- if (!has_icon("arrow"))
- return;
-
- RID ci = get_canvas_item();
- Ref<Texture> arrow = Control::get_icon("arrow");
- Ref<StyleBox> normal = get_stylebox("normal");
- Color clr = Color(1, 1, 1);
- if (get_constant("modulate_arrow"))
- switch (get_draw_mode()) {
- case DRAW_PRESSED:
- clr = get_color("font_color_pressed");
- break;
- case DRAW_HOVER:
- clr = get_color("font_color_hover");
- break;
- case DRAW_DISABLED:
- clr = get_color("font_color_disabled");
- break;
- default:
- clr = get_color("font_color");
- }
-
- Size2 size = get_size();
-
- Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
- arrow->draw(ci, ofs, clr);
-
- } break;
+ if (p_what == NOTIFICATION_DRAW) {
+
+ if (!has_icon("arrow"))
+ return;
+
+ RID ci = get_canvas_item();
+ Ref<Texture> arrow = Control::get_icon("arrow");
+ Ref<StyleBox> normal = get_stylebox("normal");
+ Color clr = Color(1, 1, 1);
+ if (get_constant("modulate_arrow")) {
+ switch (get_draw_mode()) {
+ case DRAW_PRESSED:
+ clr = get_color("font_color_pressed");
+ break;
+ case DRAW_HOVER:
+ clr = get_color("font_color_hover");
+ break;
+ case DRAW_DISABLED:
+ clr = get_color("font_color_disabled");
+ break;
+ default:
+ clr = get_color("font_color");
+ }
+ }
+
+ Size2 size = get_size();
+
+ Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
+ arrow->draw(ci, ofs, clr);
}
}
@@ -244,6 +241,11 @@ void OptionButton::remove_item(int p_idx) {
popup->remove_item(p_idx);
}
+PopupMenu *OptionButton::get_popup() const {
+
+ return popup;
+}
+
Array OptionButton::_get_items() const {
Array items;
@@ -310,6 +312,8 @@ void OptionButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_item", "idx"), &OptionButton::remove_item);
ClassDB::bind_method(D_METHOD("_select_int"), &OptionButton::_select_int);
+ ClassDB::bind_method(D_METHOD("get_popup"), &OptionButton::get_popup);
+
ClassDB::bind_method(D_METHOD("_set_items"), &OptionButton::_set_items);
ClassDB::bind_method(D_METHOD("_get_items"), &OptionButton::_get_items);
@@ -320,15 +324,16 @@ void OptionButton::_bind_methods() {
OptionButton::OptionButton() {
+ current = -1;
+ set_text_align(ALIGN_LEFT);
+ set_action_mode(ACTION_MODE_BUTTON_PRESS);
+
popup = memnew(PopupMenu);
popup->hide();
+ add_child(popup);
popup->set_as_toplevel(true);
popup->set_pass_on_modal_close_click(false);
- add_child(popup);
popup->connect("id_pressed", this, "_selected");
-
- current = -1;
- set_text_align(ALIGN_LEFT);
}
OptionButton::~OptionButton() {
diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h
index a06c540678..b09942b072 100644
--- a/scene/gui/option_button.h
+++ b/scene/gui/option_button.h
@@ -85,6 +85,8 @@ public:
void remove_item(int p_idx);
+ PopupMenu *get_popup() const;
+
virtual void get_translatable_strings(List<String> *p_strings) const;
OptionButton();
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..0fba4a6f94 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1695,10 +1695,9 @@ void TextEdit::indent_right() {
// fix selection and cursor being off by one on the last line
if (is_selection_active()) {
- selection.to_column++;
- selection.from_column++;
+ select(selection.from_line, selection.from_column + 1, selection.to_line, selection.to_column + 1);
}
- cursor.column++;
+ cursor_set_column(cursor.column + 1, false);
end_complex_operation();
update();
}
@@ -1737,14 +1736,9 @@ void TextEdit::indent_left() {
// fix selection and cursor being off by one on the last line
if (is_selection_active() && last_line_text != get_line(end_line)) {
- if (selection.to_column > 0)
- selection.to_column--;
- if (selection.from_column > 0)
- selection.from_column--;
- }
- if (cursor.column > 0) {
- cursor.column--;
+ select(selection.from_line, selection.from_column - 1, selection.to_line, selection.to_column - 1);
}
+ cursor_set_column(cursor.column - 1, false);
end_complex_operation();
update();
}
@@ -1973,6 +1967,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 +3727,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;
}
@@ -4168,11 +4195,15 @@ void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_t
p_from_line = text.size() - 1;
if (p_from_column >= text[p_from_line].length())
p_from_column = text[p_from_line].length();
+ if (p_from_column < 0)
+ p_from_column = 0;
if (p_to_line >= text.size())
p_to_line = text.size() - 1;
if (p_to_column >= text[p_to_line].length())
p_to_column = text[p_to_line].length();
+ if (p_to_column < 0)
+ p_to_column = 0;
selection.from_line = p_from_line;
selection.from_column = p_from_column;
@@ -5457,6 +5488,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 +5526,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 +5574,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 +5652,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();