diff options
Diffstat (limited to 'scene')
32 files changed, 269 insertions, 91 deletions
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index c11f13d2bd..c40aeb764e 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -284,10 +284,10 @@ bool AudioStreamPlayer2D::is_playing() const { return false; } -float AudioStreamPlayer2D::get_position() { +float AudioStreamPlayer2D::get_playback_position() { if (stream_playback.is_valid()) { - return stream_playback->get_position(); + return stream_playback->get_playback_position(); } return 0; @@ -395,7 +395,7 @@ void AudioStreamPlayer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer2D::stop); ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayer2D::is_playing); - ClassDB::bind_method(D_METHOD("get_position"), &AudioStreamPlayer2D::get_position); + ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayer2D::get_playback_position); ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioStreamPlayer2D::set_bus); ClassDB::bind_method(D_METHOD("get_bus"), &AudioStreamPlayer2D::get_bus); diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.h index 112d05856b..85104fce21 100644 --- a/scene/2d/audio_stream_player_2d.h +++ b/scene/2d/audio_stream_player_2d.h @@ -72,7 +72,7 @@ public: void seek(float p_seconds); void stop(); bool is_playing() const; - float get_position(); + float get_playback_position(); void set_bus(const StringName &p_bus); StringName get_bus() const; diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index ce56b85a9e..73e5dc6021 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -82,7 +82,7 @@ uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) { uint32_t id; if (shapes.size() == 0) { - id = 1; + id = 0; } else { id = shapes.back()->key() + 1; } diff --git a/scene/3d/SCsub b/scene/3d/SCsub index 90e78ba8d3..72739b527e 100644 --- a/scene/3d/SCsub +++ b/scene/3d/SCsub @@ -3,7 +3,7 @@ Import('env') -if (env["disable_3d"] == "yes"): +if env['disable_3d']: env.scene_sources.append("3d/spatial.cpp") env.scene_sources.append("3d/skeleton.cpp") diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index c8c478ae18..7bc8c9e89e 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -611,10 +611,10 @@ bool AudioStreamPlayer3D::is_playing() const { return false; } -float AudioStreamPlayer3D::get_position() { +float AudioStreamPlayer3D::get_playback_position() { if (stream_playback.is_valid()) { - return stream_playback->get_position(); + return stream_playback->get_playback_position(); } return 0; @@ -807,7 +807,7 @@ void AudioStreamPlayer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer3D::stop); ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayer3D::is_playing); - ClassDB::bind_method(D_METHOD("get_position"), &AudioStreamPlayer3D::get_position); + ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayer3D::get_playback_position); ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioStreamPlayer3D::set_bus); ClassDB::bind_method(D_METHOD("get_bus"), &AudioStreamPlayer3D::get_bus); diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index a6ce123790..2c2d4610c8 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -127,7 +127,7 @@ public: void seek(float p_seconds); void stop(); bool is_playing() const; - float get_position(); + float get_playback_position(); void set_bus(const StringName &p_bus); StringName get_bus() const; diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object.cpp index 1c0633fba7..7b4770e435 100644 --- a/scene/3d/collision_object.cpp +++ b/scene/3d/collision_object.cpp @@ -161,7 +161,7 @@ uint32_t CollisionObject::create_shape_owner(Object *p_owner) { uint32_t id; if (shapes.size() == 0) { - id = 1; + id = 0; } else { id = shapes.back()->key() + 1; } diff --git a/scene/3d/immediate_geometry.h b/scene/3d/immediate_geometry.h index 6db825bf54..93ef726c6d 100644 --- a/scene/3d/immediate_geometry.h +++ b/scene/3d/immediate_geometry.h @@ -38,7 +38,7 @@ class ImmediateGeometry : public GeometryInstance { GDCLASS(ImmediateGeometry, GeometryInstance); RID im; - //a list of texures drawn need to be kept, to avoid references + //a list of textures drawn need to be kept, to avoid references // in VisualServer from becoming invalid if the texture is no longer used List<Ref<Texture> > cached_textures; bool empty; diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 7402e664d9..b7cd9bd2dc 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -369,6 +369,12 @@ DirectionalLight::DirectionalLight() set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE); blend_splits = false; + +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) + // Create light with a default natural "sun" orientation in editor, instead of looking horizontally on X + set_rotation_in_degrees(Vector3(-50, 25, 30)); +#endif } void OmniLight::set_shadow_mode(ShadowMode p_mode) { diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp index 11e6c1b2e1..058b162e83 100644 --- a/scene/audio/audio_player.cpp +++ b/scene/audio/audio_player.cpp @@ -122,7 +122,6 @@ void AudioStreamPlayer::_notification(int p_what) { void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) { - ERR_FAIL_COND(!p_stream.is_valid()); AudioServer::get_singleton()->lock(); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); @@ -134,12 +133,14 @@ void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) { setseek = -1; } - stream = p_stream; - stream_playback = p_stream->instance_playback(); + if (p_stream.is_valid()) { + stream = p_stream; + stream_playback = p_stream->instance_playback(); + } AudioServer::get_singleton()->unlock(); - if (stream_playback.is_null()) { + if (p_stream.is_valid() && stream_playback.is_null()) { stream.unref(); ERR_FAIL_COND(stream_playback.is_null()); } @@ -193,10 +194,10 @@ bool AudioStreamPlayer::is_playing() const { return false; } -float AudioStreamPlayer::get_position() { +float AudioStreamPlayer::get_playback_position() { if (stream_playback.is_valid()) { - return stream_playback->get_position(); + return stream_playback->get_playback_position(); } return 0; @@ -284,7 +285,7 @@ void AudioStreamPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer::stop); ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayer::is_playing); - ClassDB::bind_method(D_METHOD("get_position"), &AudioStreamPlayer::get_position); + ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayer::get_playback_position); ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioStreamPlayer::set_bus); ClassDB::bind_method(D_METHOD("get_bus"), &AudioStreamPlayer::get_bus); diff --git a/scene/audio/audio_player.h b/scene/audio/audio_player.h index 19b61ea5d8..4bfc44730d 100644 --- a/scene/audio/audio_player.h +++ b/scene/audio/audio_player.h @@ -83,7 +83,7 @@ public: void seek(float p_seconds); void stop(); bool is_playing() const; - float get_position(); + float get_playback_position(); void set_bus(const StringName &p_bus); StringName get_bus() const; diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 04c0817b15..148277f2dd 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -39,7 +39,9 @@ void BaseButton::_unpress_group() { if (!button_group.is_valid()) return; - status.pressed = false; + if (toggle_mode) { + status.pressed = true; + } for (Set<BaseButton *>::Element *E = button_group->buttons.front(); E; E = E->next()) { if (E->get() == this) diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 704c00b1d6..62a48ad496 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -461,7 +461,7 @@ void ColorPicker::_screen_pick_pressed() { screen = memnew(Control); r->add_child(screen); screen->set_as_toplevel(true); - screen->set_area_as_parent_rect(); + screen->set_anchors_and_margins_preset(Control::PRESET_WIDE); screen->set_default_cursor_shape(CURSOR_POINTING_HAND); screen->connect("gui_input", this, "_screen_input"); } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 2c01a0e2d1..91c5263bf5 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1471,6 +1471,140 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) { } } +void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) { + // Calculate the size if the node is not resized + Size2 min_size = get_minimum_size(); + Size2 new_size = get_size(); + if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) { + new_size.x = min_size.x; + } + if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) { + new_size.y = min_size.y; + } + + float pw = _get_parent_range(0); + float ph = _get_parent_range(1); + + //Left + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_BOTTOM_LEFT: + case PRESET_CENTER_LEFT: + case PRESET_TOP_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_LEFT_WIDE: + case PRESET_HCENTER_WIDE: + case PRESET_WIDE: + data.margin[0] = pw * (0.0 - data.anchor[0]) + p_margin; + break; + + case PRESET_CENTER_TOP: + case PRESET_CENTER_BOTTOM: + case PRESET_CENTER: + case PRESET_VCENTER_WIDE: + data.margin[0] = pw * (0.5 - data.anchor[0]) - new_size.x / 2; + break; + + case PRESET_TOP_RIGHT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_RIGHT: + case PRESET_RIGHT_WIDE: + data.margin[0] = pw * (1.0 - data.anchor[0]) - new_size.x - p_margin; + break; + } + + // Top + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_TOP_RIGHT: + case PRESET_CENTER_TOP: + case PRESET_LEFT_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_TOP_WIDE: + case PRESET_VCENTER_WIDE: + case PRESET_WIDE: + data.margin[1] = ph * (0.0 - data.anchor[1]) + p_margin; + break; + + case PRESET_CENTER_LEFT: + case PRESET_CENTER_RIGHT: + case PRESET_CENTER: + case PRESET_HCENTER_WIDE: + data.margin[1] = ph * (0.5 - data.anchor[1]) - new_size.y / 2; + break; + + case PRESET_BOTTOM_LEFT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_BOTTOM: + case PRESET_BOTTOM_WIDE: + data.margin[1] = ph * (1.0 - data.anchor[1]) - new_size.y - p_margin; + break; + } + + // Right + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_BOTTOM_LEFT: + case PRESET_CENTER_LEFT: + case PRESET_LEFT_WIDE: + data.margin[2] = pw * (0.0 - data.anchor[2]) + new_size.x + p_margin; + break; + + case PRESET_CENTER_TOP: + case PRESET_CENTER_BOTTOM: + case PRESET_CENTER: + case PRESET_VCENTER_WIDE: + data.margin[2] = pw * (0.5 - data.anchor[2]) + new_size.x / 2; + break; + + case PRESET_TOP_RIGHT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_RIGHT: + case PRESET_TOP_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_HCENTER_WIDE: + case PRESET_WIDE: + data.margin[2] = pw * (1.0 - data.anchor[2]) - p_margin; + break; + } + + // Bottom + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_TOP_RIGHT: + case PRESET_CENTER_TOP: + case PRESET_TOP_WIDE: + data.margin[3] = ph * (0.0 - data.anchor[3]) + new_size.y + p_margin; + break; + + case PRESET_CENTER_LEFT: + case PRESET_CENTER_RIGHT: + case PRESET_CENTER: + case PRESET_HCENTER_WIDE: + data.margin[3] = ph * (0.5 - data.anchor[3]) + new_size.y / 2; + break; + + case PRESET_BOTTOM_LEFT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_BOTTOM: + case PRESET_LEFT_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_VCENTER_WIDE: + case PRESET_WIDE: + data.margin[3] = ph * (1.0 - data.anchor[3]) - p_margin; + break; + } + + _size_changed(); +} + +void Control::set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) { + set_anchors_preset(p_preset); + set_margins_preset(p_preset, p_resize_mode, p_margin); +} + float Control::get_anchor(Margin p_margin) const { return data.anchor[p_margin]; @@ -1622,20 +1756,6 @@ Rect2 Control::get_item_rect() const { return Rect2(Point2(), get_size()); } -void Control::set_area_as_parent_rect(int p_margin) { - - data.anchor[MARGIN_LEFT] = ANCHOR_BEGIN; - data.margin[MARGIN_LEFT] = p_margin; - data.anchor[MARGIN_TOP] = ANCHOR_BEGIN; - data.margin[MARGIN_TOP] = p_margin; - data.anchor[MARGIN_RIGHT] = ANCHOR_END; - data.margin[MARGIN_RIGHT] = -p_margin; - data.anchor[MARGIN_BOTTOM] = ANCHOR_END; - data.margin[MARGIN_BOTTOM] = -p_margin; - - _size_changed(); -} - void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon) { ERR_FAIL_COND(p_icon.is_null()); @@ -2471,9 +2591,11 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event); ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size); ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size); + ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_margin"), &Control::set_anchors_preset, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("set_margins_preset", "preset", "resize_mode", "margin"), &Control::set_margins_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("set_anchors_and_margins_preset", "preset", "resize_mode", "margin"), &Control::set_anchors_and_margins_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0)); ClassDB::bind_method(D_METHOD("set_anchor", "margin", "anchor", "keep_margin", "push_opposite_anchor"), &Control::set_anchor, DEFVAL(false), DEFVAL(true)); ClassDB::bind_method(D_METHOD("_set_anchor", "margin", "anchor"), &Control::_set_anchor); - ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_margin"), &Control::set_anchors_preset, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_anchor", "margin"), &Control::get_anchor); ClassDB::bind_method(D_METHOD("set_margin", "margin", "offset"), &Control::set_margin); ClassDB::bind_method(D_METHOD("set_anchor_and_margin", "margin", "anchor", "offset", "push_opposite_anchor"), &Control::set_anchor_and_margin, DEFVAL(false)); @@ -2505,7 +2627,6 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position); ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect); ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect); - ClassDB::bind_method(D_METHOD("set_area_as_parent_rect", "margin"), &Control::set_area_as_parent_rect, DEFVAL(0)); ClassDB::bind_method(D_METHOD("show_modal", "exclusive"), &Control::show_modal, DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode); ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode); @@ -2689,6 +2810,11 @@ void Control::_bind_methods() { BIND_ENUM_CONSTANT(PRESET_HCENTER_WIDE); BIND_ENUM_CONSTANT(PRESET_WIDE); + BIND_ENUM_CONSTANT(PRESET_MODE_MINSIZE); + BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT); + BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_WIDTH); + BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_SIZE); + BIND_ENUM_CONSTANT(SIZE_EXPAND); BIND_ENUM_CONSTANT(SIZE_FILL); BIND_ENUM_CONSTANT(SIZE_EXPAND_FILL); diff --git a/scene/gui/control.h b/scene/gui/control.h index da5c4d0908..5b146b4454 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -124,6 +124,13 @@ public: PRESET_WIDE }; + enum LayoutPresetMode { + PRESET_MODE_MINSIZE, + PRESET_MODE_KEEP_WIDTH, + PRESET_MODE_KEEP_HEIGHT, + PRESET_MODE_KEEP_SIZE + }; + private: struct CComparator { @@ -294,34 +301,32 @@ public: /* POSITIONING */ - void set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin = false, bool p_push_opposite_anchor = true); - void set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor = true); void set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin = false); + 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); float get_anchor(Margin p_margin) const; void set_margin(Margin p_margin, float p_value); + float get_margin(Margin p_margin) const; + + void set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor = true); void set_begin(const Point2 &p_point); // helper void set_end(const Point2 &p_point); // helper - void set_h_grow_direction(GrowDirection p_direction); - GrowDirection get_h_grow_direction() const; - - void set_v_grow_direction(GrowDirection p_direction); - GrowDirection get_v_grow_direction() const; - - float get_margin(Margin p_margin) const; Point2 get_begin() const; Point2 get_end() const; void set_position(const Point2 &p_point); - void set_size(const Size2 &p_size); void set_global_position(const Point2 &p_point); - Point2 get_position() const; Point2 get_global_position() const; + + void set_size(const Size2 &p_size); Size2 get_size() const; + Rect2 get_rect() const; Rect2 get_global_rect() const; Rect2 get_window_rect() const; ///< use with care, as it blocks waiting for the visual server @@ -331,14 +336,18 @@ public: float get_rotation() const; float get_rotation_deg() const; + void set_h_grow_direction(GrowDirection p_direction); + GrowDirection get_h_grow_direction() const; + + void set_v_grow_direction(GrowDirection p_direction); + GrowDirection get_v_grow_direction() const; + void set_pivot_offset(const Vector2 &p_pivot); Vector2 get_pivot_offset() const; void set_scale(const Vector2 &p_scale); Vector2 get_scale() const; - void set_area_as_parent_rect(int p_margin = 0); - void show_modal(bool p_exclusive = false); void set_theme(const Ref<Theme> &p_theme); @@ -449,6 +458,7 @@ VARIANT_ENUM_CAST(Control::FocusMode); VARIANT_ENUM_CAST(Control::SizeFlags); VARIANT_ENUM_CAST(Control::CursorShape); VARIANT_ENUM_CAST(Control::LayoutPreset); +VARIANT_ENUM_CAST(Control::LayoutPresetMode); VARIANT_ENUM_CAST(Control::MouseFilter); VARIANT_ENUM_CAST(Control::GrowDirection); VARIANT_ENUM_CAST(Control::Anchor); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 3ffa6d57a4..b0eb12fb6b 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1182,7 +1182,7 @@ GraphEdit::GraphEdit() { top_layer = memnew(GraphEditFilter(this)); add_child(top_layer); top_layer->set_mouse_filter(MOUSE_FILTER_PASS); - top_layer->set_area_as_parent_rect(); + top_layer->set_anchors_and_margins_preset(Control::PRESET_WIDE); top_layer->connect("draw", this, "_top_layer_draw"); top_layer->set_mouse_filter(MOUSE_FILTER_PASS); top_layer->connect("gui_input", this, "_top_layer_input"); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 7493ea95a8..8ca487f2bd 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -534,7 +534,7 @@ void LineEdit::_notification(int p_what) { switch (p_what) { #ifdef TOOLS_ENABLED case NOTIFICATION_ENTER_TREE: { - if (Engine::get_singleton()->is_editor_hint()) { + if (Engine::get_singleton()->is_editor_hint() && !get_tree()->is_node_being_edited(this)) { cursor_set_blink_enabled(EDITOR_DEF("text_editor/cursor/caret_blink", false)); cursor_set_blink_speed(EDITOR_DEF("text_editor/cursor/caret_blink_speed", 0.65)); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 5a2a552943..2110298950 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -265,7 +265,7 @@ void PopupPanel::set_child_rect(Control *p_child) { ERR_FAIL_NULL(p_child); Ref<StyleBox> p = get_stylebox("panel"); - p_child->set_area_as_parent_rect(); + p_child->set_anchors_preset(Control::PRESET_WIDE); p_child->set_margin(MARGIN_LEFT, p->get_margin(MARGIN_LEFT)); p_child->set_margin(MARGIN_RIGHT, -p->get_margin(MARGIN_RIGHT)); p_child->set_margin(MARGIN_TOP, p->get_margin(MARGIN_TOP)); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 41f4beb1c9..6044b86ef5 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -343,7 +343,7 @@ void ScrollBar::_notification(int p_what) { double dist = sqrt(target * target); double vel = ((target / dist) * 500) * get_fixed_process_delta_time(); - if (vel >= dist) { + if (Math::abs(vel) >= dist) { set_value(target_scroll); } else { set_value(get_value() + vel); diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 60b6746ae8..05f2809bfc 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -268,7 +268,7 @@ SpinBox::SpinBox() { line_edit = memnew(LineEdit); add_child(line_edit); - line_edit->set_area_as_parent_rect(); + line_edit->set_anchors_and_margins_preset(Control::PRESET_WIDE); //connect("value_changed",this,"_value_changed"); line_edit->connect("text_entered", this, "_text_entered", Vector<Variant>(), CONNECT_DEFERRED); line_edit->connect("focus_exited", this, "_line_edit_focus_exit", Vector<Variant>(), CONNECT_DEFERRED); diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 98a8db336e..6e50614e8f 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -264,9 +264,9 @@ void TabContainer::_notification(int p_what) { if (popup) { x -= menu->get_width(); if (mouse_x_cache > x) - menu_hl->draw(get_canvas_item(), Size2(x, 0)); + menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2)); else - menu->draw(get_canvas_item(), Size2(x, 0)); + menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2)); } // Draw the navigation buttons. @@ -367,7 +367,7 @@ void TabContainer::add_child_notify(Node *p_child) { current = 0; previous = 0; } - c->set_area_as_parent_rect(); + c->set_anchors_and_margins_preset(Control::PRESET_WIDE); if (tabs_visible) c->set_margin(MARGIN_TOP, _get_top_margin()); Ref<StyleBox> sb = get_stylebox("panel"); @@ -401,7 +401,7 @@ void TabContainer::set_current_tab(int p_current) { Control *c = tabs[i]; if (i == current) { c->show(); - c->set_area_as_parent_rect(); + c->set_anchors_and_margins_preset(Control::PRESET_WIDE); if (tabs_visible) c->set_margin(MARGIN_TOP, _get_top_margin()); c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP))); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index d79ce25344..11bdbfc3e8 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -501,8 +501,7 @@ void TextEdit::_notification(int p_what) { if (cache.background_color.a > 0.01) { - Point2i ofs = Point2i(cache.style_normal->get_offset()) / 2.0; - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs, get_size() - cache.style_normal->get_minimum_size() + ofs), cache.background_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color); } //compute actual region to start (may be inside say, a comment). //slow in very large documments :( but ok for source! diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 8d6eb0f8e2..822136820e 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2135,8 +2135,15 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (selected_item->get_children() != NULL && !selected_item->is_collapsed()) { selected_item->set_collapsed(true); } else { - selected_col = columns.size() - 1; - dobreak = false; // fall through to key_up + if (columns.size() == 1) { // goto parent with one column + TreeItem *parent = selected_item->get_parent(); + if (selected_item != get_root() && parent && parent->is_selectable(selected_col) && !(hide_root && parent == get_root())) { + select_single_item(parent, get_root(), selected_col); + } + } else { + selected_col = columns.size() - 1; + dobreak = false; // fall through to key_up + } } } else { if (select_mode == SELECT_MULTI) { @@ -2149,6 +2156,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } update(); accept_event(); + ensure_cursor_is_visible(); if (dobreak) { break; diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index e08d050ca7..816556af30 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -282,7 +282,7 @@ float VideoPlayer::get_stream_position() const { if (playback.is_null()) return 0; - return playback->get_position(); + return playback->get_playback_position(); }; Ref<Texture> VideoPlayer::get_video_texture() { diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 4f62d88934..5a1388458b 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -650,7 +650,7 @@ void SceneTree::set_quit_on_go_back(bool p_enable) { bool SceneTree::is_node_being_edited(const Node *p_node) const { - return Engine::get_singleton()->is_editor_hint() && edited_scene_root && edited_scene_root->is_a_parent_of(p_node); + return Engine::get_singleton()->is_editor_hint() && edited_scene_root && (edited_scene_root->is_a_parent_of(p_node) || edited_scene_root == p_node); } #endif @@ -2216,6 +2216,7 @@ void SceneTree::_bind_methods() { BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP); BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP_WIDTH); BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP_HEIGHT); + BIND_ENUM_CONSTANT(STRETCH_ASPECT_EXPAND); } SceneTree *SceneTree::singleton = NULL; diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index e47cb971ae..1fd84a860e 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -41,7 +41,7 @@ void AudioStreamPlaybackSample::start(float p_from_pos) { ima_adpcm[i].window_ofs = 0; } - seek_pos(p_from_pos); + seek(p_from_pos); sign = 1; active = true; } @@ -61,11 +61,11 @@ int AudioStreamPlaybackSample::get_loop_count() const { return 0; } -float AudioStreamPlaybackSample::get_position() const { +float AudioStreamPlaybackSample::get_playback_position() const { return float(offset >> MIX_FRAC_BITS) / base->mix_rate; } -void AudioStreamPlaybackSample::seek_pos(float p_time) { +void AudioStreamPlaybackSample::seek(float p_time) { if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) return; //no seeking in ima-adpcm diff --git a/scene/resources/audio_stream_sample.h b/scene/resources/audio_stream_sample.h index 46fa78ddcf..fbb8010a9c 100644 --- a/scene/resources/audio_stream_sample.h +++ b/scene/resources/audio_stream_sample.h @@ -71,8 +71,8 @@ public: virtual int get_loop_count() const; //times it looped - virtual float get_position() const; - virtual void seek_pos(float p_time); + virtual float get_playback_position() const; + virtual void seek(float p_time); virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames); diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index da3bc6a95b..4c6fa7c8a1 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -55,12 +55,11 @@ void Environment::set_sky(const Ref<Sky> &p_sky) { VS::get_singleton()->environment_set_sky(environment, sb_rid); } -void Environment::set_sky_scale(float p_scale) { +void Environment::set_sky_custom_fov(float p_scale) { - bg_sky_scale = p_scale; - VS::get_singleton()->environment_set_sky_scale(environment, p_scale); + bg_sky_custom_fov = p_scale; + VS::get_singleton()->environment_set_sky_custom_fov(environment, p_scale); } - void Environment::set_bg_color(const Color &p_color) { bg_color = p_color; @@ -101,9 +100,9 @@ Ref<Sky> Environment::get_sky() const { return bg_sky; } -float Environment::get_sky_scale() const { +float Environment::get_sky_custom_fov() const { - return bg_sky_scale; + return bg_sky_custom_fov; } Color Environment::get_bg_color() const { @@ -268,7 +267,7 @@ Ref<Texture> Environment::get_adjustment_color_correction() const { void Environment::_validate_property(PropertyInfo &property) const { - if (property.name == "background_sky" || property.name == "background_sky_scale" || property.name == "ambient_light/sky_contribution") { + if (property.name == "background_sky" || property.name == "background_sky_custom_fov" || property.name == "ambient_light/sky_contribution") { if (bg_mode != BG_SKY && bg_mode != BG_COLOR_SKY) { property.usage = PROPERTY_USAGE_NOEDITOR; } @@ -820,7 +819,7 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_background", "mode"), &Environment::set_background); ClassDB::bind_method(D_METHOD("set_sky", "sky"), &Environment::set_sky); - ClassDB::bind_method(D_METHOD("set_sky_scale", "scale"), &Environment::set_sky_scale); + ClassDB::bind_method(D_METHOD("set_sky_custom_fov", "scale"), &Environment::set_sky_custom_fov); ClassDB::bind_method(D_METHOD("set_bg_color", "color"), &Environment::set_bg_color); ClassDB::bind_method(D_METHOD("set_bg_energy", "energy"), &Environment::set_bg_energy); ClassDB::bind_method(D_METHOD("set_canvas_max_layer", "layer"), &Environment::set_canvas_max_layer); @@ -830,7 +829,7 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("get_background"), &Environment::get_background); ClassDB::bind_method(D_METHOD("get_sky"), &Environment::get_sky); - ClassDB::bind_method(D_METHOD("get_sky_scale"), &Environment::get_sky_scale); + ClassDB::bind_method(D_METHOD("get_sky_custom_fov"), &Environment::get_sky_custom_fov); ClassDB::bind_method(D_METHOD("get_bg_color"), &Environment::get_bg_color); ClassDB::bind_method(D_METHOD("get_bg_energy"), &Environment::get_bg_energy); ClassDB::bind_method(D_METHOD("get_canvas_max_layer"), &Environment::get_canvas_max_layer); @@ -841,7 +840,7 @@ void Environment::_bind_methods() { ADD_GROUP("Background", "background_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "background_mode", PROPERTY_HINT_ENUM, "Clear Color,Custom Color,Sky,Color+Sky,Canvas,Keep"), "set_background", "get_background"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "background_sky", PROPERTY_HINT_RESOURCE_TYPE, "Sky"), "set_sky", "get_sky"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_sky_scale", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_sky_scale", "get_sky_scale"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_sky_custom_fov", PROPERTY_HINT_RANGE, "0,180,0.1"), "set_sky_custom_fov", "get_sky_custom_fov"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "background_color"), "set_bg_color", "get_bg_color"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_bg_energy", "get_bg_energy"); ADD_PROPERTY(PropertyInfo(Variant::INT, "background_canvas_max_layer", PROPERTY_HINT_RANGE, "-1000,1000,1"), "set_canvas_max_layer", "get_canvas_max_layer"); @@ -1142,7 +1141,7 @@ Environment::Environment() { environment = VS::get_singleton()->environment_create(); bg_mode = BG_CLEAR_COLOR; - bg_sky_scale = 1.0; + bg_sky_custom_fov = 0; bg_energy = 1.0; bg_canvas_max_layer = 0; ambient_energy = 1.0; diff --git a/scene/resources/environment.h b/scene/resources/environment.h index 9046ec1e49..5909846074 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -76,7 +76,7 @@ private: BGMode bg_mode; Ref<Sky> bg_sky; - float bg_sky_scale; + float bg_sky_custom_fov; Color bg_color; float bg_energy; int bg_canvas_max_layer; @@ -162,7 +162,7 @@ protected: public: void set_background(BGMode p_bg); void set_sky(const Ref<Sky> &p_sky); - void set_sky_scale(float p_scale); + void set_sky_custom_fov(float p_scale); void set_bg_color(const Color &p_color); void set_bg_energy(float p_energy); void set_canvas_max_layer(int p_max_layer); @@ -172,7 +172,7 @@ public: BGMode get_background() const; Ref<Sky> get_sky() const; - float get_sky_scale() const; + float get_sky_custom_fov() const; Color get_bg_color() const; float get_bg_energy() const; int get_canvas_max_layer() const; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index ae858e862c..da0f522ff3 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -268,6 +268,8 @@ void SpatialMaterial::init_shaders() { shader_names->grow = "grow"; + shader_names->ao_light_affect = "ao_light_affect"; + shader_names->proximity_fade_distance = "proximity_fade_distance"; shader_names->distance_fade_min = "distance_fade_min"; shader_names->distance_fade_max = "distance_fade_max"; @@ -462,6 +464,7 @@ void SpatialMaterial::_update_shader() { if (features[FEATURE_AMBIENT_OCCLUSION]) { code += "uniform sampler2D texture_ambient_occlusion : hint_white;\n"; code += "uniform vec4 ao_texture_channel;\n"; + code += "uniform float ao_light_affect;\n"; } if (features[FEATURE_DETAIL]) { @@ -737,7 +740,7 @@ void SpatialMaterial::_update_shader() { code += "\tALBEDO *= 1.0 - ref_amount;\n"; code += "\tALPHA = 1.0;\n"; - } else if (features[FEATURE_TRANSPARENT] || features[FLAG_USE_ALPHA_SCISSOR] || distance_fade_enabled || proximity_fade_enabled) { + } else if (features[FEATURE_TRANSPARENT] || flags[FLAG_USE_ALPHA_SCISSOR] || distance_fade_enabled || proximity_fade_enabled) { code += "\tALPHA = albedo.a * albedo_tex.a;\n"; } @@ -796,6 +799,8 @@ void SpatialMaterial::_update_shader() { code += "\tAO = dot(texture(texture_ambient_occlusion,base_uv),ao_texture_channel);\n"; } } + + code += "\tAO_LIGHT_AFFECT = ao_light_affect;\n"; } if (features[FEATURE_SUBSURACE_SCATTERING]) { @@ -857,10 +862,10 @@ void SpatialMaterial::_update_shader() { code += "\tvec3 detail_norm = mix(NORMALMAP,detail_norm_tex.rgb,detail_tex.a);\n"; code += "\tNORMALMAP = mix(NORMALMAP,detail_norm,detail_mask_tex.r);\n"; code += "\tALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n"; + } - if (flags[FLAG_USE_ALPHA_SCISSOR]) { - code += "\tALPHA_SCISSOR=alpha_scissor_threshold;\n"; - } + if (flags[FLAG_USE_ALPHA_SCISSOR]) { + code += "\tALPHA_SCISSOR=alpha_scissor_threshold;\n"; } code += "}\n"; @@ -1012,6 +1017,16 @@ float SpatialMaterial::get_rim_tint() const { return rim_tint; } +void SpatialMaterial::set_ao_light_affect(float p_ao_light_affect) { + + ao_light_affect = p_ao_light_affect; + VS::get_singleton()->material_set_param(_get_material(), shader_names->ao_light_affect, p_ao_light_affect); +} +float SpatialMaterial::get_ao_light_affect() const { + + return ao_light_affect; +} + void SpatialMaterial::set_clearcoat(float p_clearcoat) { clearcoat = p_clearcoat; @@ -1745,6 +1760,9 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_grow", "amount"), &SpatialMaterial::set_grow); ClassDB::bind_method(D_METHOD("get_grow"), &SpatialMaterial::get_grow); + ClassDB::bind_method(D_METHOD("set_ao_light_affect", "amount"), &SpatialMaterial::set_ao_light_affect); + ClassDB::bind_method(D_METHOD("get_ao_light_affect"), &SpatialMaterial::get_ao_light_affect); + ClassDB::bind_method(D_METHOD("set_alpha_scissor_threshold", "threshold"), &SpatialMaterial::set_alpha_scissor_threshold); ClassDB::bind_method(D_METHOD("get_alpha_scissor_threshold"), &SpatialMaterial::get_alpha_scissor_threshold); @@ -1853,6 +1871,7 @@ void SpatialMaterial::_bind_methods() { ADD_GROUP("Ambient Occlusion", "ao_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_enabled"), "set_feature", "get_feature", FEATURE_AMBIENT_OCCLUSION); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "ao_light_affect", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ao_light_affect", "get_ao_light_affect"); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "ao_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_AMBIENT_OCCLUSION); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_on_uv2"), "set_flag", "get_flag", FLAG_AO_ON_UV2); ADD_PROPERTY(PropertyInfo(Variant::INT, "ao_texture_channel", PROPERTY_HINT_ENUM, "Red,Green,Blue,Alpha,Gray"), "set_ao_texture_channel", "get_ao_texture_channel"); @@ -2036,6 +2055,8 @@ SpatialMaterial::SpatialMaterial() set_distance_fade_min_distance(0); set_distance_fade_max_distance(10); + set_ao_light_affect(0.0); + set_metallic_texture_channel(TEXTURE_CHANNEL_RED); set_roughness_texture_channel(TEXTURE_CHANNEL_RED); set_ao_texture_channel(TEXTURE_CHANNEL_RED); diff --git a/scene/resources/material.h b/scene/resources/material.h index 721514f586..cf190f0921 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -315,6 +315,7 @@ private: StringName proximity_fade_distance; StringName distance_fade_min; StringName distance_fade_max; + StringName ao_light_affect; StringName metallic_texture_channel; StringName roughness_texture_channel; @@ -358,6 +359,7 @@ private: float point_size; float alpha_scissor_threshold; bool grow_enabled; + float ao_light_affect; float grow; int particles_anim_h_frames; int particles_anim_v_frames; @@ -443,6 +445,9 @@ public: void set_rim_tint(float p_rim_tint); float get_rim_tint() const; + void set_ao_light_affect(float p_ao_light_affect); + float get_ao_light_affect() const; + void set_clearcoat(float p_clearcoat); float get_clearcoat() const; diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h index 30264691ee..0f07233185 100644 --- a/scene/resources/video_stream.h +++ b/scene/resources/video_stream.h @@ -55,8 +55,8 @@ public: virtual float get_length() const = 0; - virtual float get_position() const = 0; - virtual void seek_pos(float p_time) = 0; + virtual float get_playback_position() const = 0; + virtual void seek(float p_time) = 0; virtual void set_audio_track(int p_idx) = 0; |