diff options
-rw-r--r-- | .mailmap | 3 | ||||
-rw-r--r-- | SConstruct | 7 | ||||
-rw-r--r-- | doc/classes/AnimationPlayer.xml | 3 | ||||
-rw-r--r-- | editor/plugins/animation_player_editor_plugin.cpp | 24 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 24 | ||||
-rw-r--r-- | editor/plugins/cube_grid_theme_editor_plugin.cpp | 3 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 38 | ||||
-rw-r--r-- | editor/plugins/tile_set_editor_plugin.cpp | 3 | ||||
-rw-r--r-- | editor/property_editor.cpp | 2 | ||||
-rw-r--r-- | methods.py | 30 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 7 | ||||
-rw-r--r-- | scene/animation/animation_player.cpp | 28 | ||||
-rw-r--r-- | scene/animation/animation_player.h | 2 | ||||
-rw-r--r-- | scene/gui/control.h | 4 | ||||
-rw-r--r-- | scene/gui/viewport_container.cpp | 28 | ||||
-rw-r--r-- | scene/gui/viewport_container.h | 1 |
16 files changed, 139 insertions, 68 deletions
@@ -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/doc/classes/AnimationPlayer.xml b/doc/classes/AnimationPlayer.xml index 8808e324d6..46602911d2 100644 --- a/doc/classes/AnimationPlayer.xml +++ b/doc/classes/AnimationPlayer.xml @@ -208,6 +208,9 @@ </method> </methods> <members> + <member name="assigned_animation" type="String" setter="set_assigned_animation" getter="get_assigned_animation"> + If playing, the current animation; otherwise, the animation last played. When set, would change the animation, but would not play it unless currently playing. See also [member current_animation]. + </member> <member name="autoplay" type="String" setter="set_autoplay" getter="get_autoplay"> The name of the animation to play when the scene loads. Default value: [code]""[/code]. </member> diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 3593493d11..d071d43cb7 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -73,7 +73,7 @@ void AnimationPlayerEditor::_notification(int p_what) { if (player->is_playing()) { { - String animname = player->get_current_animation(); + String animname = player->get_assigned_animation(); if (player->has_animation(animname)) { Ref<Animation> anim = player->get_animation(animname); @@ -186,7 +186,7 @@ void AnimationPlayerEditor::_play_pressed() { if (current != "") { - if (current == player->get_current_animation()) + if (current == player->get_assigned_animation()) player->stop(); //so it wont blend with itself player->play(current); } @@ -209,7 +209,7 @@ void AnimationPlayerEditor::_play_from_pressed() { float time = player->get_current_animation_position(); - if (current == player->get_current_animation() && player->is_playing()) { + if (current == player->get_assigned_animation() && player->is_playing()) { player->stop(); //so it wont blend with itself } @@ -234,7 +234,7 @@ void AnimationPlayerEditor::_play_bw_pressed() { if (current != "") { - if (current == player->get_current_animation()) + if (current == player->get_assigned_animation()) player->stop(); //so it wont blend with itself player->play(current, -1, -1, true); } @@ -256,7 +256,7 @@ void AnimationPlayerEditor::_play_bw_from_pressed() { if (current != "") { float time = player->get_current_animation_position(); - if (current == player->get_current_animation()) + if (current == player->get_assigned_animation()) player->stop(); //so it wont blend with itself player->play(current, -1, -1, true); @@ -299,7 +299,7 @@ void AnimationPlayerEditor::_animation_selected(int p_which) { if (current != "") { - // player->set_current_animation(current, false); + player->set_assigned_animation(current); Ref<Animation> anim = player->get_animation(current); { @@ -654,9 +654,7 @@ Dictionary AnimationPlayerEditor::get_state() const { d["visible"] = is_visible_in_tree(); if (EditorNode::get_singleton()->get_edited_scene() && is_visible_in_tree() && player) { d["player"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(player); - } - if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - d["animation"] = animation->get_item_text(animation->get_selected()); + d["animation"] = player->get_assigned_animation(); } return d; @@ -784,7 +782,7 @@ void AnimationPlayerEditor::_update_animation() { } scale->set_text(String::num(player->get_speed_scale(), 2)); - String current = player->get_current_animation(); + String current = player->get_assigned_animation(); for (int i = 0; i < animation->get_item_count(); i++) { @@ -831,7 +829,7 @@ void AnimationPlayerEditor::_update_player() { else animation->add_item(E->get()); - if (player->get_current_animation() == E->get()) + if (player->get_assigned_animation() == E->get()) active_idx = animation->get_item_count() - 1; } @@ -988,7 +986,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { }; updating = true; - String current = player->get_current_animation(); //animation->get_item_text( animation->get_selected() ); + String current = player->get_assigned_animation(); //animation->get_item_text( animation->get_selected() ); if (current == "" || !player->has_animation(current)) { updating = false; current = ""; @@ -1338,7 +1336,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_1() { void AnimationPlayerEditor::_prepare_onion_layers_2() { - Ref<Animation> anim = player->get_animation(player->get_current_animation()); + Ref<Animation> anim = player->get_animation(player->get_assigned_animation()); if (!anim.is_valid()) return; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index bd5e5c7355..f6834732a3 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1999,29 +1999,29 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { switch (drag) { case DRAG_ANCHOR_TOP_LEFT: - if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x); - if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y); + if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x, false); + if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y, false); continue; break; case DRAG_ANCHOR_TOP_RIGHT: - if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x); - if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y); + if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x, false); + if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y, false); continue; break; case DRAG_ANCHOR_BOTTOM_RIGHT: - if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x); - if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y); + if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x, false); + if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y, false); break; case DRAG_ANCHOR_BOTTOM_LEFT: - if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x); - if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y); + if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x, false); + if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y, false); continue; break; case DRAG_ANCHOR_ALL: - if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x); - if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x); - if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y); - if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y); + if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x, false); + if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x, false); + if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y, false); + if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y, false); continue; break; } diff --git a/editor/plugins/cube_grid_theme_editor_plugin.cpp b/editor/plugins/cube_grid_theme_editor_plugin.cpp index 23465a654d..81f45b9f55 100644 --- a/editor/plugins/cube_grid_theme_editor_plugin.cpp +++ b/editor/plugins/cube_grid_theme_editor_plugin.cpp @@ -290,8 +290,7 @@ MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) { theme_editor = memnew(MeshLibraryEditor(p_node)); p_node->get_viewport()->add_child(theme_editor); - theme_editor->set_anchors_and_margins_preset(Control::PRESET_WIDE); - theme_editor->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_BEGIN); + theme_editor->set_anchors_and_margins_preset(Control::PRESET_TOP_WIDE); theme_editor->set_end(Point2(0, 22)); theme_editor->hide(); } 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/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 612bdb1d2a..f47f9e55bb 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -304,8 +304,7 @@ TileSetEditorPlugin::TileSetEditorPlugin(EditorNode *p_node) { tileset_editor = memnew(TileSetEditor(p_node)); add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, tileset_editor); - tileset_editor->set_anchors_and_margins_preset(Control::PRESET_WIDE); - tileset_editor->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_BEGIN); + tileset_editor->set_anchors_and_margins_preset(Control::PRESET_TOP_WIDE); tileset_editor->set_end(Point2(0, 22)); tileset_editor->hide(); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 46d52d21d4..87906c5a93 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -665,6 +665,8 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: } else if (hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE) { + MAKE_PROPSELECT + Object *instance = ObjectDB::get_instance(hint_text.to_int64()); if (instance) property_select->select_property_from_instance(instance, v); 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/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index f45217d031..cff5d9c9bd 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -398,6 +398,11 @@ Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::Call owner = memnew(Reference); } + if (!owner) { + r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; + return Variant(); + } + Reference *r = Object::cast_to<Reference>(owner); if (r) { ref = REF(r); @@ -793,7 +798,7 @@ NativeScriptLanguage *NativeScriptLanguage::singleton; void NativeScriptLanguage::_unload_stuff(bool p_reload) { for (Map<String, Map<StringName, NativeScriptDesc> >::Element *L = library_classes.front(); L; L = L->next()) { - if (p_reload && !library_gdnatives[L->key()]->get_library()->is_reloadable()) { + if (p_reload && library_gdnatives[L->key()].is_valid() && !library_gdnatives[L->key()]->get_library()->is_reloadable()) { continue; } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index d1829ce4d4..b20bc64d41 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -977,6 +977,7 @@ bool AnimationPlayer::is_playing() const { return true; */ } + void AnimationPlayer::set_current_animation(const String &p_anim) { if (p_anim == "[stop]" || p_anim == "") { @@ -986,13 +987,6 @@ void AnimationPlayer::set_current_animation(const String &p_anim) { } else { // Same animation, do not replay from start } - - /* - ERR_FAIL_COND(!animation_set.has(p_anim)); - playback.current.pos = 0; - playback.current.from = &animation_set[p_anim]; - playback.assigned = p_anim; - */ } String AnimationPlayer::get_current_animation() const { @@ -1000,6 +994,23 @@ String AnimationPlayer::get_current_animation() const { return (is_playing() ? playback.assigned : ""); } +void AnimationPlayer::set_assigned_animation(const String &p_anim) { + + if (is_playing()) { + play(p_anim); + } else { + ERR_FAIL_COND(!animation_set.has(p_anim)); + playback.current.pos = 0; + playback.current.from = &animation_set[p_anim]; + playback.assigned = p_anim; + } +} + +String AnimationPlayer::get_assigned_animation() const { + + return playback.assigned; +} + void AnimationPlayer::stop(bool p_reset) { Playback &c = playback; @@ -1301,6 +1312,8 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation); ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation); + ClassDB::bind_method(D_METHOD("set_assigned_animation", "anim"), &AnimationPlayer::set_assigned_animation); + ClassDB::bind_method(D_METHOD("get_assigned_animation"), &AnimationPlayer::get_assigned_animation); ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue); ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue); @@ -1331,6 +1344,7 @@ void AnimationPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER), "set_current_animation", "get_current_animation"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "assigned_animation", PROPERTY_HINT_NONE, "", 0), "set_assigned_animation", "get_assigned_animation"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_autoplay", "get_autoplay"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_length", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_length"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position"); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index ef1720443f..ef758bac44 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -284,6 +284,8 @@ public: bool is_playing() const; String get_current_animation() const; void set_current_animation(const String &p_anim); + String get_assigned_animation() const; + void set_assigned_animation(const String &p_anim); void stop_all(); void set_active(bool p_active); bool is_active() const; diff --git a/scene/gui/control.h b/scene/gui/control.h index 2d61ecb2af..51325f27b5 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -317,11 +317,11 @@ public: /* POSITIONING */ - void set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin = false); + void set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin = true); void set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0); void set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0); - void set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin = false, bool p_push_opposite_anchor = true); + void set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin = true, bool p_push_opposite_anchor = true); float get_anchor(Margin p_margin) const; void set_margin(Margin p_margin, float p_value); 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; |