summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/classes/EditorResourcePicker.xml2
-rw-r--r--editor/editor_resource_picker.cpp12
-rw-r--r--editor/editor_resource_picker.h3
-rw-r--r--editor/plugins/text_control_editor_plugin.cpp199
-rw-r--r--editor/plugins/text_control_editor_plugin.h2
-rw-r--r--scene/gui/graph_edit.cpp14
-rw-r--r--scene/gui/graph_edit.h2
-rw-r--r--scene/gui/rich_text_label.cpp1
-rw-r--r--scene/main/viewport.cpp4
-rw-r--r--scene/main/viewport.h3
10 files changed, 181 insertions, 61 deletions
diff --git a/doc/classes/EditorResourcePicker.xml b/doc/classes/EditorResourcePicker.xml
index b26b6f9527..f374b5f425 100644
--- a/doc/classes/EditorResourcePicker.xml
+++ b/doc/classes/EditorResourcePicker.xml
@@ -11,7 +11,7 @@
</tutorials>
<methods>
<method name="_handle_menu_selected" qualifiers="virtual">
- <return type="void" />
+ <return type="bool" />
<argument index="0" name="id" type="int" />
<description>
This virtual method can be implemented to handle context menu items not handled by default. See [method _set_create_options].
diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp
index 421d16313a..c649162d7e 100644
--- a/editor/editor_resource_picker.cpp
+++ b/editor/editor_resource_picker.cpp
@@ -387,8 +387,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
void EditorResourcePicker::set_create_options(Object *p_menu_node) {
_ensure_resource_menu();
// If a subclass implements this method, use it to replace all create items.
- if (get_script_instance() && get_script_instance()->has_method("_set_create_options")) {
- get_script_instance()->call("_set_create_options", p_menu_node);
+ if (GDVIRTUAL_CALL(_set_create_options, p_menu_node)) {
return;
}
@@ -444,8 +443,9 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) {
}
bool EditorResourcePicker::handle_menu_selected(int p_which) {
- if (get_script_instance() && get_script_instance()->has_method("_handle_menu_selected")) {
- return get_script_instance()->call("_handle_menu_selected", p_which);
+ bool success;
+ if (GDVIRTUAL_CALL(_handle_menu_selected, p_which, success)) {
+ return success;
}
return false;
@@ -706,8 +706,8 @@ void EditorResourcePicker::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_editable", "enable"), &EditorResourcePicker::set_editable);
ClassDB::bind_method(D_METHOD("is_editable"), &EditorResourcePicker::is_editable);
- ClassDB::add_virtual_method(get_class_static(), MethodInfo("_set_create_options", PropertyInfo(Variant::OBJECT, "menu_node")));
- ClassDB::add_virtual_method(get_class_static(), MethodInfo("_handle_menu_selected", PropertyInfo(Variant::INT, "id")));
+ GDVIRTUAL_BIND(_set_create_options, "menu_node");
+ GDVIRTUAL_BIND(_handle_menu_selected, "id");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type"), "set_base_type", "get_base_type");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource", PROPERTY_USAGE_NONE), "set_edited_resource", "get_edited_resource");
diff --git a/editor/editor_resource_picker.h b/editor/editor_resource_picker.h
index e693eeba14..8ffa52f14f 100644
--- a/editor/editor_resource_picker.h
+++ b/editor/editor_resource_picker.h
@@ -102,6 +102,9 @@ protected:
static void _bind_methods();
void _notification(int p_what);
+ GDVIRTUAL1(_set_create_options, Object *)
+ GDVIRTUAL1R(bool, _handle_menu_selected, int)
+
public:
static void clear_caches();
diff --git a/editor/plugins/text_control_editor_plugin.cpp b/editor/plugins/text_control_editor_plugin.cpp
index bef93c161a..a51b5d3e03 100644
--- a/editor/plugins/text_control_editor_plugin.cpp
+++ b/editor/plugins/text_control_editor_plugin.cpp
@@ -53,6 +53,10 @@ void TextControlEditor::_notification(int p_notification) {
}
}
+void TextControlEditor::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("_update_control"), &TextControlEditor::_update_control);
+}
+
void TextControlEditor::_find_resources(EditorFileSystemDirectory *p_dir) {
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
_find_resources(p_dir->get_subdir(i));
@@ -179,8 +183,13 @@ void TextControlEditor::_update_control() {
}
// Get other theme overrides.
+ font_size_list->set_block_signals(true);
font_size_list->set_value(edited_control->get_theme_font_size(edited_font_size));
+ font_size_list->set_block_signals(false);
+
+ outline_size_list->set_block_signals(true);
outline_size_list->set_value(edited_control->get_theme_constant("outline_size"));
+ outline_size_list->set_block_signals(false);
font_color_picker->set_pick_color(edited_control->get_theme_color(edited_color));
outline_color_picker->set_pick_color(edited_control->get_theme_color("font_outline_color"));
@@ -188,7 +197,6 @@ void TextControlEditor::_update_control() {
}
void TextControlEditor::_font_selected(int p_id) {
- _update_styles_menu();
_set_font();
}
@@ -197,70 +205,177 @@ void TextControlEditor::_font_style_selected(int p_id) {
}
void TextControlEditor::_set_font() {
- if (edited_control) {
- if (font_list->get_selected_id() == FONT_INFO_THEME_DEFAULT) {
- // Remove font override.
- edited_control->remove_theme_font_override(edited_font);
- return;
- } else if (font_list->get_selected_id() == FONT_INFO_USER_CUSTOM) {
- // Restore "custom_font".
- edited_control->add_theme_font_override(edited_font, custom_font);
- return;
- } else {
- // Load new font resource using selected name and style.
- String name = font_list->get_item_text(font_list->get_selected());
- String sty = font_style_list->get_item_text(font_style_list->get_selected());
- if (sty.is_empty()) {
- sty = "Default";
- }
- if (fonts.has(name)) {
- Ref<FontData> fd = ResourceLoader::load(fonts[name][sty]);
- if (fd.is_valid()) {
- Ref<Font> f;
- f.instantiate();
- f->add_data(fd);
- edited_control->add_theme_font_override(edited_font, f);
- }
+ if (!edited_control) {
+ return;
+ }
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Set Font"));
+
+ if (font_list->get_selected_id() == FONT_INFO_THEME_DEFAULT) {
+ // Remove font override.
+ ur->add_do_method(edited_control, "remove_theme_font_override", edited_font);
+ } else if (font_list->get_selected_id() == FONT_INFO_USER_CUSTOM) {
+ // Restore "custom_font".
+ ur->add_do_method(edited_control, "add_theme_font_override", edited_font, custom_font);
+ } else {
+ // Load new font resource using selected name and style.
+ String name = font_list->get_item_text(font_list->get_selected());
+ String style = font_style_list->get_item_text(font_style_list->get_selected());
+ if (style.is_empty()) {
+ style = "Default";
+ }
+
+ if (fonts.has(name)) {
+ Ref<FontData> fd = ResourceLoader::load(fonts[name][style]);
+ if (fd.is_valid()) {
+ Ref<Font> font;
+ font.instantiate();
+ font->add_data(fd);
+ ur->add_do_method(edited_control, "add_theme_font_override", edited_font, font);
}
}
}
+
+ if (edited_control->has_theme_font_override(edited_font)) {
+ ur->add_undo_method(edited_control, "add_theme_font_override", edited_font, edited_control->get_theme_font(edited_font));
+ } else {
+ ur->add_undo_method(edited_control, "remove_theme_font_override", edited_font);
+ }
+
+ ur->add_do_method(this, "_update_control");
+ ur->add_undo_method(this, "_update_control");
+
+ ur->commit_action();
}
void TextControlEditor::_font_size_selected(double p_size) {
- if (edited_control) {
- edited_control->add_theme_font_size_override(edited_font_size, p_size);
+ if (!edited_control) {
+ return;
+ }
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Set Font Size"));
+
+ ur->add_do_method(edited_control, "add_theme_font_size_override", edited_font_size, p_size);
+ if (edited_control->has_theme_font_size_override(edited_font_size)) {
+ ur->add_undo_method(edited_control, "add_theme_font_size_override", edited_font_size, edited_control->get_theme_font_size(edited_font_size));
+ } else {
+ ur->add_undo_method(edited_control, "remove_theme_font_size_override", edited_font_size);
}
+
+ ur->add_do_method(this, "_update_control");
+ ur->add_undo_method(this, "_update_control");
+
+ ur->commit_action();
}
void TextControlEditor::_outline_size_selected(double p_size) {
- if (edited_control) {
- edited_control->add_theme_constant_override("outline_size", p_size);
+ if (!edited_control) {
+ return;
+ }
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Set Font Outline Size"));
+
+ ur->add_do_method(edited_control, "add_theme_constant_override", "outline_size", p_size);
+ if (edited_control->has_theme_constant_override("outline_size")) {
+ ur->add_undo_method(edited_control, "add_theme_constant_override", "outline_size", edited_control->get_theme_constant("outline_size"));
+ } else {
+ ur->add_undo_method(edited_control, "remove_theme_constant_override", "outline_size");
}
+
+ ur->add_do_method(this, "_update_control");
+ ur->add_undo_method(this, "_update_control");
+
+ ur->commit_action();
}
void TextControlEditor::_font_color_changed(const Color &p_color) {
- if (edited_control) {
- edited_control->add_theme_color_override(edited_color, p_color);
+ if (!edited_control) {
+ return;
+ }
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Set Font Color"), UndoRedo::MERGE_ENDS);
+
+ ur->add_do_method(edited_control, "add_theme_color_override", edited_color, p_color);
+ if (edited_control->has_theme_color_override(edited_color)) {
+ ur->add_undo_method(edited_control, "add_theme_color_override", edited_color, edited_control->get_theme_color(edited_color));
+ } else {
+ ur->add_undo_method(edited_control, "remove_theme_color_override", edited_color);
}
+
+ ur->add_do_method(this, "_update_control");
+ ur->add_undo_method(this, "_update_control");
+
+ ur->commit_action();
}
void TextControlEditor::_outline_color_changed(const Color &p_color) {
- if (edited_control) {
- edited_control->add_theme_color_override("font_outline_color", p_color);
+ if (!edited_control) {
+ return;
+ }
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Set Font Outline Color"), UndoRedo::MERGE_ENDS);
+
+ ur->add_do_method(edited_control, "add_theme_color_override", "font_outline_color", p_color);
+ if (edited_control->has_theme_color_override("font_outline_color")) {
+ ur->add_undo_method(edited_control, "add_theme_color_override", "font_outline_color", edited_control->get_theme_color("font_outline_color"));
+ } else {
+ ur->add_undo_method(edited_control, "remove_theme_color_override", "font_outline_color");
}
+
+ ur->add_do_method(this, "_update_control");
+ ur->add_undo_method(this, "_update_control");
+
+ ur->commit_action();
}
void TextControlEditor::_clear_formatting() {
- if (edited_control) {
- edited_control->begin_bulk_theme_override();
- edited_control->remove_theme_font_override(edited_font);
- edited_control->remove_theme_font_size_override(edited_font_size);
- edited_control->remove_theme_color_override(edited_color);
- edited_control->remove_theme_color_override("font_outline_color");
- edited_control->remove_theme_constant_override("outline_size");
- edited_control->end_bulk_theme_override();
- _update_control();
+ if (!edited_control) {
+ return;
+ }
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Clear Control Formatting"));
+
+ ur->add_do_method(edited_control, "begin_bulk_theme_override");
+ ur->add_undo_method(edited_control, "begin_bulk_theme_override");
+
+ ur->add_do_method(edited_control, "remove_theme_font_override", edited_font);
+ if (edited_control->has_theme_font_override(edited_font)) {
+ ur->add_undo_method(edited_control, "add_theme_font_override", edited_font, edited_control->get_theme_font(edited_font));
+ }
+
+ ur->add_do_method(edited_control, "remove_theme_font_size_override", edited_font_size);
+ if (edited_control->has_theme_font_size_override(edited_font_size)) {
+ ur->add_undo_method(edited_control, "add_theme_font_size_override", edited_font_size, edited_control->get_theme_font_size(edited_font_size));
+ }
+
+ ur->add_do_method(edited_control, "remove_theme_color_override", edited_color);
+ if (edited_control->has_theme_color_override(edited_color)) {
+ ur->add_undo_method(edited_control, "add_theme_color_override", edited_color, edited_control->get_theme_color(edited_color));
+ }
+
+ ur->add_do_method(edited_control, "remove_theme_color_override", "font_outline_color");
+ if (edited_control->has_theme_color_override("font_outline_color")) {
+ ur->add_undo_method(edited_control, "add_theme_color_override", "font_outline_color", edited_control->get_theme_color("font_outline_color"));
+ }
+
+ ur->add_do_method(edited_control, "remove_theme_constant_override", "outline_size");
+ if (edited_control->has_theme_constant_override("outline_size")) {
+ ur->add_undo_method(edited_control, "add_theme_constant_override", "outline_size", edited_control->get_theme_constant("outline_size"));
}
+
+ ur->add_do_method(edited_control, "end_bulk_theme_override");
+ ur->add_undo_method(edited_control, "end_bulk_theme_override");
+
+ ur->add_do_method(this, "_update_control");
+ ur->add_undo_method(this, "_update_control");
+
+ ur->commit_action();
}
void TextControlEditor::edit(Object *p_object) {
diff --git a/editor/plugins/text_control_editor_plugin.h b/editor/plugins/text_control_editor_plugin.h
index d3a4ff5ef9..d284a30f16 100644
--- a/editor/plugins/text_control_editor_plugin.h
+++ b/editor/plugins/text_control_editor_plugin.h
@@ -70,7 +70,7 @@ class TextControlEditor : public HBoxContainer {
protected:
void _notification(int p_notification);
- static void _bind_methods(){};
+ static void _bind_methods();
void _find_resources(EditorFileSystemDirectory *p_dir);
void _reload_fonts(const String &p_path);
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 92c770429b..3701a8139b 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -773,8 +773,9 @@ bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos)
}
bool GraphEdit::is_in_input_hotzone(GraphNode *p_graph_node, int p_slot_index, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
- if (get_script_instance() && get_script_instance()->has_method("_is_in_input_hotzone")) {
- return get_script_instance()->call("_is_in_input_hotzone", p_graph_node, p_slot_index, p_mouse_pos);
+ bool success;
+ if (GDVIRTUAL_CALL(_is_in_input_hotzone, p_graph_node, p_slot_index, p_mouse_pos, success)) {
+ return success;
} else {
Vector2 pos = p_graph_node->get_connection_input_position(p_slot_index) + p_graph_node->get_position();
return is_in_port_hotzone(pos / zoom, p_mouse_pos, p_port_size, true);
@@ -782,8 +783,9 @@ bool GraphEdit::is_in_input_hotzone(GraphNode *p_graph_node, int p_slot_index, c
}
bool GraphEdit::is_in_output_hotzone(GraphNode *p_graph_node, int p_slot_index, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
- if (get_script_instance() && get_script_instance()->has_method("_is_in_output_hotzone")) {
- return get_script_instance()->call("_is_in_output_hotzone", p_graph_node, p_slot_index, p_mouse_pos);
+ bool success;
+ if (GDVIRTUAL_CALL(_is_in_output_hotzone, p_graph_node, p_slot_index, p_mouse_pos, success)) {
+ return success;
} else {
Vector2 pos = p_graph_node->get_connection_output_position(p_slot_index) + p_graph_node->get_position();
return is_in_port_hotzone(pos / zoom, p_mouse_pos, p_port_size, false);
@@ -2227,8 +2229,8 @@ void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_right_disconnects_enabled"), &GraphEdit::is_right_disconnects_enabled);
ClassDB::bind_method(D_METHOD("_update_scroll_offset"), &GraphEdit::_update_scroll_offset);
- ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "_is_in_input_hotzone", PropertyInfo(Variant::OBJECT, "graph_node"), PropertyInfo(Variant::INT, "slot_index"), PropertyInfo(Variant::VECTOR2, "mouse_position")));
- ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "_is_in_output_hotzone", PropertyInfo(Variant::OBJECT, "graph_node"), PropertyInfo(Variant::INT, "slot_index"), PropertyInfo(Variant::VECTOR2, "mouse_position")));
+ GDVIRTUAL_BIND(_is_in_input_hotzone, "graph_node", "slot_index", "mouse_position");
+ GDVIRTUAL_BIND(_is_in_output_hotzone, "graph_node", "slot_index", "mouse_position");
ClassDB::bind_method(D_METHOD("get_zoom_hbox"), &GraphEdit::get_zoom_hbox);
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index f1c4e95e38..145e0dcc59 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -261,6 +261,8 @@ protected:
void _notification(int p_what);
GDVIRTUAL2RC(Vector<Vector2>, _get_connection_line, Vector2, Vector2)
+ GDVIRTUAL3R(bool, _is_in_input_hotzone, Object *, int, Vector2)
+ GDVIRTUAL3R(bool, _is_in_output_hotzone, Object *, int, Vector2)
public:
Error connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index fe25d027f6..348a0324f4 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -2363,6 +2363,7 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub
// Then remove the provided item itself.
p_item->parent->subitems.erase(p_item);
}
+ memdelete(p_item);
}
void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color, InlineAlignment p_alignment) {
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 3e63ba7869..abbd7ba5a0 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -372,8 +372,6 @@ void Viewport::_sub_window_remove(Window *p_window) {
void Viewport::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- gui.embedding_subwindows = gui.embed_subwindows_hint;
-
if (get_parent()) {
parent = get_parent()->get_viewport();
RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid());
@@ -2546,7 +2544,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
bool click_on_window = false;
for (int i = gui.sub_windows.size() - 1; i >= 0; i--) {
- SubWindow &sw = gui.sub_windows.write[i];
+ SubWindow sw = gui.sub_windows.write[i];
// Clicked inside window?
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 57e1100521..a3127811f5 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -362,7 +362,6 @@ private:
bool dragging = false;
bool drag_successful = false;
bool embed_subwindows_hint = false;
- bool embedding_subwindows = false;
Window *subwindow_focused = nullptr;
SubWindowDrag subwindow_drag = SUB_WINDOW_DRAG_DISABLED;
@@ -373,7 +372,7 @@ private:
SubWindowResize subwindow_resize_mode;
Rect2i subwindow_resize_from_rect;
- Vector<SubWindow> sub_windows;
+ Vector<SubWindow> sub_windows; // Don't obtain references or pointers to the elements, as their location can change.
} gui;
DefaultCanvasItemTextureFilter default_canvas_item_texture_filter = DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR;