summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.mailmap3
-rw-r--r--SConstruct7
-rw-r--r--editor/code_editor.cpp385
-rw-r--r--editor/code_editor.h56
-rw-r--r--editor/plugins/script_editor_plugin.cpp12
-rw-r--r--editor/plugins/script_text_editor.cpp1
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp38
-rw-r--r--methods.py30
-rw-r--r--scene/gui/text_edit.cpp13
-rw-r--r--scene/gui/viewport_container.cpp28
-rw-r--r--scene/gui/viewport_container.h1
11 files changed, 100 insertions, 474 deletions
diff --git a/.mailmap b/.mailmap
index b37cd2884d..aa2e0911ec 100644
--- a/.mailmap
+++ b/.mailmap
@@ -8,6 +8,9 @@ Bastiaan Olij <mux213@gmail.com>
Bernhard Liebl <poke1024@gmx.de>
Bernhard Liebl <poke1024@gmx.org>
Geequlim <geequlim@gmail.com>
+Hugo Locurcio <hugo.locurcio@hugo.pro>
+Hugo Locurcio <hugo.locurcio@hugo.pro> <hugo.l@openmailbox.org>
+Hugo Locurcio <hugo.locurcio@hugo.pro> <Calinou@users.noreply.github.com>
Ignacio Etcheverry <ignalfonsore@gmail.com>
Indah Sylvia <ISylvox@yahoo.com>
Jakub Grzesik <kubecz3k@gmail.com>
diff --git a/SConstruct b/SConstruct
index 7e82e582d0..dcf8134c93 100644
--- a/SConstruct
+++ b/SConstruct
@@ -498,7 +498,12 @@ node_count_interval = 1
node_pruning = 8 # Number of nodes to process before prunning the cache
if ('env' in locals()):
node_count_fname = str(env.Dir('#')) + '/.scons_node_count'
-show_progress = env['progress']
+# Progress reporting is not available in non-TTY environments since it
+# messes with the output (for example, when writing to a file)
+if sys.stdout.isatty():
+ show_progress = env['progress']
+else:
+ show_progress = False
import time, math
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 3e079cb3ca..061f6ccc33 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -577,391 +577,6 @@ FindReplaceBar::FindReplaceBar() {
selection_only->connect("toggled", this, "_search_options_changed");
}
-void FindReplaceDialog::popup_search() {
-
- set_title(TTR("Search"));
- replace_mc->hide();
- replace_label->hide();
- replace_vb->hide();
- skip->hide();
- popup_centered(Point2(300, 190));
- get_ok()->set_text(TTR("Find"));
- search_text->grab_focus();
- if (text_edit->is_selection_active() && (text_edit->get_selection_from_line() == text_edit->get_selection_to_line())) {
-
- search_text->set_text(text_edit->get_selection_text());
- }
- search_text->select_all();
-
- error_label->set_text("");
-}
-
-void FindReplaceDialog::popup_replace() {
-
- set_title(TTR("Replace"));
- bool do_selection = (text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line());
-
- set_replace_selection_only(do_selection);
-
- if (!do_selection && text_edit->is_selection_active()) {
- search_text->set_text(text_edit->get_selection_text());
- }
-
- replace_mc->show();
- replace_label->show();
- replace_vb->show();
- popup_centered(Point2(300, 300));
- if (search_text->get_text() != "" && replace_text->get_text() == "") {
- search_text->select(0, 0);
- replace_text->grab_focus();
- } else {
- search_text->grab_focus();
- search_text->select_all();
- }
- error_label->set_text("");
-
- if (prompt->is_pressed()) {
- skip->show();
- get_ok()->set_text(TTR("Next"));
- selection_only->set_disabled(true);
-
- } else {
- skip->hide();
- get_ok()->set_text(TTR("Replace"));
- selection_only->set_disabled(false);
- }
-}
-
-void FindReplaceDialog::_search_callback() {
-
- if (is_replace_mode())
- _replace();
- else
- _search();
-}
-
-void FindReplaceDialog::_replace_skip_callback() {
-
- _search();
-}
-
-void FindReplaceDialog::_replace() {
-
- text_edit->begin_complex_operation();
- if (is_replace_all_mode()) {
-
- //line as x so it gets priority in comparison, column as y
- Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column());
- Point2i prev_match = Point2(-1, -1);
-
- bool selection_enabled = text_edit->is_selection_active();
- Point2i selection_begin, selection_end;
- if (selection_enabled) {
- selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
- selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
- }
- int vsval = text_edit->get_v_scroll();
- //int hsval = text_edit->get_h_scroll();
-
- text_edit->cursor_set_line(0);
- text_edit->cursor_set_column(0);
-
- int rc = 0;
-
- while (_search()) {
-
- if (!text_edit->is_selection_active()) {
- //search selects
- break;
- }
-
- //replace area
- Point2i match_from(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
- Point2i match_to(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
-
- if (match_from < prev_match)
- break; //done
-
- prev_match = match_to;
-
- if (selection_enabled && is_replace_selection_only()) {
-
- if (match_from < selection_begin || match_to > selection_end)
- continue;
-
- //replace but adjust selection bounds
-
- text_edit->insert_text_at_cursor(get_replace_text());
- if (match_to.x == selection_end.x)
- selection_end.y += get_replace_text().length() - get_search_text().length();
- } else {
- //just replace
- text_edit->insert_text_at_cursor(get_replace_text());
- }
- rc++;
- }
- //restore editor state (selection, cursor, scroll)
- text_edit->cursor_set_line(orig_cursor.x);
- text_edit->cursor_set_column(orig_cursor.y);
-
- if (selection_enabled && is_replace_selection_only()) {
- //reselect
- text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y);
- } else {
- text_edit->deselect();
- }
-
- text_edit->set_v_scroll(vsval);
- //text_edit->set_h_scroll(hsval);
- error_label->set_text(vformat(TTR("Replaced %d occurrence(s)."), rc));
-
- //hide();
- } else {
-
- if (text_edit->get_selection_text() == get_search_text()) {
-
- text_edit->insert_text_at_cursor(get_replace_text());
- }
-
- _search();
- }
- text_edit->end_complex_operation();
-}
-
-bool FindReplaceDialog::_search() {
-
- String text = get_search_text();
- uint32_t flags = 0;
-
- if (is_whole_words())
- flags |= TextEdit::SEARCH_WHOLE_WORDS;
- if (is_case_sensitive())
- flags |= TextEdit::SEARCH_MATCH_CASE;
- if (is_backwards())
- flags |= TextEdit::SEARCH_BACKWARDS;
-
- int line = text_edit->cursor_get_line(), col = text_edit->cursor_get_column();
-
- if (is_backwards()) {
- col -= 1;
- if (col < 0) {
- line -= 1;
- if (line < 0) {
- line = text_edit->get_line_count() - 1;
- }
- col = text_edit->get_line(line).length();
- }
- }
- bool found = text_edit->search(text, flags, line, col, line, col);
-
- if (found) {
- // print_line("found");
- text_edit->unfold_line(line);
- text_edit->cursor_set_line(line);
- if (is_backwards())
- text_edit->cursor_set_column(col);
- else
- text_edit->cursor_set_column(col + text.length());
- text_edit->select(line, col, line, col + text.length());
- set_error("");
- return true;
- } else {
-
- set_error(TTR("Not found!"));
- return false;
- }
-}
-
-void FindReplaceDialog::_prompt_changed() {
-
- if (prompt->is_pressed()) {
- skip->show();
- get_ok()->set_text(TTR("Next"));
- selection_only->set_disabled(true);
-
- } else {
- skip->hide();
- get_ok()->set_text(TTR("Replace"));
- selection_only->set_disabled(false);
- }
-}
-
-void FindReplaceDialog::_skip_pressed() {
-
- _replace_skip_callback();
-}
-
-bool FindReplaceDialog::is_replace_mode() const {
-
- return replace_text->is_visible_in_tree();
-}
-
-bool FindReplaceDialog::is_replace_all_mode() const {
-
- return !prompt->is_pressed();
-}
-
-bool FindReplaceDialog::is_replace_selection_only() const {
-
- return selection_only->is_pressed();
-}
-void FindReplaceDialog::set_replace_selection_only(bool p_enable) {
-
- selection_only->set_pressed(p_enable);
-}
-
-void FindReplaceDialog::ok_pressed() {
-
- _search_callback();
-}
-
-void FindReplaceDialog::_search_text_entered(const String &p_text) {
-
- if (replace_text->is_visible_in_tree())
- return;
- emit_signal("search");
- _search();
-}
-
-void FindReplaceDialog::_replace_text_entered(const String &p_text) {
-
- if (!replace_text->is_visible_in_tree())
- return;
-
- emit_signal("search");
- _replace();
-}
-
-String FindReplaceDialog::get_search_text() const {
-
- return search_text->get_text();
-}
-String FindReplaceDialog::get_replace_text() const {
-
- return replace_text->get_text();
-}
-bool FindReplaceDialog::is_whole_words() const {
-
- return whole_words->is_pressed();
-}
-bool FindReplaceDialog::is_case_sensitive() const {
-
- return case_sensitive->is_pressed();
-}
-bool FindReplaceDialog::is_backwards() const {
-
- return backwards->is_pressed();
-}
-
-void FindReplaceDialog::set_error(const String &p_error) {
-
- error_label->set_text(p_error);
-}
-
-void FindReplaceDialog::set_text_edit(TextEdit *p_text_edit) {
-
- text_edit = p_text_edit;
-}
-
-void FindReplaceDialog::search_next() {
- _search();
-}
-
-void FindReplaceDialog::_bind_methods() {
-
- ClassDB::bind_method("_search_text_entered", &FindReplaceDialog::_search_text_entered);
- ClassDB::bind_method("_replace_text_entered", &FindReplaceDialog::_replace_text_entered);
- ClassDB::bind_method("_prompt_changed", &FindReplaceDialog::_prompt_changed);
- ClassDB::bind_method("_skip_pressed", &FindReplaceDialog::_skip_pressed);
- ADD_SIGNAL(MethodInfo("search"));
- ADD_SIGNAL(MethodInfo("skip"));
-}
-
-FindReplaceDialog::FindReplaceDialog() {
-
- set_self_modulate(Color(1, 1, 1, 0.8));
-
- VBoxContainer *vb = memnew(VBoxContainer);
- add_child(vb);
-
- search_text = memnew(LineEdit);
- vb->add_margin_child(TTR("Search"), search_text);
- search_text->connect("text_entered", this, "_search_text_entered");
-
- replace_label = memnew(Label);
- replace_label->set_text(TTR("Replace By"));
- vb->add_child(replace_label);
- replace_mc = memnew(MarginContainer);
- vb->add_child(replace_mc);
-
- replace_text = memnew(LineEdit);
- replace_text->set_anchor(MARGIN_RIGHT, ANCHOR_END);
- replace_text->set_begin(Point2(15, 132));
- replace_text->set_end(Point2(-15, 135));
-
- replace_mc->add_child(replace_text);
-
- replace_text->connect("text_entered", this, "_replace_text_entered");
-
- MarginContainer *opt_mg = memnew(MarginContainer);
- vb->add_child(opt_mg);
- VBoxContainer *svb = memnew(VBoxContainer);
- opt_mg->add_child(svb);
-
- svb->add_child(memnew(Label));
-
- whole_words = memnew(CheckButton);
- whole_words->set_text(TTR("Whole Words"));
- svb->add_child(whole_words);
-
- case_sensitive = memnew(CheckButton);
- case_sensitive->set_text(TTR("Case Sensitive"));
- svb->add_child(case_sensitive);
-
- backwards = memnew(CheckButton);
- backwards->set_text(TTR("Backwards"));
- svb->add_child(backwards);
-
- opt_mg = memnew(MarginContainer);
- vb->add_child(opt_mg);
- VBoxContainer *rvb = memnew(VBoxContainer);
- opt_mg->add_child(rvb);
- replace_vb = rvb;
- //rvb ->add_child(memnew(HSeparator));
- rvb->add_child(memnew(Label));
-
- prompt = memnew(CheckButton);
- prompt->set_text(TTR("Prompt On Replace"));
- rvb->add_child(prompt);
- prompt->connect("pressed", this, "_prompt_changed");
-
- selection_only = memnew(CheckButton);
- selection_only->set_text(TTR("Selection Only"));
- rvb->add_child(selection_only);
-
- int margin = get_constant("margin", "Dialogs");
- int button_margin = get_constant("button_margin", "Dialogs");
-
- skip = memnew(Button);
- skip->set_anchor(MARGIN_LEFT, ANCHOR_END);
- skip->set_anchor(MARGIN_TOP, ANCHOR_END);
- skip->set_anchor(MARGIN_RIGHT, ANCHOR_END);
- skip->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
- skip->set_begin(Point2(-70, -button_margin));
- skip->set_end(Point2(-10, -margin));
- skip->set_text(TTR("Skip"));
- add_child(skip);
- skip->connect("pressed", this, "_skip_pressed");
-
- error_label = memnew(Label);
- error_label->set_align(Label::ALIGN_CENTER);
- error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
-
- vb->add_child(error_label);
-
- set_hide_on_ok(false);
-}
-
/*** CODE EDITOR ****/
void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) {
diff --git a/editor/code_editor.h b/editor/code_editor.h
index f735631ef6..2e6340acc0 100644
--- a/editor/code_editor.h
+++ b/editor/code_editor.h
@@ -131,62 +131,6 @@ public:
FindReplaceBar();
};
-class FindReplaceDialog : public ConfirmationDialog {
-
- GDCLASS(FindReplaceDialog, ConfirmationDialog);
-
- LineEdit *search_text;
- LineEdit *replace_text;
- CheckButton *whole_words;
- CheckButton *case_sensitive;
- CheckButton *backwards;
- CheckButton *prompt;
- CheckButton *selection_only;
- Button *skip;
- Label *error_label;
- MarginContainer *replace_mc;
- Label *replace_label;
- VBoxContainer *replace_vb;
-
- void _search_text_entered(const String &p_text);
- void _replace_text_entered(const String &p_text);
- void _prompt_changed();
- void _skip_pressed();
-
- TextEdit *text_edit;
-
-protected:
- void _search_callback();
- void _replace_skip_callback();
-
- bool _search();
- void _replace();
-
- virtual void ok_pressed();
- static void _bind_methods();
-
-public:
- String get_search_text() const;
- String get_replace_text() const;
- bool is_whole_words() const;
- bool is_case_sensitive() const;
- bool is_backwards() const;
- bool is_replace_mode() const;
- bool is_replace_all_mode() const;
- bool is_replace_selection_only() const;
- void set_replace_selection_only(bool p_enable);
-
- void set_error(const String &p_error);
-
- void popup_search();
- void popup_replace();
-
- void set_text_edit(TextEdit *p_text_edit);
-
- void search_next();
- FindReplaceDialog();
-};
-
typedef void (*CodeTextEditorCodeCompleteFunc)(void *p_ud, const String &p_code, List<String> *r_options, bool &r_forced);
class CodeTextEditor : public VBoxContainer {
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index f99768400f..d18422c0c0 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1672,10 +1672,14 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change");
+ const bool should_open = open_dominant || !EditorNode::get_singleton()->is_changing_scene();
+
if (p_script->get_language()->overrides_external_editor()) {
- Error err = p_script->get_language()->open_in_external_editor(p_script, p_line >= 0 ? p_line : 0, p_col);
- if (err != OK)
- ERR_PRINT("Couldn't open script in the overridden external text editor");
+ if (should_open) {
+ Error err = p_script->get_language()->open_in_external_editor(p_script, p_line >= 0 ? p_line : 0, p_col);
+ if (err != OK)
+ ERR_PRINT("Couldn't open script in the overridden external text editor");
+ }
return false;
}
@@ -1726,7 +1730,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
if (se->get_edited_script() == p_script) {
- if (open_dominant || !EditorNode::get_singleton()->is_changing_scene()) {
+ if (should_open) {
if (tab_container->get_current_tab() != i) {
_go_to_tab(i);
script_list->select(script_list->find_metadata(i));
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 2a6b4ee173..dffb98e488 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -231,6 +231,7 @@ void ScriptTextEditor::_set_theme_for_script() {
text_edit->add_keyword_color(n, colors_cache.type_color);
}
+ _update_member_keywords();
//colorize comments
List<String> comments;
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index cef1da1d06..e2ea853052 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -2017,6 +2017,20 @@ Point2i SpatialEditorViewport::_get_warped_mouse_motion(const Ref<InputEventMous
return relative;
}
+static bool is_shortcut_pressed(const String &p_path) {
+ Ref<ShortCut> shortcut = ED_GET_SHORTCUT(p_path);
+ if (shortcut.is_null()) {
+ return false;
+ }
+ InputEventKey *k = Object::cast_to<InputEventKey>(shortcut->get_shortcut().ptr());
+ if (k == NULL) {
+ return false;
+ }
+ const Input &input = *Input::get_singleton();
+ int scancode = k->get_scancode();
+ return input.is_key_pressed(scancode);
+}
+
void SpatialEditorViewport::_update_freelook(real_t delta) {
if (!is_freelook_active()) {
@@ -2027,38 +2041,28 @@ void SpatialEditorViewport::_update_freelook(real_t delta) {
Vector3 right = camera->get_transform().basis.xform(Vector3(1, 0, 0));
Vector3 up = camera->get_transform().basis.xform(Vector3(0, 1, 0));
- int key_left = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_left")->get_shortcut().ptr())->get_scancode();
- int key_right = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_right")->get_shortcut().ptr())->get_scancode();
- int key_forward = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_forward")->get_shortcut().ptr())->get_scancode();
- int key_backwards = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_backwards")->get_shortcut().ptr())->get_scancode();
- int key_up = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_up")->get_shortcut().ptr())->get_scancode();
- int key_down = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_down")->get_shortcut().ptr())->get_scancode();
- int key_speed_modifier = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_speed_modifier")->get_shortcut().ptr())->get_scancode();
-
Vector3 direction;
bool speed_modifier = false;
- const Input &input = *Input::get_singleton();
-
- if (input.is_key_pressed(key_left)) {
+ if (is_shortcut_pressed("spatial_editor/freelook_left")) {
direction -= right;
}
- if (input.is_key_pressed(key_right)) {
+ if (is_shortcut_pressed("spatial_editor/freelook_right")) {
direction += right;
}
- if (input.is_key_pressed(key_forward)) {
+ if (is_shortcut_pressed("spatial_editor/freelook_forward")) {
direction += forward;
}
- if (input.is_key_pressed(key_backwards)) {
+ if (is_shortcut_pressed("spatial_editor/freelook_backwards")) {
direction -= forward;
}
- if (input.is_key_pressed(key_up)) {
+ if (is_shortcut_pressed("spatial_editor/freelook_up")) {
direction += up;
}
- if (input.is_key_pressed(key_down)) {
+ if (is_shortcut_pressed("spatial_editor/freelook_down")) {
direction -= up;
}
- if (input.is_key_pressed(key_speed_modifier)) {
+ if (is_shortcut_pressed("spatial_editor/freelook_speed_modifier")) {
speed_modifier = true;
}
diff --git a/methods.py b/methods.py
index fbdac8a966..3ffe8cb310 100644
--- a/methods.py
+++ b/methods.py
@@ -1549,18 +1549,26 @@ def save_active_platforms(apnames, ap):
def no_verbose(sys, env):
- # If the output is not a terminal, do nothing
- if not sys.stdout.isatty():
- return
-
colors = {}
- colors['cyan'] = '\033[96m'
- colors['purple'] = '\033[95m'
- colors['blue'] = '\033[94m'
- colors['green'] = '\033[92m'
- colors['yellow'] = '\033[93m'
- colors['red'] = '\033[91m'
- colors['end'] = '\033[0m'
+
+ # Colors are disabled in non-TTY environments such as pipes. This means
+ # that if output is redirected to a file, it will not contain color codes
+ if sys.stdout.isatty():
+ colors['cyan'] = '\033[96m'
+ colors['purple'] = '\033[95m'
+ colors['blue'] = '\033[94m'
+ colors['green'] = '\033[92m'
+ colors['yellow'] = '\033[93m'
+ colors['red'] = '\033[91m'
+ colors['end'] = '\033[0m'
+ else:
+ colors['cyan'] = ''
+ colors['purple'] = ''
+ colors['blue'] = ''
+ colors['green'] = ''
+ colors['yellow'] = ''
+ colors['red'] = ''
+ colors['end'] = ''
compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
java_compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 439b0ce605..4d87a6b3ba 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1119,6 +1119,19 @@ void TextEdit::_notification(int p_what) {
if ((char_ofs + char_margin) < xmargin_beg) {
char_ofs += char_w;
+
+ // line highlighting handle horizontal clipping
+ if (line == cursor.line && highlight_current_line) {
+ // char next to margin is skipped
+ if ((char_ofs + char_margin) > xmargin_beg) {
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, (char_ofs + char_margin) - (xmargin_beg + ofs_x), get_row_height()), cache.current_line_color);
+ }
+
+ // end of line when last char is skipped
+ if (j == str.length() - 1) {
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color);
+ }
+ }
continue;
}
diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp
index af849589cf..ac5e6020eb 100644
--- a/scene/gui/viewport_container.cpp
+++ b/scene/gui/viewport_container.cpp
@@ -30,6 +30,7 @@
#include "viewport_container.h"
+#include "core/engine.h"
#include "scene/main/viewport.h"
Size2 ViewportContainer::get_minimum_size() const {
@@ -139,8 +140,34 @@ void ViewportContainer::_notification(int p_what) {
}
}
+void ViewportContainer::_input(const Ref<InputEvent> &p_event) {
+
+ if (Engine::get_singleton()->is_editor_hint())
+ return;
+
+ Transform2D xform = get_global_transform();
+
+ if (stretch) {
+ Transform2D scale_xf;
+ scale_xf.scale(Vector2(shrink, shrink));
+ xform *= scale_xf;
+ }
+
+ Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
+
+ for (int i = 0; i < get_child_count(); i++) {
+
+ Viewport *c = Object::cast_to<Viewport>(get_child(i));
+ if (!c || c->is_input_disabled())
+ continue;
+
+ c->input(ev);
+ }
+}
+
void ViewportContainer::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input);
ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch);
ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled);
@@ -155,4 +182,5 @@ ViewportContainer::ViewportContainer() {
stretch = false;
shrink = 1;
+ set_process_input(true);
}
diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h
index cd8b4dd5c1..45c4cd03a1 100644
--- a/scene/gui/viewport_container.h
+++ b/scene/gui/viewport_container.h
@@ -48,6 +48,7 @@ public:
void set_stretch(bool p_enable);
bool is_stretch_enabled() const;
+ void _input(const Ref<InputEvent> &p_event);
void set_stretch_shrink(int p_shrink);
int get_stretch_shrink() const;