diff options
42 files changed, 419 insertions, 141 deletions
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index ef9894bcdb..2a3c298633 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,4 +1,4 @@ -**Operating system or device - Godot version:** +**Operating system or device, Godot version, GPU Model and driver (if graphics related):** **Issue description:** diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index c69fe17049..5f534f63a8 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -978,9 +978,9 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_screen_count"), &_OS::get_screen_count); ClassDB::bind_method(D_METHOD("get_current_screen"), &_OS::get_current_screen); ClassDB::bind_method(D_METHOD("set_current_screen", "screen"), &_OS::set_current_screen); - ClassDB::bind_method(D_METHOD("get_screen_position", "screen"), &_OS::get_screen_position, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("get_screen_size", "screen"), &_OS::get_screen_size, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("get_screen_dpi", "screen"), &_OS::get_screen_dpi, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("get_screen_position", "screen"), &_OS::get_screen_position, DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("get_screen_size", "screen"), &_OS::get_screen_size, DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("get_screen_dpi", "screen"), &_OS::get_screen_dpi, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("get_window_position"), &_OS::get_window_position); ClassDB::bind_method(D_METHOD("set_window_position", "position"), &_OS::set_window_position); ClassDB::bind_method(D_METHOD("get_window_size"), &_OS::get_window_size); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 41653c8846..fc280bd7ef 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -140,9 +140,9 @@ public: virtual int get_screen_count() const; virtual int get_current_screen() const; virtual void set_current_screen(int p_screen); - virtual Point2 get_screen_position(int p_screen = 0) const; - virtual Size2 get_screen_size(int p_screen = 0) const; - virtual int get_screen_dpi(int p_screen = 0) const; + virtual Point2 get_screen_position(int p_screen = -1) const; + virtual Size2 get_screen_size(int p_screen = -1) const; + virtual int get_screen_dpi(int p_screen = -1) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2 &p_position); virtual Size2 get_window_size() const; diff --git a/core/global_constants.cpp b/core/global_constants.cpp index d296b678b9..cd9a302ba6 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -45,15 +45,15 @@ struct _GlobalConstant { _GlobalConstant() {} #ifdef DEBUG_METHODS_ENABLED - _GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value) { - enum_name = p_enum_name; - name = p_name; - value = p_value; + _GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value) + : enum_name(p_enum_name), + name(p_name), + value(p_value) { } #else - _GlobalConstant(const char *p_name, int p_value) { - name = p_name; - value = p_value; + _GlobalConstant(const char *p_name, int p_value) + : name(p_name), + value(p_value) { } #endif }; diff --git a/core/os/os.h b/core/os/os.h index 4d64e4a9f0..0fcf465655 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -164,9 +164,9 @@ public: virtual int get_screen_count() const { return 1; } virtual int get_current_screen() const { return 0; } virtual void set_current_screen(int p_screen) {} - virtual Point2 get_screen_position(int p_screen = 0) const { return Point2(); } - virtual Size2 get_screen_size(int p_screen = 0) const { return get_window_size(); } - virtual int get_screen_dpi(int p_screen = 0) const { return 72; } + virtual Point2 get_screen_position(int p_screen = -1) const { return Point2(); } + virtual Size2 get_screen_size(int p_screen = -1) const { return get_window_size(); } + virtual int get_screen_dpi(int p_screen = -1) const { return 72; } virtual Point2 get_window_position() const { return Vector2(); } virtual void set_window_position(const Point2 &p_position) {} virtual Size2 get_window_size() const = 0; diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 398f20caf3..5aa71f6704 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -326,6 +326,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri is_float = true; } else if (c == 'e') { reading = READING_EXP; + is_float = true; } else { reading = READING_DONE; } @@ -337,7 +338,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri } else if (c == 'e') { reading = READING_EXP; - } else { reading = READING_DONE; } @@ -349,8 +349,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { - if (c == '-') - is_float = true; exp_sign = true; } else { diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 570d90f81e..26c0b81428 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -46114,6 +46114,13 @@ <description> </description> </method> + <method name="get_nine_patch_stretch"> + <return type="bool"> + </return> + <description> + Returns true if textures are stretched as nine-patches or false otherwise. + </description> + </method> <method name="get_over_texture" qualifiers="const"> <return type="Object"> </return> @@ -46138,6 +46145,15 @@ <description> </description> </method> + <method name="get_stretch_margin" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="margin" type="int"> + </argument> + <description> + Return nine-patch texture offset for a given margin (MARGIN_LEFT, MARGIN_TOP, MARGIN_RIGHT, MARGIN_BOTTOM). + </description> + </method> <method name="get_under_texture" qualifiers="const"> <return type="Object"> </return> @@ -46156,6 +46172,13 @@ <description> </description> </method> + <method name="set_nine_patch_stretch"> + <argument index="0" name="stretch" type="bool"> + </argument> + <description> + Set if textures should be stretched as nine-patches. + </description> + </method> <method name="set_over_texture"> <argument index="0" name="tex" type="Object"> </argument> @@ -46180,6 +46203,15 @@ <description> </description> </method> + <method name="set_stretch_margin"> + <argument index="0" name="margin" type="int"> + </argument> + <argument index="1" name="size" type="int"> + </argument> + <description> + Set nine-patch texture offset for a given margin (MARGIN_LEFT, MARGIN_TOP, MARGIN_RIGHT, MARGIN_BOTTOM). + </description> + </method> <method name="set_under_texture"> <argument index="0" name="tex" type="Object"> </argument> @@ -46202,6 +46234,16 @@ </member> <member name="texture_under" type="Texture" setter="set_under_texture" getter="get_under_texture" brief=""> </member> + <member name="nine_patch_stretch" type="bool" setter="set_nine_patch_stretch" getter="get_nine_patch_stretch" brief=""> + </member> + <member name="stretch_margin_left" type="int" setter="set_stretch_margin" getter="get_stretch_margin" brief=""> + </member> + <member name="stretch_margin_top" type="int" setter="set_stretch_margin" getter="get_stretch_margin" brief=""> + </member> + <member name="stretch_margin_right" type="int" setter="set_stretch_margin" getter="get_stretch_margin" brief=""> + </member> + <member name="stretch_margin_bottom" type="int" setter="set_stretch_margin" getter="get_stretch_margin" brief=""> + </member> </members> <constants> <constant name="FILL_LEFT_TO_RIGHT" value="0"> diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index c89fc0768f..05cfba726c 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -2186,7 +2186,7 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo while (m->next_pass.is_valid()) { m = storage->material_owner.getornull(m->next_pass); - if (!m) + if (!m || !m->shader || !m->shader->valid) break; _add_geometry_with_material(p_geometry, p_instance, p_owner, m, p_shadow); } diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 3f0498746b..e6476bd6b6 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1694,6 +1694,7 @@ FRAGMENT_SHADER_CODE if (gl_FragCoord.w > shadow_split_offsets.w) { vec3 pssm_coord; + float pssm_fade=0.0; #ifdef LIGHT_USE_PSSM_BLEND float pssm_blend; @@ -1751,6 +1752,7 @@ FRAGMENT_SHADER_CODE } else { highp vec4 splane=(shadow_matrix4 * vec4(vertex,1.0)); pssm_coord=splane.xyz/splane.w; + pssm_fade = smoothstep(shadow_split_offsets.z,shadow_split_offsets.w,gl_FragCoord.w); #if defined(LIGHT_USE_PSSM_BLEND) use_blend=false; @@ -1782,6 +1784,7 @@ FRAGMENT_SHADER_CODE } else { highp vec4 splane=(shadow_matrix2 * vec4(vertex,1.0)); pssm_coord=splane.xyz/splane.w; + pssm_fade = smoothstep(shadow_split_offsets.x,shadow_split_offsets.y,gl_FragCoord.w); #if defined(LIGHT_USE_PSSM_BLEND) use_blend=false; @@ -1818,7 +1821,7 @@ FRAGMENT_SHADER_CODE } #endif - light_attenuation=mix(shadow_color_contact.rgb,vec3(1.0),shadow); + light_attenuation=mix(mix(shadow_color_contact.rgb,vec3(1.0),shadow),vec3(1.0),pssm_fade); } diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index 988e31d1ea..73dec4f90c 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -170,7 +170,7 @@ vec3 tonemap_aces(vec3 color) { return color = clamp((color*(a*color+b))/(color*(c*color+d)+e),vec3(0.0),vec3(1.0)); } -vec3 tonemap_reindhart(vec3 color,vec3 white) { +vec3 tonemap_reindhart(vec3 color,float white) { return ( color * ( 1.0 + ( color / ( white) ) ) ) / ( 1.0 + color ); } diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 5c8e166730..358d575764 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -593,6 +593,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { hints["text_editor/theme/color_theme"] = PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, "Default"); set("text_editor/theme/line_spacing", 4); + set("text_editor/theme/adapted_code_editor_background_color", true); _load_default_text_editor_theme(); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 9f6416f4e6..f628a23d5f 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -86,19 +86,6 @@ static Ref<StyleBoxFlat> change_border_color(Ref<StyleBoxFlat> p_style, Color p_ return style; } -static Ref<StyleBoxFlat> add_additional_border(Ref<StyleBoxFlat> p_style, int p_left, int p_top, int p_right, int p_bottom) { - Ref<StyleBoxFlat> style = p_style->duplicate(); - style->set_border_width(MARGIN_LEFT, p_left * EDSCALE + style->get_border_width(MARGIN_LEFT)); - style->set_border_width(MARGIN_RIGHT, p_right * EDSCALE + style->get_border_width(MARGIN_RIGHT)); - style->set_border_width(MARGIN_TOP, p_top * EDSCALE + style->get_border_width(MARGIN_TOP)); - style->set_border_width(MARGIN_BOTTOM, p_bottom * EDSCALE + style->get_border_width(MARGIN_BOTTOM)); - style->set_expand_margin_size(MARGIN_LEFT, p_left * EDSCALE); - style->set_expand_margin_size(MARGIN_RIGHT, p_right * EDSCALE); - style->set_expand_margin_size(MARGIN_TOP, p_top * EDSCALE); - style->set_expand_margin_size(MARGIN_BOTTOM, p_bottom * EDSCALE); - return style; -} - #define HIGHLIGHT_COLOR_LIGHT highlight_color.linear_interpolate(Color(1, 1, 1, 1), 0.3) #define HIGHLIGHT_COLOR_DARK highlight_color.linear_interpolate(Color(0, 0, 0, 1), 0.5) @@ -424,6 +411,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_stylebox("SceneTabFG", "EditorStyles", make_flat_stylebox(title_color_hl, 10, 5, 10, 5)); theme->set_stylebox("SceneTabBG", "EditorStyles", make_empty_stylebox(6, 5, 6, 5)); theme->set_icon("close", "Tabs", theme->get_icon("GuiClose", "EditorIcons")); + theme->set_stylebox("button_pressed", "Tabs", style_menu); + theme->set_stylebox("button", "Tabs", style_menu); // Separators (no separators) theme->set_stylebox("separator", "HSeparator", make_line_stylebox(separator_color, border_width)); @@ -537,7 +526,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // PopupPanel Ref<StyleBoxFlat> style_dock_select = make_flat_stylebox(base_color); style_dock_select->set_border_color_all(light_color_1); - style_dock_select = add_additional_border(style_dock_select, 2, 2, 2, 2); + style_dock_select->set_expand_margin_size_all(2); + style_dock_select->set_border_width_all(2); theme->set_stylebox("panel", "PopupPanel", style_dock_select); // SpinBox diff --git a/editor/icons/SCsub b/editor/icons/SCsub index 564188f315..86c51a50f3 100644 --- a/editor/icons/SCsub +++ b/editor/icons/SCsub @@ -88,5 +88,4 @@ make_editor_icons_builder = Builder(action=make_editor_icons_action, env['BUILDERS']['MakeEditorIconsBuilder'] = make_editor_icons_builder env.Alias('editor_icons', [env.MakeEditorIconsBuilder('#editor/editor_icons.gen.h', Glob("*.svg"))]) -env.editor_sources.append("#editor/editor_icons.gen.h") Export('env') diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 6db732ba5d..e8770febd9 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -2072,7 +2072,10 @@ void ScriptEditor::_update_selected_editor_menu() { } } - EditorHelp *eh = tab_container->get_current_tab_control()->cast_to<EditorHelp>(); + EditorHelp *eh = NULL; + if (tab_container->get_current_tab_control()) + eh = tab_container->get_current_tab_control()->cast_to<EditorHelp>(); + if (eh) { script_search_menu->show(); } else { @@ -2349,7 +2352,6 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { debug_menu = memnew(MenuButton); menu_hb->add_child(debug_menu); debug_menu->set_text(TTR("Debug")); - debug_menu->get_popup()->add_separator(); debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/step_over", TTR("Step Over"), KEY_F10), DEBUG_NEXT); debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/step_into", TTR("Step Into"), KEY_F11), DEBUG_STEP); debug_menu->get_popup()->add_separator(); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 1a3092b6e4..19de027287 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -75,9 +75,14 @@ void ScriptTextEditor::_load_theme_settings() { text_edit->clear_colors(); - /* keyword color */ + /* color from color_theme or from editor color */ + + Color background_color = EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0)); + if (EDITOR_DEF("text_editor/theme/adapted_code_editor_background_color", false)) + background_color = get_color("dark_color_1", "Editor"); - text_edit->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0))); + /* keyword color */ + text_edit->add_color_override("background_color", background_color); text_edit->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0, 0, 0, 0))); text_edit->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/highlighting/completion_selected_color", Color::html("434244"))); text_edit->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf"))); diff --git a/main/tests/test_shader_lang.cpp b/main/tests/test_shader_lang.cpp index dc581a71e2..f9516dad99 100644 --- a/main/tests/test_shader_lang.cpp +++ b/main/tests/test_shader_lang.cpp @@ -56,8 +56,6 @@ static String _mktab(int p_level) { static String _typestr(SL::DataType p_type) { return ShaderLanguage::get_datatype_name(p_type); - - return ""; } static String _prestr(SL::DataPrecision p_pres) { diff --git a/modules/gdscript/gd_function.h b/modules/gdscript/gd_function.h index 6d20b19777..661de0acce 100644 --- a/modules/gdscript/gd_function.h +++ b/modules/gdscript/gd_function.h @@ -210,8 +210,9 @@ public: #ifdef TOOLS_ENABLED ERR_FAIL_INDEX_V(p_idx, arg_names.size(), StringName()); return arg_names[p_idx]; -#endif +#else return StringName(); +#endif } Variant get_default_argument(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, default_arguments.size(), Variant()); diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 7d3857266e..b349b6b9a8 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1894,7 +1894,26 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { return NULL; } - if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) { + if (value->type == Node::TYPE_OPERATOR) { + // Maybe it's SomeEnum.VALUE + Node *current_value = value; + + while (current_value->type == Node::TYPE_OPERATOR) { + OperatorNode *op_node = static_cast<OperatorNode *>(current_value); + + if (op_node->op != OperatorNode::OP_INDEX_NAMED) { + _set_error("Invalid operator in pattern. Only index (`A.B`) is allowed"); + return NULL; + } + current_value = op_node->arguments[0]; + } + + if (current_value->type != Node::TYPE_IDENTIFIER) { + _set_error("Only constant expression or variables allowed in a pattern"); + return NULL; + } + + } else if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) { _set_error("Only constant expressions or variables allowed in a pattern"); return NULL; } diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 2d06c0f5d2..23201dc1b0 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -559,8 +559,9 @@ bool GDScript::_update_exports() { return changed; -#endif +#else return false; +#endif } void GDScript::update_exports() { diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 7b8b2abebb..5ad16c7337 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -49,7 +49,7 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra //end of file! if (vorbis_stream->loop) { //loop - seek_pos(0); + seek_pos(vorbis_stream->loop_offset); loops++; } else { for (int i = mixed; i < p_frames; i++) { @@ -227,6 +227,14 @@ bool AudioStreamOGGVorbis::has_loop() const { return loop; } +void AudioStreamOGGVorbis::set_loop_offset(float p_seconds) { + loop_offset = p_seconds; +} + +float AudioStreamOGGVorbis::get_loop_offset() const { + return loop_offset; +} + void AudioStreamOGGVorbis::_bind_methods() { ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamOGGVorbis::set_data); @@ -235,8 +243,12 @@ void AudioStreamOGGVorbis::_bind_methods() { ClassDB::bind_method(D_METHOD("set_loop", "enable"), &AudioStreamOGGVorbis::set_loop); ClassDB::bind_method(D_METHOD("has_loop"), &AudioStreamOGGVorbis::has_loop); + ClassDB::bind_method(D_METHOD("set_loop_offset", "seconds"), &AudioStreamOGGVorbis::set_loop_offset); + ClassDB::bind_method(D_METHOD("get_loop_offset"), &AudioStreamOGGVorbis::get_loop_offset); + ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_data", "get_data"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop", "has_loop"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop_offset", "get_loop_offset"); } AudioStreamOGGVorbis::AudioStreamOGGVorbis() { @@ -245,6 +257,7 @@ AudioStreamOGGVorbis::AudioStreamOGGVorbis() { length = 0; sample_rate = 1; channels = 1; + loop_offset = 0; decode_mem_size = 0; loop = false; } diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index 46cdfd3f2d..56bfe398c0 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -89,6 +89,7 @@ class AudioStreamOGGVorbis : public AudioStream { int channels; float length; bool loop; + float loop_offset; protected: static void _bind_methods(); @@ -97,6 +98,9 @@ public: void set_loop(bool p_enable); bool has_loop() const; + void set_loop_offset(float p_seconds); + float get_loop_offset() const; + virtual Ref<AudioStreamPlayback> instance_playback(); virtual String get_stream_name() const; diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index f0a7ee1ec6..5a1157bf9c 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -72,11 +72,13 @@ String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options, int p_preset) const { r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_offset"), 0)); } Error ResourceImporterOGGVorbis::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { bool loop = p_options["loop"]; + float loop_offset = p_options["loop_offset"]; FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); if (!f) { @@ -98,6 +100,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin ogg_stream->set_data(data); ogg_stream->set_loop(loop); + ogg_stream->set_loop_offset(loop_offset); return ResourceSaver::save(p_save_path + ".oggstr", ogg_stream); } diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index 46931fb0f6..c74188d9ea 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -82,9 +82,9 @@ Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, const char *s size_t str_len = strlen(svg_str); PoolVector<uint8_t> src_data; - src_data.resize(str_len); + src_data.resize(str_len + 1); PoolVector<uint8_t>::Write src_w = src_data.write(); - memcpy(src_w.ptr(), svg_str, str_len); + memcpy(src_w.ptr(), svg_str, str_len + 1); return _create_image(p_image, &src_data, p_scale, upsample); } @@ -93,9 +93,10 @@ Error ImageLoaderSVG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force uint32_t size = f->get_len(); PoolVector<uint8_t> src_image; - src_image.resize(size); + src_image.resize(size + 1); PoolVector<uint8_t>::Write src_w = src_image.write(); f->get_buffer(src_w.ptr(), size); + src_w.ptr()[size] = '\0'; return _create_image(p_image, &src_image, p_scale, 1.0); } diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 78b70934c0..25c2ebd6d2 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -585,7 +585,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { r_token.type = TK_BASIC_TYPE; r_token.value = i; return OK; - break; } } diff --git a/platform/android/godot_android.cpp b/platform/android/godot_android.cpp index 5933b83d06..2dd2c0532a 100644 --- a/platform/android/godot_android.cpp +++ b/platform/android/godot_android.cpp @@ -833,7 +833,6 @@ void android_main(struct android_app *app) { if (engine.requested_quit) { engine_term_display(&engine); exit(0); - return; } // LOGI("end\n"); diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 256c9eecf7..4440f2843d 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -96,8 +96,8 @@ public: virtual int get_screen_count() const; virtual int get_current_screen() const; virtual void set_current_screen(int p_screen); - virtual Point2 get_screen_position(int p_screen = 0) const; - virtual Size2 get_screen_size(int p_screen = 0) const; + virtual Point2 get_screen_position(int p_screen = -1) const; + virtual Size2 get_screen_size(int p_screen = -1) const; virtual void set_window_title(const String &p_title); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2 p_size); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index d339baf024..f49acb04de 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -687,8 +687,6 @@ OS::VideoMode OS_JavaScript::get_video_mode(int p_screen) const { Size2 OS_JavaScript::get_screen_size(int p_screen) const { - ERR_FAIL_COND_V(p_screen != 0, Size2()); - EmscriptenFullscreenChangeEvent ev; EMSCRIPTEN_RESULT result = emscripten_get_fullscreen_status(&ev); ERR_FAIL_COND_V(result != EMSCRIPTEN_RESULT_SUCCESS, Size2()); diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 13c500b3dc..ff484204c7 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -124,7 +124,7 @@ public: virtual VideoMode get_video_mode(int p_screen = 0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const; - virtual Size2 get_screen_size(int p_screen = 0) const; + virtual Size2 get_screen_size(int p_screen = -1) const; virtual void set_window_size(const Size2); virtual Size2 get_window_size() const; diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 56e6802eeb..827114cd2b 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -187,9 +187,9 @@ public: virtual int get_screen_count() const; virtual int get_current_screen() const; virtual void set_current_screen(int p_screen); - virtual Point2 get_screen_position(int p_screen = 0) const; - virtual Size2 get_screen_size(int p_screen = 0) const; - virtual int get_screen_dpi(int p_screen = 0) const; + virtual Point2 get_screen_position(int p_screen = -1) const; + virtual Size2 get_screen_size(int p_screen = -1) const; + virtual int get_screen_dpi(int p_screen = -1) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2 &p_position); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 34f1a93f3b..a0fc53d517 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1433,6 +1433,10 @@ void OS_OSX::set_current_screen(int p_screen) { }; Point2 OS_OSX::get_screen_position(int p_screen) const { + if (p_screen == -1) { + p_screen = get_current_screen(); + } + NSArray *screenArray = [NSScreen screens]; if (p_screen < [screenArray count]) { float displayScale = 1.0; @@ -1449,6 +1453,10 @@ Point2 OS_OSX::get_screen_position(int p_screen) const { } int OS_OSX::get_screen_dpi(int p_screen) const { + if (p_screen == -1) { + p_screen = get_current_screen(); + } + NSArray *screenArray = [NSScreen screens]; if (p_screen < [screenArray count]) { float displayScale = 1.0; @@ -1469,6 +1477,10 @@ int OS_OSX::get_screen_dpi(int p_screen) const { } Size2 OS_OSX::get_screen_size(int p_screen) const { + if (p_screen == -1) { + p_screen = get_current_screen(); + } + NSArray *screenArray = [NSScreen screens]; if (p_screen < [screenArray count]) { float displayScale = 1.0; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 2e908b82ab..db453a5f46 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1384,7 +1384,7 @@ static BOOL CALLBACK _MonitorEnumProcPos(HMONITOR hMonitor, HDC hdcMonitor, LPRE Point2 OS_Windows::get_screen_position(int p_screen) const { - EnumPosData data = { 0, p_screen, Point2() }; + EnumPosData data = { 0, p_screen == -1 ? get_current_screen() : p_screen, Point2() }; EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcPos, (LPARAM)&data); return data.pos; } @@ -1409,7 +1409,7 @@ static BOOL CALLBACK _MonitorEnumProcSize(HMONITOR hMonitor, HDC hdcMonitor, LPR Size2 OS_Windows::get_screen_size(int p_screen) const { - EnumSizeData data = { 0, p_screen, Size2() }; + EnumSizeData data = { 0, p_screen == -1 ? get_current_screen() : p_screen, Size2() }; EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcSize, (LPARAM)&data); return data.size; } @@ -1433,7 +1433,7 @@ static BOOL CALLBACK _MonitorEnumProcDpi(HMONITOR hMonitor, HDC hdcMonitor, LPRE int OS_Windows::get_screen_dpi(int p_screen) const { - EnumDpiData data = { 0, p_screen, 72 }; + EnumDpiData data = { 0, p_screen == -1 ? get_current_screen() : p_screen, 72 }; EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcDpi, (LPARAM)&data); return data.dpi; } diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index e9af14f11c..deb1ae0982 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -194,9 +194,9 @@ public: virtual int get_screen_count() const; virtual int get_current_screen() const; virtual void set_current_screen(int p_screen); - virtual Point2 get_screen_position(int p_screen = 0) const; - virtual Size2 get_screen_size(int p_screen = 0) const; - virtual int get_screen_dpi(int p_screen = 0) const; + virtual Point2 get_screen_position(int p_screen = -1) const; + virtual Size2 get_screen_size(int p_screen = -1) const; + virtual int get_screen_dpi(int p_screen = -1) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2 &p_position); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 8b4253c72c..dbc3914410 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -761,6 +761,10 @@ void OS_X11::set_current_screen(int p_screen) { } Point2 OS_X11::get_screen_position(int p_screen) const { + if (p_screen == -1) { + p_screen = get_current_screen(); + } + // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); @@ -782,6 +786,10 @@ Point2 OS_X11::get_screen_position(int p_screen) const { } Size2 OS_X11::get_screen_size(int p_screen) const { + if (p_screen == -1) { + p_screen = get_current_screen(); + } + // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); @@ -797,6 +805,9 @@ Size2 OS_X11::get_screen_size(int p_screen) const { } int OS_X11::get_screen_dpi(int p_screen) const { + if (p_screen == -1) { + p_screen = get_current_screen(); + } //invalid screen? ERR_FAIL_INDEX_V(p_screen, get_screen_count(), 0); diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index db70f8f84a..497ce1dde2 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -233,9 +233,9 @@ public: virtual int get_screen_count() const; virtual int get_current_screen() const; virtual void set_current_screen(int p_screen); - virtual Point2 get_screen_position(int p_screen = 0) const; - virtual Size2 get_screen_size(int p_screen = 0) const; - virtual int get_screen_dpi(int p_screen = 0) const; + virtual Point2 get_screen_position(int p_screen = -1) const; + virtual Size2 get_screen_size(int p_screen = -1) const; + virtual int get_screen_dpi(int p_screen = -1) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2 &p_position); virtual Size2 get_window_size() const; diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index a5a59252a9..debdc22b65 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -36,6 +36,9 @@ void ParallaxLayer::set_motion_scale(const Size2 &p_scale) { motion_scale = p_scale; + if (!get_parent()) + return; + ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); if (is_inside_tree() && pb) { Vector2 ofs = pb->get_final_offset(); @@ -53,6 +56,9 @@ void ParallaxLayer::set_motion_offset(const Size2 &p_offset) { motion_offset = p_offset; + if (!get_parent()) + return; + ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); if (is_inside_tree() && pb) { Vector2 ofs = pb->get_final_offset(); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 6a3ef66e0a..36fc9a6b3a 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1839,8 +1839,6 @@ Control *Control::find_prev_valid_focus() const { } return NULL; - - return NULL; } Control::FocusMode Control::get_focus_mode() const { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f15fb71f87..68529ae255 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -3656,9 +3656,6 @@ void TextEdit::cut() { void TextEdit::copy() { - if (!selection.active) - return; - if (!selection.active) { String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length()); OS::get_singleton()->set_clipboard(clipboard); diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index 08025452d8..59cff84719 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -57,9 +57,33 @@ Ref<Texture> TextureProgress::get_over_texture() const { return over; } +void TextureProgress::set_stretch_margin(Margin p_margin, int p_size) { + ERR_FAIL_INDEX(p_margin, 4); + stretch_margin[p_margin] = p_size; + update(); + minimum_size_changed(); +} + +int TextureProgress::get_stretch_margin(Margin p_margin) const { + ERR_FAIL_INDEX_V(p_margin, 4, 0); + return stretch_margin[p_margin]; +} + +void TextureProgress::set_nine_patch_stretch(bool p_stretch) { + nine_patch_stretch = p_stretch; + update(); + minimum_size_changed(); +} + +bool TextureProgress::get_nine_patch_stretch() const { + return nine_patch_stretch; +} + Size2 TextureProgress::get_minimum_size() const { - if (under.is_valid()) + if (nine_patch_stretch) + return Size2(stretch_margin[MARGIN_LEFT] + stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_TOP] + stretch_margin[MARGIN_BOTTOM]); + else if (under.is_valid()) return under->get_size(); else if (over.is_valid()) return over->get_size(); @@ -122,80 +146,165 @@ Point2 TextureProgress::get_relative_center() { return p; } +void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, FillMode p_mode, double p_ratio) { + Vector2 texture_size = p_texture->get_size(); + Vector2 topleft = Vector2(stretch_margin[MARGIN_LEFT], stretch_margin[MARGIN_TOP]); + Vector2 bottomright = Vector2(stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_BOTTOM]); + + Rect2 src_rect = Rect2(Point2(), texture_size); + Rect2 dst_rect = Rect2(Point2(), get_size()); + + if (p_ratio < 1.0) { + // Drawing a partially-filled 9-patch is a little tricky - + // texture is divided by 3 sections toward fill direction, + // then middle section is streching while the other two aren't. + + double width_total = 0.0; + double width_texture = 0.0; + double first_section_size = 0.0; + double last_section_size = 0.0; + switch (mode) { + case FILL_LEFT_TO_RIGHT: + case FILL_RIGHT_TO_LEFT: { + width_total = dst_rect.size.x; + width_texture = texture_size.x; + first_section_size = topleft.x; + last_section_size = bottomright.x; + } break; + case FILL_TOP_TO_BOTTOM: + case FILL_BOTTOM_TO_TOP: { + width_total = dst_rect.size.y; + width_texture = texture_size.y; + first_section_size = topleft.y; + last_section_size = bottomright.y; + } break; + } + + double width_filled = width_total * p_ratio; + double middle_section_size = MAX(0.0, width_texture - first_section_size - last_section_size); + + middle_section_size *= MIN(1.0, (MAX(0.0, width_filled - first_section_size) / MAX(1.0, width_total - first_section_size - last_section_size))); + last_section_size = MAX(0.0, last_section_size - (width_total - width_filled)); + width_texture = MIN(width_texture, first_section_size + middle_section_size + last_section_size); + + switch (mode) { + case FILL_LEFT_TO_RIGHT: { + src_rect.size.x = width_texture; + dst_rect.size.x = width_filled; + bottomright.x = last_section_size; + } break; + case FILL_RIGHT_TO_LEFT: { + src_rect.position.x += src_rect.size.x - width_texture; + src_rect.size.x = width_texture; + dst_rect.position.x += width_total - width_filled; + dst_rect.size.x = width_filled; + topleft.x = last_section_size; + } break; + case FILL_TOP_TO_BOTTOM: { + src_rect.size.y = width_texture; + dst_rect.size.y = width_filled; + bottomright.y = last_section_size; + } break; + case FILL_BOTTOM_TO_TOP: { + src_rect.position.y += src_rect.size.y - width_texture; + src_rect.size.y = width_texture; + dst_rect.position.y += width_total - width_filled; + dst_rect.size.y = width_filled; + topleft.y = last_section_size; + } break; + } + } + + RID ci = get_canvas_item(); + VS::get_singleton()->canvas_item_add_nine_patch(ci, dst_rect, src_rect, p_texture->get_rid(), topleft, bottomright); +} + void TextureProgress::_notification(int p_what) { const float corners[12] = { -0.125, -0.375, -0.625, -0.875, 0.125, 0.375, 0.625, 0.875, 1.125, 1.375, 1.625, 1.875 }; switch (p_what) { case NOTIFICATION_DRAW: { - if (under.is_valid()) - draw_texture(under, Point2()); - if (progress.is_valid()) { - Size2 s = progress->get_size(); - switch (mode) { - case FILL_LEFT_TO_RIGHT: { - Rect2 region = Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)); - draw_texture_rect_region(progress, region, region); - } break; - case FILL_RIGHT_TO_LEFT: { - Rect2 region = Rect2(Point2(s.x - s.x * get_as_ratio(), 0), Size2(s.x * get_as_ratio(), s.y)); - draw_texture_rect_region(progress, region, region); - } break; - case FILL_TOP_TO_BOTTOM: { - Rect2 region = Rect2(Point2(), Size2(s.x, s.y * get_as_ratio())); - draw_texture_rect_region(progress, region, region); - } break; - case FILL_BOTTOM_TO_TOP: { - Rect2 region = Rect2(Point2(0, s.y - s.y * get_as_ratio()), Size2(s.x, s.y * get_as_ratio())); - draw_texture_rect_region(progress, region, region); - } break; - case FILL_CLOCKWISE: - case FILL_COUNTER_CLOCKWISE: { - float val = get_as_ratio() * rad_max_degrees / 360; - if (val == 1) { - Rect2 region = Rect2(Point2(), s); + if (nine_patch_stretch && (mode == FILL_LEFT_TO_RIGHT || mode == FILL_RIGHT_TO_LEFT || mode == FILL_TOP_TO_BOTTOM || mode == FILL_BOTTOM_TO_TOP)) { + if (under.is_valid()) { + draw_nine_patch_stretched(under, FILL_LEFT_TO_RIGHT, 1.0); + } + if (progress.is_valid()) { + draw_nine_patch_stretched(progress, mode, get_as_ratio()); + } + if (over.is_valid()) { + draw_nine_patch_stretched(over, FILL_LEFT_TO_RIGHT, 1.0); + } + } else { + if (under.is_valid()) + draw_texture(under, Point2()); + if (progress.is_valid()) { + Size2 s = progress->get_size(); + switch (mode) { + case FILL_LEFT_TO_RIGHT: { + Rect2 region = Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)); + draw_texture_rect_region(progress, region, region); + } break; + case FILL_RIGHT_TO_LEFT: { + Rect2 region = Rect2(Point2(s.x - s.x * get_as_ratio(), 0), Size2(s.x * get_as_ratio(), s.y)); draw_texture_rect_region(progress, region, region); - } else if (val != 0) { - Array pts; - float direction = mode == FILL_CLOCKWISE ? 1 : -1; - float start = rad_init_angle / 360; - float end = start + direction * val; - pts.append(start); - pts.append(end); - float from = MIN(start, end); - float to = MAX(start, end); - for (int i = 0; i < 12; i++) - if (corners[i] > from && corners[i] < to) - pts.append(corners[i]); - pts.sort(); - Vector<Point2> uvs; - Vector<Point2> points; - uvs.push_back(get_relative_center()); - points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y)); - for (int i = 0; i < pts.size(); i++) { - Point2 uv = unit_val_to_uv(pts[i]); - if (uvs.find(uv) >= 0) - continue; - uvs.push_back(uv); - points.push_back(Point2(uv.x * s.x, uv.y * s.y)); + } break; + case FILL_TOP_TO_BOTTOM: { + Rect2 region = Rect2(Point2(), Size2(s.x, s.y * get_as_ratio())); + draw_texture_rect_region(progress, region, region); + } break; + case FILL_BOTTOM_TO_TOP: { + Rect2 region = Rect2(Point2(0, s.y - s.y * get_as_ratio()), Size2(s.x, s.y * get_as_ratio())); + draw_texture_rect_region(progress, region, region); + } break; + case FILL_CLOCKWISE: + case FILL_COUNTER_CLOCKWISE: { + float val = get_as_ratio() * rad_max_degrees / 360; + if (val == 1) { + Rect2 region = Rect2(Point2(), s); + draw_texture_rect_region(progress, region, region); + } else if (val != 0) { + Array pts; + float direction = mode == FILL_CLOCKWISE ? 1 : -1; + float start = rad_init_angle / 360; + float end = start + direction * val; + pts.append(start); + pts.append(end); + float from = MIN(start, end); + float to = MAX(start, end); + for (int i = 0; i < 12; i++) + if (corners[i] > from && corners[i] < to) + pts.append(corners[i]); + pts.sort(); + Vector<Point2> uvs; + Vector<Point2> points; + uvs.push_back(get_relative_center()); + points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y)); + for (int i = 0; i < pts.size(); i++) { + Point2 uv = unit_val_to_uv(pts[i]); + if (uvs.find(uv) >= 0) + continue; + uvs.push_back(uv); + points.push_back(Point2(uv.x * s.x, uv.y * s.y)); + } + draw_polygon(points, Vector<Color>(), uvs, progress); + } + if (Engine::get_singleton()->is_editor_hint()) { + Point2 p = progress->get_size(); + p.x *= get_relative_center().x; + p.y *= get_relative_center().y; + p = p.floor(); + draw_line(p - Point2(8, 0), p + Point2(8, 0), Color(0.9, 0.5, 0.5), 2); + draw_line(p - Point2(0, 8), p + Point2(0, 8), Color(0.9, 0.5, 0.5), 2); } - draw_polygon(points, Vector<Color>(), uvs, progress); - } - if (Engine::get_singleton()->is_editor_hint()) { - Point2 p = progress->get_size(); - p.x *= get_relative_center().x; - p.y *= get_relative_center().y; - p = p.floor(); - draw_line(p - Point2(8, 0), p + Point2(8, 0), Color(0.9, 0.5, 0.5), 2); - draw_line(p - Point2(0, 8), p + Point2(0, 8), Color(0.9, 0.5, 0.5), 2); - } - } break; - default: - draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y))); + } break; + default: + draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y))); + } } + if (over.is_valid()) + draw_texture(over, Point2()); } - if (over.is_valid()) - draw_texture(over, Point2()); } break; } @@ -265,6 +374,12 @@ void TextureProgress::_bind_methods() { ClassDB::bind_method(D_METHOD("set_fill_degrees", "mode"), &TextureProgress::set_fill_degrees); ClassDB::bind_method(D_METHOD("get_fill_degrees"), &TextureProgress::get_fill_degrees); + ClassDB::bind_method(D_METHOD("set_stretch_margin", "margin", "value"), &TextureProgress::set_stretch_margin); + ClassDB::bind_method(D_METHOD("get_stretch_margin", "margin"), &TextureProgress::get_stretch_margin); + + ClassDB::bind_method(D_METHOD("set_nine_patch_stretch", "stretch"), &TextureProgress::set_nine_patch_stretch); + ClassDB::bind_method(D_METHOD("get_nine_patch_stretch"), &TextureProgress::get_nine_patch_stretch); + ADD_GROUP("Textures", "texture_"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_under", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_under_texture", "get_under_texture"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_over", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_over_texture", "get_over_texture"); @@ -274,6 +389,12 @@ void TextureProgress::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "radial_initial_angle", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_radial_initial_angle", "get_radial_initial_angle"); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "radial_fill_degrees", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_fill_degrees", "get_fill_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "radial_center_offset"), "set_radial_center_offset", "get_radial_center_offset"); + ADD_GROUP("Stretch", "stretch_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "nine_patch_stretch"), "set_nine_patch_stretch", "get_nine_patch_stretch"); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "stretch_margin_left", PROPERTY_HINT_RANGE, "0,16384,1"), "set_stretch_margin", "get_stretch_margin", MARGIN_LEFT); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "stretch_margin_top", PROPERTY_HINT_RANGE, "0,16384,1"), "set_stretch_margin", "get_stretch_margin", MARGIN_TOP); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "stretch_margin_right", PROPERTY_HINT_RANGE, "0,16384,1"), "set_stretch_margin", "get_stretch_margin", MARGIN_RIGHT); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "stretch_margin_bottom", PROPERTY_HINT_RANGE, "0,16384,1"), "set_stretch_margin", "get_stretch_margin", MARGIN_BOTTOM); BIND_ENUM_CONSTANT(FILL_LEFT_TO_RIGHT); BIND_ENUM_CONSTANT(FILL_RIGHT_TO_LEFT); @@ -289,4 +410,10 @@ TextureProgress::TextureProgress() { rad_center_off = Point2(); rad_max_degrees = 360; set_mouse_filter(MOUSE_FILTER_PASS); + + nine_patch_stretch = false; + stretch_margin[MARGIN_LEFT] = 0; + stretch_margin[MARGIN_RIGHT] = 0; + stretch_margin[MARGIN_BOTTOM] = 0; + stretch_margin[MARGIN_TOP] = 0; } diff --git a/scene/gui/texture_progress.h b/scene/gui/texture_progress.h index 3c018febf3..20546bd11f 100644 --- a/scene/gui/texture_progress.h +++ b/scene/gui/texture_progress.h @@ -75,6 +75,12 @@ public: void set_over_texture(const Ref<Texture> &p_texture); Ref<Texture> get_over_texture() const; + void set_stretch_margin(Margin p_margin, int p_size); + int get_stretch_margin(Margin p_margin) const; + + void set_nine_patch_stretch(bool p_stretch); + bool get_nine_patch_stretch() const; + Size2 get_minimum_size() const; TextureProgress(); @@ -84,9 +90,12 @@ private: float rad_init_angle; float rad_max_degrees; Point2 rad_center_off; + bool nine_patch_stretch; + int stretch_margin[4]; Point2 unit_val_to_uv(float val); Point2 get_relative_center(); + void draw_nine_patch_stretched(const Ref<Texture> &p_texture, FillMode p_mode, double p_ratio); }; VARIANT_ENUM_CAST(TextureProgress::FillMode); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 00460e9eda..10ab28150b 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -630,7 +630,7 @@ void SceneTree::_notification(int p_notification) { case NOTIFICATION_WM_ABOUT: { #ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { + if (EditorNode::get_singleton()) { EditorNode::get_singleton()->show_about(); } else { #endif diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 9309cef89f..7b2a9ffbc2 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -191,6 +191,22 @@ void StyleBoxTexture::set_expand_margin_size(Margin p_expand_margin, float p_siz emit_changed(); } +void StyleBoxTexture::set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) { + expand_margin[MARGIN_LEFT] = p_left; + expand_margin[MARGIN_TOP] = p_top; + expand_margin[MARGIN_RIGHT] = p_right; + expand_margin[MARGIN_BOTTOM] = p_bottom; + emit_changed(); +} + +void StyleBoxTexture::set_expand_margin_size_all(float p_expand_margin_size) { + for (int i = 0; i < 4; i++) { + + expand_margin[i] = p_expand_margin_size; + } + emit_changed(); +} + float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const { ERR_FAIL_INDEX_V(p_expand_margin, 4, 0); @@ -257,6 +273,8 @@ void StyleBoxTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("get_margin_size", "margin"), &StyleBoxTexture::get_margin_size); ClassDB::bind_method(D_METHOD("set_expand_margin_size", "margin", "size"), &StyleBoxTexture::set_expand_margin_size); + ClassDB::bind_method(D_METHOD("set_expand_margin_all", "size"), &StyleBoxTexture::set_expand_margin_size_all); + ClassDB::bind_method(D_METHOD("set_expand_margin_individual", "size_left", "size_top", "size_right", "size_bottom"), &StyleBoxTexture::set_expand_margin_size_individual); ClassDB::bind_method(D_METHOD("get_expand_margin_size", "margin"), &StyleBoxTexture::get_expand_margin_size); ClassDB::bind_method(D_METHOD("set_region_rect", "region"), &StyleBoxTexture::set_region_rect); @@ -421,7 +439,25 @@ void StyleBoxFlat::set_expand_margin_size(Margin p_expand_margin, float p_size) expand_margin[p_expand_margin] = p_size; emit_changed(); } + +void StyleBoxFlat::set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) { + expand_margin[MARGIN_LEFT] = p_left; + expand_margin[MARGIN_TOP] = p_top; + expand_margin[MARGIN_RIGHT] = p_right; + expand_margin[MARGIN_BOTTOM] = p_bottom; + emit_changed(); +} + +void StyleBoxFlat::set_expand_margin_size_all(float p_expand_margin_size) { + for (int i = 0; i < 4; i++) { + + expand_margin[i] = p_expand_margin_size; + } + emit_changed(); +} + float StyleBoxFlat::get_expand_margin_size(Margin p_expand_margin) const { + return expand_margin[p_expand_margin]; } void StyleBoxFlat::set_filled(bool p_filled) { @@ -736,6 +772,8 @@ void StyleBoxFlat::_bind_methods() { ClassDB::bind_method(D_METHOD("get_corner_radius", "corner"), &StyleBoxFlat::get_corner_radius); ClassDB::bind_method(D_METHOD("set_expand_margin", "margin", "size"), &StyleBoxFlat::set_expand_margin_size); + ClassDB::bind_method(D_METHOD("set_expand_margin_all", "size"), &StyleBoxFlat::set_expand_margin_size_all); + ClassDB::bind_method(D_METHOD("set_expand_margin_individual", "size_left", "size_top", "size_right", "size_bottom"), &StyleBoxFlat::set_expand_margin_size_individual); ClassDB::bind_method(D_METHOD("get_expand_margin", "margin"), &StyleBoxFlat::get_expand_margin_size); ClassDB::bind_method(D_METHOD("set_filled", "filled"), &StyleBoxFlat::set_filled); diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index a750fae753..30eb9543e8 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -101,6 +101,8 @@ protected: public: void set_expand_margin_size(Margin p_expand_margin, float p_size); + void set_expand_margin_size_all(float p_expand_margin_size); + void set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom); float get_expand_margin_size(Margin p_expand_margin) const; void set_margin_size(Margin p_margin, float p_size); @@ -196,6 +198,8 @@ public: //EXPANDS void set_expand_margin_size(Margin p_expand_margin, float p_size); + void set_expand_margin_size_all(float p_expand_margin_size); + void set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom); float get_expand_margin_size(Margin p_expand_margin) const; //FILLED |