diff options
57 files changed, 988 insertions, 392 deletions
diff --git a/core/error/error_macros.cpp b/core/error/error_macros.cpp index ddfee3fc5d..8376c0aaf8 100644 --- a/core/error/error_macros.cpp +++ b/core/error/error_macros.cpp @@ -118,11 +118,11 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool p_editor_notify, bool p_fatal) { String fstr(p_fatal ? "FATAL: " : ""); String err(fstr + "Index " + p_index_str + " = " + itos(p_index) + " is out of bounds (" + p_size_str + " = " + itos(p_size) + ")."); - _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message); + _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message, p_editor_notify, ERR_HANDLER_ERROR); } void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool p_editor_notify, bool p_fatal) { - _err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), p_fatal); + _err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), p_editor_notify, p_fatal); } void _err_flush_stdout() { diff --git a/core/error/error_macros.h b/core/error/error_macros.h index 63a2d22416..65804b7796 100644 --- a/core/error/error_macros.h +++ b/core/error/error_macros.h @@ -189,12 +189,12 @@ void _err_flush_stdout(); * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0. * If not, the application crashes. */ -#define CRASH_BAD_INDEX(m_index, m_size) \ - if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \ - _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define CRASH_BAD_INDEX(m_index, m_size) \ + if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \ + _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", false, true); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void)0) /** @@ -204,12 +204,12 @@ void _err_flush_stdout(); * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0. * If not, prints `m_msg` and the application crashes. */ -#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \ - if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \ - _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \ + if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \ + _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, false, true); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void)0) // Unsigned integer index out of bounds error macros. @@ -292,12 +292,12 @@ void _err_flush_stdout(); * Ensures an unsigned integer index `m_index` is less than `m_size`. * If not, the application crashes. */ -#define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \ - if (unlikely((m_index) >= (m_size))) { \ - _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \ + if (unlikely((m_index) >= (m_size))) { \ + _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", false, true); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void)0) /** @@ -307,12 +307,12 @@ void _err_flush_stdout(); * Ensures an unsigned integer index `m_index` is less than `m_size`. * If not, prints `m_msg` and the application crashes. */ -#define CRASH_BAD_UNSIGNED_INDEX_MSG(m_index, m_size, m_msg) \ - if (unlikely((m_index) >= (m_size))) { \ - _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define CRASH_BAD_UNSIGNED_INDEX_MSG(m_index, m_size, m_msg) \ + if (unlikely((m_index) >= (m_size))) { \ + _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, false, true); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void)0) // Null reference error macros. diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index a54804c5dc..9bfe46727b 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -794,7 +794,7 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) { bool found_route = false; - Vector<AStar3D::Point *> open_list; + LocalVector<AStar3D::Point *> open_list; SortArray<AStar3D::Point *, AStar3D::SortPoints> sorter; begin_point->g_score = 0; @@ -802,19 +802,19 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) { open_list.push_back(begin_point); while (!open_list.is_empty()) { - AStar3D::Point *p = open_list[0]; // The currently processed point + AStar3D::Point *p = open_list[0]; // The currently processed point. if (p == end_point) { found_route = true; break; } - sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list + sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list. open_list.remove_at(open_list.size() - 1); - p->closed_pass = astar.pass; // Mark the point as closed + p->closed_pass = astar.pass; // Mark the point as closed. for (OAHashMap<int64_t, AStar3D::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - AStar3D::Point *e = *(it.value); // The neighbour point + AStar3D::Point *e = *(it.value); // The neighbour point. if (!e->enabled || e->closed_pass == astar.pass) { continue; @@ -837,9 +837,9 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) { e->f_score = e->g_score + _estimate_cost(e->id, end_point->id); if (new_point) { // The position of the new points is already known. - sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr()); } else { - sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr()); } } } diff --git a/core/math/expression.cpp b/core/math/expression.cpp index da52bb9465..d1ec987d56 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -434,14 +434,13 @@ Error Expression::_get_token(Token &r_token) { } return OK; - } else if (is_ascii_char(cchar) || is_underscore(cchar)) { - String id; - bool first = true; + } else if (is_unicode_identifier_start(cchar)) { + String id = String::chr(cchar); + cchar = GET_CHAR(); - while (is_ascii_char(cchar) || is_underscore(cchar) || (!first && is_digit(cchar))) { + while (is_unicode_identifier_continue(cchar)) { id += String::chr(cchar); cchar = GET_CHAR(); - first = false; } str_ofs--; //go back one diff --git a/doc/classes/AudioStreamPlaybackPolyphonic.xml b/doc/classes/AudioStreamPlaybackPolyphonic.xml new file mode 100644 index 0000000000..35ab05058a --- /dev/null +++ b/doc/classes/AudioStreamPlaybackPolyphonic.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="AudioStreamPlaybackPolyphonic" inherits="AudioStreamPlayback" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + Playback instance for [AudioStreamPolyphonic]. + </brief_description> + <description> + Playback instance for [AudioStreamPolyphonic]. After setting the [code]stream[/code] property of [AudioStreamPlayer], [AudioStreamPlayer2D], or [AudioStreamPlayer3D], the playback instance can be obtained by calling [method AudioStreamPlayer.get_stream_playback], [method AudioStreamPlayer2D.get_stream_playback] or [method AudioStreamPlayer3D.get_stream_playback] methods. + </description> + <tutorials> + </tutorials> + <methods> + <method name="is_stream_playing" qualifiers="const"> + <return type="bool" /> + <param index="0" name="stream" type="int" /> + <description> + Return true whether the stream associated with an integer ID is still playing. Check [method play_stream] for information on when this ID becomes invalid. + </description> + </method> + <method name="play_stream"> + <return type="int" /> + <param index="0" name="stream" type="AudioStream" /> + <param index="1" name="from_offset" type="float" default="0" /> + <param index="2" name="volume_db" type="float" default="0" /> + <param index="3" name="pitch_scale" type="float" default="1.0" /> + <description> + Play an [AudioStream] at a given offset, volume and pitch scale. Playback starts immediately. + The return value is an unique integer ID that is associated to this playback stream and which can be used to controll it. + This ID becomes invalid when the stream ends (if it does not loop), when the [AudioStreamPlaybackPolyphonic] is stopped, or when [method stop_stream] is called. + This function returns [constant INVALID_ID] if the amount of streams currently playing equals [member AudioStreamPolyphonic.polyphony]. If you need a higher amount of maximum polyphony, raise this value. + </description> + </method> + <method name="set_stream_pitch_scale"> + <return type="void" /> + <param index="0" name="stream" type="int" /> + <param index="1" name="pitch_scale" type="float" /> + <description> + Change the stream pitch scale. The [param stream] argument is an integer ID returned by [method play_stream]. + </description> + </method> + <method name="set_stream_volume"> + <return type="void" /> + <param index="0" name="stream" type="int" /> + <param index="1" name="volume_db" type="float" /> + <description> + Change the stream volume (in db). The [param stream] argument is an integer ID returned by [method play_stream]. + </description> + </method> + <method name="stop_stream"> + <return type="void" /> + <param index="0" name="stream" type="int" /> + <description> + Stop a stream. The [param stream] argument is an integer ID returned by [method play_stream], which becomes invalid after calling this function. + </description> + </method> + </methods> + <constants> + <constant name="INVALID_ID" value="-1"> + Returned by [method play_stream] in case it could not allocate a stream for playback. + </constant> + </constants> +</class> diff --git a/doc/classes/AudioStreamPolyphonic.xml b/doc/classes/AudioStreamPolyphonic.xml new file mode 100644 index 0000000000..baa1fc7037 --- /dev/null +++ b/doc/classes/AudioStreamPolyphonic.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="AudioStreamPolyphonic" inherits="AudioStream" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + AudioStream that lets the user play custom streams at any time from code, simultaneously using a single player. + </brief_description> + <description> + AudioStream that lets the user play custom streams at any time from code, simultaneously using a single player. + Playback control is done via the [AudioStreamPlaybackPolyphonic] instance set inside the player, which can be obtained via [method AudioStreamPlayer.get_stream_playback], [method AudioStreamPlayer2D.get_stream_playback] or [method AudioStreamPlayer3D.get_stream_playback] methods. Obtaining the playback instance is only valid after the [code]stream[/code] property is set as an [AudioStreamPolyphonic] in those players. + </description> + <tutorials> + </tutorials> + <members> + <member name="polyphony" type="int" setter="set_polyphony" getter="get_polyphony" default="32"> + Maximum amount of simultaneous streams that can be played. + </member> + </members> +</class> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index bd68dc7a64..be272976f4 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -384,6 +384,9 @@ <member name="debug/gdscript/warnings/assert_always_true" type="int" setter="" getter="" default="1"> When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when an [code]assert[/code] call always evaluates to true. </member> + <member name="debug/gdscript/warnings/confusable_identifier" type="int" setter="" getter="" default="1"> + When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when an indentifier contains characters that can be confused with something else, like when mixing different alphabets. + </member> <member name="debug/gdscript/warnings/constant_used_as_function" type="int" setter="" getter="" default="1"> When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when a constant is used as a function. </member> diff --git a/doc/classes/StyleBox.xml b/doc/classes/StyleBox.xml index ff6d4d8821..4a63f4488c 100644 --- a/doc/classes/StyleBox.xml +++ b/doc/classes/StyleBox.xml @@ -17,21 +17,16 @@ <description> </description> </method> - <method name="_get_center_size" qualifiers="virtual const"> - <return type="Vector2" /> - <description> - </description> - </method> <method name="_get_draw_rect" qualifiers="virtual const"> <return type="Rect2" /> <param index="0" name="rect" type="Rect2" /> <description> </description> </method> - <method name="_get_style_margin" qualifiers="virtual const"> - <return type="float" /> - <param index="0" name="side" type="int" enum="Side" /> + <method name="_get_minimum_size" qualifiers="virtual const"> + <return type="Vector2" /> <description> + Virtual method to be implemented by the user. Returns a custom minimum size that the stylebox must respect when drawing. By default [method get_minimum_size] only takes content margins into account. This method can be overridden to add another size restriction. A combination of the default behavior and the output of this method will be used, to account for both sizes. </description> </method> <method name="_test_mask" qualifiers="virtual const"> @@ -50,10 +45,11 @@ The [RID] value can either be the result of [method CanvasItem.get_canvas_item] called on an existing [CanvasItem]-derived node, or directly from creating a canvas item in the [RenderingServer] with [method RenderingServer.canvas_item_create]. </description> </method> - <method name="get_center_size" qualifiers="const"> - <return type="Vector2" /> + <method name="get_content_margin" qualifiers="const"> + <return type="float" /> + <param index="0" name="margin" type="int" enum="Side" /> <description> - Returns the size of this [StyleBox] without the margins. + Returns the default margin of the specified [enum Side]. </description> </method> <method name="get_current_item_drawn" qualifiers="const"> @@ -62,13 +58,6 @@ Returns the [CanvasItem] that handles its [constant CanvasItem.NOTIFICATION_DRAW] or [method CanvasItem._draw] callback at this moment. </description> </method> - <method name="get_default_margin" qualifiers="const"> - <return type="float" /> - <param index="0" name="margin" type="int" enum="Side" /> - <description> - Returns the default margin of the specified [enum Side]. - </description> - </method> <method name="get_margin" qualifiers="const"> <return type="float" /> <param index="0" name="margin" type="int" enum="Side" /> @@ -89,7 +78,7 @@ Returns the "offset" of a stylebox. This helper function returns a value equivalent to [code]Vector2(style.get_margin(MARGIN_LEFT), style.get_margin(MARGIN_TOP))[/code]. </description> </method> - <method name="set_default_margin"> + <method name="set_content_margin"> <return type="void" /> <param index="0" name="margin" type="int" enum="Side" /> <param index="1" name="offset" type="float" /> @@ -97,7 +86,7 @@ Sets the default value of the specified [enum Side] to [param offset] pixels. </description> </method> - <method name="set_default_margin_all"> + <method name="set_content_margin_all"> <return type="void" /> <param index="0" name="offset" type="float" /> <description> @@ -114,21 +103,21 @@ </method> </methods> <members> - <member name="content_margin_bottom" type="float" setter="set_default_margin" getter="get_default_margin" default="-1.0"> + <member name="content_margin_bottom" type="float" setter="set_content_margin" getter="get_content_margin" default="-1.0"> The bottom margin for the contents of this style box. Increasing this value reduces the space available to the contents from the bottom. If this value is negative, it is ignored and a child-specific margin is used instead. For example for [StyleBoxFlat] the border thickness (if any) is used instead. It is up to the code using this style box to decide what these contents are: for example, a [Button] respects this content margin for the textual contents of the button. [method get_margin] should be used to fetch this value as consumer instead of reading these properties directly. This is because it correctly respects negative values and the fallback mentioned above. </member> - <member name="content_margin_left" type="float" setter="set_default_margin" getter="get_default_margin" default="-1.0"> + <member name="content_margin_left" type="float" setter="set_content_margin" getter="get_content_margin" default="-1.0"> The left margin for the contents of this style box. Increasing this value reduces the space available to the contents from the left. Refer to [member content_margin_bottom] for extra considerations. </member> - <member name="content_margin_right" type="float" setter="set_default_margin" getter="get_default_margin" default="-1.0"> + <member name="content_margin_right" type="float" setter="set_content_margin" getter="get_content_margin" default="-1.0"> The right margin for the contents of this style box. Increasing this value reduces the space available to the contents from the right. Refer to [member content_margin_bottom] for extra considerations. </member> - <member name="content_margin_top" type="float" setter="set_default_margin" getter="get_default_margin" default="-1.0"> + <member name="content_margin_top" type="float" setter="set_content_margin" getter="get_content_margin" default="-1.0"> The top margin for the contents of this style box. Increasing this value reduces the space available to the contents from the top. Refer to [member content_margin_bottom] for extra considerations. </member> diff --git a/doc/classes/StyleBoxTexture.xml b/doc/classes/StyleBoxTexture.xml index aeba777b43..745187ed63 100644 --- a/doc/classes/StyleBoxTexture.xml +++ b/doc/classes/StyleBoxTexture.xml @@ -9,36 +9,36 @@ <tutorials> </tutorials> <methods> - <method name="get_expand_margin_size" qualifiers="const"> + <method name="get_expand_margin" qualifiers="const"> <return type="float" /> <param index="0" name="margin" type="int" enum="Side" /> <description> Returns the expand margin size of the specified [enum Side]. </description> </method> - <method name="get_margin_size" qualifiers="const"> + <method name="get_texture_margin" qualifiers="const"> <return type="float" /> <param index="0" name="margin" type="int" enum="Side" /> <description> Returns the margin size of the specified [enum Side]. </description> </method> - <method name="set_expand_margin_all"> + <method name="set_expand_margin"> <return type="void" /> - <param index="0" name="size" type="float" /> + <param index="0" name="margin" type="int" enum="Side" /> + <param index="1" name="size" type="float" /> <description> - Sets the expand margin to [param size] pixels for all margins. + Sets the expand margin to [param size] pixels for the specified [enum Side]. </description> </method> - <method name="set_expand_margin_size"> + <method name="set_expand_margin_all"> <return type="void" /> - <param index="0" name="margin" type="int" enum="Side" /> - <param index="1" name="size" type="float" /> + <param index="0" name="size" type="float" /> <description> - Sets the expand margin to [param size] pixels for the specified [enum Side]. + Sets the expand margin to [param size] pixels for all margins. </description> </method> - <method name="set_margin_size"> + <method name="set_texture_margin"> <return type="void" /> <param index="0" name="margin" type="int" enum="Side" /> <param index="1" name="size" type="float" /> @@ -46,7 +46,7 @@ Sets the margin to [param size] pixels for the specified [enum Side]. </description> </method> - <method name="set_margin_size_all"> + <method name="set_texture_margin_all"> <return type="void" /> <param index="0" name="size" type="float" /> <description> @@ -64,48 +64,48 @@ <member name="draw_center" type="bool" setter="set_draw_center" getter="is_draw_center_enabled" default="true"> If [code]true[/code], the nine-patch texture's center tile will be drawn. </member> - <member name="expand_margin_bottom" type="float" setter="set_expand_margin_size" getter="get_expand_margin_size" default="0.0"> + <member name="expand_margin_bottom" type="float" setter="set_expand_margin" getter="get_expand_margin" default="0.0"> Expands the bottom margin of this style box when drawing, causing it to be drawn larger than requested. </member> - <member name="expand_margin_left" type="float" setter="set_expand_margin_size" getter="get_expand_margin_size" default="0.0"> + <member name="expand_margin_left" type="float" setter="set_expand_margin" getter="get_expand_margin" default="0.0"> Expands the left margin of this style box when drawing, causing it to be drawn larger than requested. </member> - <member name="expand_margin_right" type="float" setter="set_expand_margin_size" getter="get_expand_margin_size" default="0.0"> + <member name="expand_margin_right" type="float" setter="set_expand_margin" getter="get_expand_margin" default="0.0"> Expands the right margin of this style box when drawing, causing it to be drawn larger than requested. </member> - <member name="expand_margin_top" type="float" setter="set_expand_margin_size" getter="get_expand_margin_size" default="0.0"> + <member name="expand_margin_top" type="float" setter="set_expand_margin" getter="get_expand_margin" default="0.0"> Expands the top margin of this style box when drawing, causing it to be drawn larger than requested. </member> - <member name="margin_bottom" type="float" setter="set_margin_size" getter="get_margin_size" default="0.0"> + <member name="modulate_color" type="Color" setter="set_modulate" getter="get_modulate" default="Color(1, 1, 1, 1)"> + Modulates the color of the texture when this style box is drawn. + </member> + <member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2(0, 0, 0, 0)"> + Species a sub-region of the texture to use. + This is equivalent to first wrapping the texture in an [AtlasTexture] with the same region. + </member> + <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture"> + The texture to use when drawing this style box. + </member> + <member name="texture_margin_bottom" type="float" setter="set_texture_margin" getter="get_texture_margin" default="0.0"> Increases the bottom margin of the 3×3 texture box. A higher value means more of the source texture is considered to be part of the bottom border of the 3×3 box. This is also the value used as fallback for [member StyleBox.content_margin_bottom] if it is negative. </member> - <member name="margin_left" type="float" setter="set_margin_size" getter="get_margin_size" default="0.0"> + <member name="texture_margin_left" type="float" setter="set_texture_margin" getter="get_texture_margin" default="0.0"> Increases the left margin of the 3×3 texture box. A higher value means more of the source texture is considered to be part of the left border of the 3×3 box. This is also the value used as fallback for [member StyleBox.content_margin_left] if it is negative. </member> - <member name="margin_right" type="float" setter="set_margin_size" getter="get_margin_size" default="0.0"> + <member name="texture_margin_right" type="float" setter="set_texture_margin" getter="get_texture_margin" default="0.0"> Increases the right margin of the 3×3 texture box. A higher value means more of the source texture is considered to be part of the right border of the 3×3 box. This is also the value used as fallback for [member StyleBox.content_margin_right] if it is negative. </member> - <member name="margin_top" type="float" setter="set_margin_size" getter="get_margin_size" default="0.0"> + <member name="texture_margin_top" type="float" setter="set_texture_margin" getter="get_texture_margin" default="0.0"> Increases the top margin of the 3×3 texture box. A higher value means more of the source texture is considered to be part of the top border of the 3×3 box. This is also the value used as fallback for [member StyleBox.content_margin_top] if it is negative. </member> - <member name="modulate_color" type="Color" setter="set_modulate" getter="get_modulate" default="Color(1, 1, 1, 1)"> - Modulates the color of the texture when this style box is drawn. - </member> - <member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2(0, 0, 0, 0)"> - Species a sub-region of the texture to use. - This is equivalent to first wrapping the texture in an [AtlasTexture] with the same region. - </member> - <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture"> - The texture to use when drawing this style box. - </member> </members> <constants> <constant name="AXIS_STRETCH_MODE_STRETCH" value="0" enum="AxisStretchMode"> diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 6f4736dca7..9ff480f130 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -285,7 +285,7 @@ void ConnectDialog::_notification(int p_what) { Ref<StyleBox> style = get_theme_stylebox("normal", "LineEdit")->duplicate(); if (style.is_valid()) { - style->set_default_margin(SIDE_TOP, style->get_default_margin(SIDE_TOP) + 1.0); + style->set_content_margin(SIDE_TOP, style->get_content_margin(SIDE_TOP) + 1.0); from_signal->add_theme_style_override("normal", style); } } break; diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index a83a53ad15..33a1fe4b45 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -980,7 +980,7 @@ EditorFeatureProfileManager::EditorFeatureProfileManager() { no_profile_selected_help = memnew(Label(TTR("Create or import a profile to edit available classes and properties."))); // Add some spacing above the help label. Ref<StyleBoxEmpty> sb = memnew(StyleBoxEmpty); - sb->set_default_margin(SIDE_TOP, 20 * EDSCALE); + sb->set_content_margin(SIDE_TOP, 20 * EDSCALE); no_profile_selected_help->add_theme_style_override("normal", sb); no_profile_selected_help->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); no_profile_selected_help->set_v_size_flags(Control::SIZE_EXPAND_FILL); diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 16ecac4dac..ef33b82390 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1552,6 +1552,11 @@ void EditorFileSystem::_update_script_classes() { int index = -1; EditorFileSystemDirectory *efd = find_file(path, &index); + if (!efd || index < 0) { + // The file was removed + continue; + } + for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptLanguage *lang = ScriptServer::get_language(i); if (lang->supports_documentation() && efd->files[index]->type == lang->get_type()) { diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 9b1a5e028b..4cf947b006 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -195,8 +195,8 @@ void EditorHelp::_class_desc_resized(bool p_force_update_theme) { display_margin = new_display_margin; Ref<StyleBox> class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_theme_stylebox(SNAME("background"), SNAME("EditorHelp"))->duplicate(); - class_desc_stylebox->set_default_margin(SIDE_LEFT, display_margin); - class_desc_stylebox->set_default_margin(SIDE_RIGHT, display_margin); + class_desc_stylebox->set_content_margin(SIDE_LEFT, display_margin); + class_desc_stylebox->set_content_margin(SIDE_RIGHT, display_margin); class_desc->add_theme_style_override("normal", class_desc_stylebox); class_desc->add_theme_style_override("focused", class_desc_stylebox); } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index d68720e573..19d991b112 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3653,12 +3653,12 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { if (get_edited_scene()) { if (current_tab < 2) { - // Use heuristic instead. - int n2d = 0, n3d = 0; - _find_node_types(get_edited_scene(), n2d, n3d); - if (n2d > n3d) { + Node *editor_node = SceneTreeDock::get_singleton()->get_tree_editor()->get_selected(); + editor_node = editor_node == nullptr ? get_edited_scene() : editor_node; + + if (Object::cast_to<Node2D>(editor_node) || Object::cast_to<Control>(editor_node)) { editor_select(EDITOR_2D); - } else if (n3d > n2d) { + } else if (Object::cast_to<Node3D>(editor_node)) { editor_select(EDITOR_3D); } } @@ -6944,7 +6944,7 @@ EditorNode::EditorNode() { _reset_play_buttons(); - ED_SHORTCUT_AND_COMMAND("editor/run_specific_scene", TTR("Run Specific Scene"), KeyModifierMask::META | KeyModifierMask::SHIFT | Key::F5); + ED_SHORTCUT_AND_COMMAND("editor/run_specific_scene", TTR("Run Specific Scene"), KeyModifierMask::CTRL | KeyModifierMask::SHIFT | Key::F5); ED_SHORTCUT_OVERRIDE("editor/run_specific_scene", "macos", KeyModifierMask::META | KeyModifierMask::SHIFT | Key::R); play_custom_scene_button->set_shortcut(ED_GET_SHORTCUT("editor/run_specific_scene")); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 7f02148dfc..14cdbc364e 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -662,7 +662,7 @@ void EditorPlugin::make_visible(bool p_visible) { } void EditorPlugin::edit(Object *p_object) { - if (p_object->is_class("Resource")) { + if (Object::cast_to<Resource>(p_object)) { GDVIRTUAL_CALL(_edit, Ref<Resource>(Object::cast_to<Resource>(p_object))); } else { GDVIRTUAL_CALL(_edit, p_object); diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index cb71a2457b..86ffbccefd 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -97,7 +97,7 @@ void EditorResourcePicker::_update_resource_preview(const String &p_path, const } if (p_preview.is_valid()) { - preview_rect->set_offset(SIDE_LEFT, assign_button->get_icon()->get_width() + assign_button->get_theme_stylebox(SNAME("normal"))->get_default_margin(SIDE_LEFT) + get_theme_constant(SNAME("h_separation"), SNAME("Button"))); + preview_rect->set_offset(SIDE_LEFT, assign_button->get_icon()->get_width() + assign_button->get_theme_stylebox(SNAME("normal"))->get_content_margin(SIDE_LEFT) + get_theme_constant(SNAME("h_separation"), SNAME("Button"))); // Resource-specific stretching. if (Ref<GradientTexture1D>(edited_resource).is_valid() || Ref<Gradient>(edited_resource).is_valid()) { diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 177266e366..54e14074d9 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -278,11 +278,11 @@ void EditorSpinSlider::_update_value_input_stylebox() { // higher margin to match the location where the text begins. // The margin values below were determined by empirical testing. if (is_layout_rtl()) { - stylebox->set_default_margin(SIDE_LEFT, 0); - stylebox->set_default_margin(SIDE_RIGHT, (!get_label().is_empty() ? 23 : 16) * EDSCALE); + stylebox->set_content_margin(SIDE_LEFT, 0); + stylebox->set_content_margin(SIDE_RIGHT, (!get_label().is_empty() ? 23 : 16) * EDSCALE); } else { - stylebox->set_default_margin(SIDE_LEFT, (!get_label().is_empty() ? 23 : 16) * EDSCALE); - stylebox->set_default_margin(SIDE_RIGHT, 0); + stylebox->set_content_margin(SIDE_LEFT, (!get_label().is_empty() ? 23 : 16) * EDSCALE); + stylebox->set_content_margin(SIDE_RIGHT, 0); } value_input->add_theme_style_override("normal", stylebox); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 7a880d2ab3..745acca04b 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -197,15 +197,15 @@ void EditorColorMap::create() { static Ref<StyleBoxTexture> make_stylebox(Ref<Texture2D> p_texture, float p_left, float p_top, float p_right, float p_bottom, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, bool p_draw_center = true) { Ref<StyleBoxTexture> style(memnew(StyleBoxTexture)); style->set_texture(p_texture); - style->set_margin_size_individual(p_left * EDSCALE, p_top * EDSCALE, p_right * EDSCALE, p_bottom * EDSCALE); - style->set_default_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); + style->set_texture_margin_individual(p_left * EDSCALE, p_top * EDSCALE, p_right * EDSCALE, p_bottom * EDSCALE); + style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); style->set_draw_center(p_draw_center); return style; } static Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) { Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty)); - style->set_default_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); + style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); return style; } @@ -215,7 +215,7 @@ static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = // Adjust level of detail based on the corners' effective sizes. style->set_corner_detail(Math::ceil(0.8 * p_corner_width * EDSCALE)); style->set_corner_radius_all(p_corner_width * EDSCALE); - style->set_default_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); + style->set_content_margin_individual(p_margin_left * EDSCALE, p_margin_top * EDSCALE, p_margin_right * EDSCALE, p_margin_bottom * EDSCALE); // Work around issue about antialiased edges being blurrier (GH-35279). style->set_anti_aliased(false); return style; @@ -648,7 +648,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { const Vector2 widget_default_margin = Vector2(extra_spacing + 6, extra_spacing + default_margin_size + 1) * EDSCALE; Ref<StyleBoxFlat> style_widget = style_default->duplicate(); - style_widget->set_default_margin_individual(widget_default_margin.x, widget_default_margin.y, widget_default_margin.x, widget_default_margin.y); + style_widget->set_content_margin_individual(widget_default_margin.x, widget_default_margin.y, widget_default_margin.x, widget_default_margin.y); style_widget->set_bg_color(dark_color_1); if (draw_extra_borders) { style_widget->set_border_width_all(Math::round(EDSCALE)); @@ -684,7 +684,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // Style for windows, popups, etc.. Ref<StyleBoxFlat> style_popup = style_default->duplicate(); const int popup_margin_size = default_margin_size * EDSCALE * 3; - style_popup->set_default_margin_all(popup_margin_size); + style_popup->set_content_margin_all(popup_margin_size); style_popup->set_border_color(contrast_color_1); const Color shadow_color = Color(0, 0, 0, dark_theme ? 0.3 : 0.1); style_popup->set_shadow_color(shadow_color); @@ -722,12 +722,12 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { style_tab_base->set_corner_radius(CORNER_BOTTOM_RIGHT, 0); // When using a border width greater than 0, visually line up the left of the selected tab with the underlying panel. - style_tab_base->set_expand_margin_size(SIDE_LEFT, -border_width); + style_tab_base->set_expand_margin(SIDE_LEFT, -border_width); - style_tab_base->set_default_margin(SIDE_LEFT, widget_default_margin.x + 5 * EDSCALE); - style_tab_base->set_default_margin(SIDE_RIGHT, widget_default_margin.x + 5 * EDSCALE); - style_tab_base->set_default_margin(SIDE_BOTTOM, widget_default_margin.y); - style_tab_base->set_default_margin(SIDE_TOP, widget_default_margin.y); + style_tab_base->set_content_margin(SIDE_LEFT, widget_default_margin.x + 5 * EDSCALE); + style_tab_base->set_content_margin(SIDE_RIGHT, widget_default_margin.x + 5 * EDSCALE); + style_tab_base->set_content_margin(SIDE_BOTTOM, widget_default_margin.y); + style_tab_base->set_content_margin(SIDE_TOP, widget_default_margin.y); Ref<StyleBoxFlat> style_tab_selected = style_tab_base->duplicate(); @@ -740,13 +740,13 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { style_tab_selected->set_corner_radius_all(0); Ref<StyleBoxFlat> style_tab_unselected = style_tab_base->duplicate(); - style_tab_unselected->set_expand_margin_size(SIDE_BOTTOM, 0); + style_tab_unselected->set_expand_margin(SIDE_BOTTOM, 0); style_tab_unselected->set_bg_color(dark_color_1); // Add some spacing between unselected tabs to make them easier to distinguish from each other style_tab_unselected->set_border_color(Color(0, 0, 0, 0)); Ref<StyleBoxFlat> style_tab_disabled = style_tab_base->duplicate(); - style_tab_disabled->set_expand_margin_size(SIDE_BOTTOM, 0); + style_tab_disabled->set_expand_margin(SIDE_BOTTOM, 0); style_tab_disabled->set_bg_color(disabled_bg_color); style_tab_disabled->set_border_color(disabled_bg_color); @@ -772,7 +772,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // CanvasItem Editor Ref<StyleBoxFlat> style_canvas_editor_info = make_flat_stylebox(Color(0.0, 0.0, 0.0, 0.2)); - style_canvas_editor_info->set_expand_margin_size_all(4 * EDSCALE); + style_canvas_editor_info->set_expand_margin_all(4 * EDSCALE); theme->set_stylebox("CanvasItemInfoOverlay", "EditorStyles", style_canvas_editor_info); // 2D and 3D contextual toolbar. @@ -787,7 +787,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // Add an underline to the StyleBox, but prevent its minimum vertical size from changing. toolbar_stylebox->set_border_color(accent_color); toolbar_stylebox->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE)); - toolbar_stylebox->set_default_margin(SIDE_BOTTOM, 0); + toolbar_stylebox->set_content_margin(SIDE_BOTTOM, 0); theme->set_stylebox("ContextualToolbar", "EditorStyles", toolbar_stylebox); // Script Editor @@ -808,11 +808,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { Ref<StyleBoxFlat> style_write_movie_button = style_widget_pressed->duplicate(); style_write_movie_button->set_bg_color(accent_color); style_write_movie_button->set_corner_radius_all(corner_radius * EDSCALE); - style_write_movie_button->set_default_margin(SIDE_TOP, 0); - style_write_movie_button->set_default_margin(SIDE_BOTTOM, 0); - style_write_movie_button->set_default_margin(SIDE_LEFT, 0); - style_write_movie_button->set_default_margin(SIDE_RIGHT, 0); - style_write_movie_button->set_expand_margin_size(SIDE_RIGHT, 2 * EDSCALE); + style_write_movie_button->set_content_margin(SIDE_TOP, 0); + style_write_movie_button->set_content_margin(SIDE_BOTTOM, 0); + style_write_movie_button->set_content_margin(SIDE_LEFT, 0); + style_write_movie_button->set_content_margin(SIDE_RIGHT, 0); + style_write_movie_button->set_expand_margin(SIDE_RIGHT, 2 * EDSCALE); theme->set_stylebox("MovieWriterButtonPressed", "EditorStyles", style_write_movie_button); theme->set_stylebox("normal", "MenuButton", style_menu); @@ -855,16 +855,16 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { color_inspector_action.a = 0.5; Ref<StyleBoxFlat> style_inspector_action = style_widget->duplicate(); style_inspector_action->set_bg_color(color_inspector_action); - style_inspector_action->set_default_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); + style_inspector_action->set_content_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); theme->set_stylebox("normal", "InspectorActionButton", style_inspector_action); style_inspector_action = style_widget_hover->duplicate(); - style_inspector_action->set_default_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); + style_inspector_action->set_content_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); theme->set_stylebox("hover", "InspectorActionButton", style_inspector_action); style_inspector_action = style_widget_pressed->duplicate(); - style_inspector_action->set_default_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); + style_inspector_action->set_content_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); theme->set_stylebox("pressed", "InspectorActionButton", style_inspector_action); style_inspector_action = style_widget_disabled->duplicate(); - style_inspector_action->set_default_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); + style_inspector_action->set_content_margin(SIDE_RIGHT, ACTION_BUTTON_EXTRA_MARGIN); theme->set_stylebox("disabled", "InspectorActionButton", style_inspector_action); theme->set_constant("h_separation", "InspectorActionButton", ACTION_BUTTON_EXTRA_MARGIN); @@ -908,11 +908,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { Ref<StyleBoxFlat> style_option_button_pressed = style_widget_pressed->duplicate(); Ref<StyleBoxFlat> style_option_button_disabled = style_widget_disabled->duplicate(); - style_option_button_focus->set_default_margin(SIDE_RIGHT, 4 * EDSCALE); - style_option_button_normal->set_default_margin(SIDE_RIGHT, 4 * EDSCALE); - style_option_button_hover->set_default_margin(SIDE_RIGHT, 4 * EDSCALE); - style_option_button_pressed->set_default_margin(SIDE_RIGHT, 4 * EDSCALE); - style_option_button_disabled->set_default_margin(SIDE_RIGHT, 4 * EDSCALE); + style_option_button_focus->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + style_option_button_normal->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + style_option_button_hover->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + style_option_button_pressed->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); + style_option_button_disabled->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); theme->set_stylebox("focus", "OptionButton", style_option_button_focus); theme->set_stylebox("normal", "OptionButton", style_widget); @@ -978,7 +978,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // Checkbox Ref<StyleBoxFlat> sb_checkbox = style_menu->duplicate(); - sb_checkbox->set_default_margin_all(default_margin_size * EDSCALE); + sb_checkbox->set_content_margin_all(default_margin_size * EDSCALE); theme->set_stylebox("normal", "CheckBox", sb_checkbox); theme->set_stylebox("pressed", "CheckBox", sb_checkbox); @@ -1018,7 +1018,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // Use 1 pixel for the sides, since if 0 is used, the highlight of hovered items is drawn // on top of the popup border. This causes a 'gap' in the panel border when an item is highlighted, // and it looks weird. 1px solves this. - style_popup_menu->set_default_margin_individual(EDSCALE, 2 * EDSCALE, EDSCALE, 2 * EDSCALE); + style_popup_menu->set_content_margin_individual(EDSCALE, 2 * EDSCALE, EDSCALE, 2 * EDSCALE); // Always display a border for PopupMenus so they can be distinguished from their background. style_popup_menu->set_border_width_all(EDSCALE); if (draw_extra_borders) { @@ -1078,7 +1078,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { sub_inspector_bg->set_bg_color(dark_color_1.lerp(si_base_color, 0.08)); sub_inspector_bg->set_border_width_all(2 * EDSCALE); sub_inspector_bg->set_border_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8)); - sub_inspector_bg->set_default_margin_all(4 * EDSCALE); + sub_inspector_bg->set_content_margin_all(4 * EDSCALE); sub_inspector_bg->set_corner_radius(CORNER_TOP_LEFT, 0); sub_inspector_bg->set_corner_radius(CORNER_TOP_RIGHT, 0); @@ -1318,7 +1318,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { style_content_panel->set_corner_radius(CORNER_TOP_LEFT, 0); style_content_panel->set_corner_radius(CORNER_TOP_RIGHT, 0); // Compensate for the border. - style_content_panel->set_default_margin_individual(margin_size_extra * EDSCALE, (2 + margin_size_extra) * EDSCALE, margin_size_extra * EDSCALE, margin_size_extra * EDSCALE); + style_content_panel->set_content_margin_individual(margin_size_extra * EDSCALE, (2 + margin_size_extra) * EDSCALE, margin_size_extra * EDSCALE, margin_size_extra * EDSCALE); theme->set_stylebox("panel", "TabContainer", style_content_panel); // Bottom panel. @@ -1339,15 +1339,15 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // This stylebox is used in 3d and 2d viewports (no borders). Ref<StyleBoxFlat> style_content_panel_vp = style_content_panel->duplicate(); - style_content_panel_vp->set_default_margin_individual(border_width * 2, default_margin_size * EDSCALE, border_width * 2, border_width * 2); + style_content_panel_vp->set_content_margin_individual(border_width * 2, default_margin_size * EDSCALE, border_width * 2, border_width * 2); theme->set_stylebox("Content", "EditorStyles", style_content_panel_vp); // This stylebox is used by preview tabs in the Theme Editor. Ref<StyleBoxFlat> style_theme_preview_tab = style_tab_selected_odd->duplicate(); - style_theme_preview_tab->set_expand_margin_size(SIDE_BOTTOM, 5 * EDSCALE); + style_theme_preview_tab->set_expand_margin(SIDE_BOTTOM, 5 * EDSCALE); theme->set_stylebox("ThemeEditorPreviewFG", "EditorStyles", style_theme_preview_tab); Ref<StyleBoxFlat> style_theme_preview_bg_tab = style_tab_unselected->duplicate(); - style_theme_preview_bg_tab->set_expand_margin_size(SIDE_BOTTOM, 2 * EDSCALE); + style_theme_preview_bg_tab->set_expand_margin(SIDE_BOTTOM, 2 * EDSCALE); theme->set_stylebox("ThemeEditorPreviewBG", "EditorStyles", style_theme_preview_bg_tab); // Separators @@ -1361,9 +1361,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_stylebox("DebuggerPanel", "EditorStyles", style_panel_debugger); Ref<StyleBoxFlat> style_panel_invisible_top = style_content_panel->duplicate(); - int stylebox_offset = theme->get_font(SNAME("tab_selected"), SNAME("TabContainer"))->get_height(theme->get_font_size(SNAME("tab_selected"), SNAME("TabContainer"))) + theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainer"))->get_minimum_size().height + theme->get_stylebox(SNAME("panel"), SNAME("TabContainer"))->get_default_margin(SIDE_TOP); - style_panel_invisible_top->set_expand_margin_size(SIDE_TOP, -stylebox_offset); - style_panel_invisible_top->set_default_margin(SIDE_TOP, 0); + int stylebox_offset = theme->get_font(SNAME("tab_selected"), SNAME("TabContainer"))->get_height(theme->get_font_size(SNAME("tab_selected"), SNAME("TabContainer"))) + theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainer"))->get_minimum_size().height + theme->get_stylebox(SNAME("panel"), SNAME("TabContainer"))->get_content_margin(SIDE_TOP); + style_panel_invisible_top->set_expand_margin(SIDE_TOP, -stylebox_offset); + style_panel_invisible_top->set_content_margin(SIDE_TOP, 0); theme->set_stylebox("BottomPanelDebuggerOverride", "EditorStyles", style_panel_invisible_top); // LineEdit @@ -1371,7 +1371,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { Ref<StyleBoxFlat> style_line_edit = style_widget->duplicate(); // The original style_widget style has an extra 1 pixel offset that makes LineEdits not align with Buttons, // so this compensates for that. - style_line_edit->set_default_margin(SIDE_TOP, style_line_edit->get_default_margin(SIDE_TOP) - 1 * EDSCALE); + style_line_edit->set_content_margin(SIDE_TOP, style_line_edit->get_content_margin(SIDE_TOP) - 1 * EDSCALE); // Don't round the bottom corner to make the line look sharper. style_tab_selected->set_corner_radius(CORNER_BOTTOM_LEFT, 0); @@ -1459,12 +1459,12 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { style_window_title->set_corner_radius(CORNER_TOP_LEFT, 0); style_window_title->set_corner_radius(CORNER_TOP_RIGHT, 0); // Prevent visible line between window title and body. - style_window_title->set_expand_margin_size(SIDE_BOTTOM, 2 * EDSCALE); + style_window_title->set_expand_margin(SIDE_BOTTOM, 2 * EDSCALE); Ref<StyleBoxFlat> style_window = style_popup->duplicate(); style_window->set_border_color(base_color); style_window->set_border_width(SIDE_TOP, 24 * EDSCALE); - style_window->set_expand_margin_size(SIDE_TOP, 24 * EDSCALE); + style_window->set_expand_margin(SIDE_TOP, 24 * EDSCALE); theme->set_stylebox("embedded_border", "Window", style_window); theme->set_color("title_color", "Window", font_color); @@ -1598,7 +1598,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // is only relevant for default tooltips. Ref<StyleBoxFlat> style_tooltip = style_popup->duplicate(); style_tooltip->set_shadow_size(0); - style_tooltip->set_default_margin_all(default_margin_size * EDSCALE * 0.5); + style_tooltip->set_content_margin_all(default_margin_size * EDSCALE * 0.5); style_tooltip->set_bg_color(dark_color_3 * Color(0.8, 0.8, 0.8, 0.9)); style_tooltip->set_border_width_all(0); theme->set_color("font_color", "TooltipLabel", font_hover_color); @@ -1610,10 +1610,10 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { Ref<StyleBoxFlat> control_editor_popup_style = style_popup->duplicate(); control_editor_popup_style->set_shadow_size(0); - control_editor_popup_style->set_default_margin(SIDE_LEFT, default_margin_size * EDSCALE); - control_editor_popup_style->set_default_margin(SIDE_TOP, default_margin_size * EDSCALE); - control_editor_popup_style->set_default_margin(SIDE_RIGHT, default_margin_size * EDSCALE); - control_editor_popup_style->set_default_margin(SIDE_BOTTOM, default_margin_size * EDSCALE); + control_editor_popup_style->set_content_margin(SIDE_LEFT, default_margin_size * EDSCALE); + control_editor_popup_style->set_content_margin(SIDE_TOP, default_margin_size * EDSCALE); + control_editor_popup_style->set_content_margin(SIDE_RIGHT, default_margin_size * EDSCALE); + control_editor_popup_style->set_content_margin(SIDE_BOTTOM, default_margin_size * EDSCALE); control_editor_popup_style->set_border_width_all(0); theme->set_stylebox("panel", "ControlEditorPopupPanel", control_editor_popup_style); @@ -1826,8 +1826,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // Dictionary editor add item. // Expand to the left and right by 4px to compensate for the dictionary editor margins. Ref<StyleBoxFlat> style_dictionary_add_item = make_flat_stylebox(prop_subsection_color, 0, 4, 0, 4, corner_radius); - style_dictionary_add_item->set_expand_margin_size(SIDE_LEFT, 4 * EDSCALE); - style_dictionary_add_item->set_expand_margin_size(SIDE_RIGHT, 4 * EDSCALE); + style_dictionary_add_item->set_expand_margin(SIDE_LEFT, 4 * EDSCALE); + style_dictionary_add_item->set_expand_margin(SIDE_RIGHT, 4 * EDSCALE); theme->set_stylebox("DictionaryAddItem", "EditorStyles", style_dictionary_add_item); Ref<StyleBoxEmpty> vshader_label_style = make_empty_stylebox(2, 1, 2, 1); diff --git a/editor/editor_toaster.cpp b/editor/editor_toaster.cpp index 43f2c4e74e..73b645f351 100644 --- a/editor/editor_toaster.cpp +++ b/editor/editor_toaster.cpp @@ -525,7 +525,7 @@ EditorToaster::EditorToaster() { Ref<StyleBoxFlat> boxes[] = { info_panel_style_background, warning_panel_style_background, error_panel_style_background }; for (int i = 0; i < 3; i++) { - boxes[i]->set_default_margin_individual(int(stylebox_radius * 2.5), 3, int(stylebox_radius * 2.5), 3); + boxes[i]->set_content_margin_individual(int(stylebox_radius * 2.5), 3, int(stylebox_radius * 2.5), 3); } // Theming (progress). diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index f41792af7f..54d5ddacab 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2648,7 +2648,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str p_popup->add_icon_shortcut(get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER); p_popup->set_item_text(p_popup->get_item_index(FILE_SHOW_IN_EXPLORER), item_text); if (!is_directory) { - p_popup->add_icon_item(get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), TTR("Open in External Program"), FILE_OPEN_EXTERNAL); + p_popup->add_icon_shortcut(get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/open_in_external_program"), FILE_OPEN_EXTERNAL); } path = fpath; } @@ -2869,6 +2869,8 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) { _tree_rmb_option(FILE_RENAME); } else if (ED_IS_SHORTCUT("filesystem_dock/show_in_explorer", p_event)) { _tree_rmb_option(FILE_SHOW_IN_EXPLORER); + } else if (ED_IS_SHORTCUT("filesystem_dock/open_in_external_program", p_event)) { + _tree_rmb_option(FILE_OPEN_EXTERNAL); } else if (ED_IS_SHORTCUT("editor/open_search", p_event)) { focus_on_filter(); } else { @@ -3098,6 +3100,7 @@ FileSystemDock::FileSystemDock() { ED_SHORTCUT("filesystem_dock/rename", TTR("Rename..."), Key::F2); ED_SHORTCUT_OVERRIDE("filesystem_dock/rename", "macos", Key::ENTER); ED_SHORTCUT("filesystem_dock/show_in_explorer", TTR("Open in File Manager")); + ED_SHORTCUT("filesystem_dock/open_in_external_program", TTR("Open in External Program")); VBoxContainer *top_vbc = memnew(VBoxContainer); add_child(top_vbc); diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index eab5eb0404..2639765283 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -107,7 +107,7 @@ void EditorAssetLibraryItem::_bind_methods() { EditorAssetLibraryItem::EditorAssetLibraryItem() { Ref<StyleBoxEmpty> border; border.instantiate(); - border->set_default_margin_all(5 * EDSCALE); + border->set_content_margin_all(5 * EDSCALE); add_theme_style_override("panel", border); HBoxContainer *hb = memnew(HBoxContainer); @@ -1549,7 +1549,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { Ref<StyleBoxEmpty> border2; border2.instantiate(); - border2->set_default_margin_individual(15 * EDSCALE, 15 * EDSCALE, 35 * EDSCALE, 15 * EDSCALE); + border2->set_content_margin_individual(15 * EDSCALE, 15 * EDSCALE, 35 * EDSCALE, 15 * EDSCALE); PanelContainer *library_vb_border = memnew(PanelContainer); library_scroll->add_child(library_vb_border); diff --git a/editor/plugins/bit_map_editor_plugin.cpp b/editor/plugins/bit_map_editor_plugin.cpp index 4f82aaf071..30fc60b0e0 100644 --- a/editor/plugins/bit_map_editor_plugin.cpp +++ b/editor/plugins/bit_map_editor_plugin.cpp @@ -53,7 +53,7 @@ BitMapEditor::BitMapEditor() { // Reduce extra padding on top and bottom of size label. Ref<StyleBoxEmpty> stylebox; stylebox.instantiate(); - stylebox->set_default_margin(SIDE_RIGHT, 4 * EDSCALE); + stylebox->set_content_margin(SIDE_RIGHT, 4 * EDSCALE); size_label->add_theme_style_override("normal", stylebox); } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 4c14755b03..e7522b000c 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3958,8 +3958,8 @@ void CanvasItemEditor::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { select_sb->set_texture(get_theme_icon(SNAME("EditorRect2D"), SNAME("EditorIcons"))); - select_sb->set_margin_size_all(4); - select_sb->set_default_margin_all(4); + select_sb->set_texture_margin_all(4); + select_sb->set_content_margin_all(4); AnimationPlayerEditor::get_singleton()->get_track_editor()->connect("visibility_changed", callable_mp(this, &CanvasItemEditor::_keying_changed)); _keying_changed(); @@ -3990,6 +3990,10 @@ void CanvasItemEditor::_selection_changed() { } void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { + if (!p_canvas_item) { + return; + } + Array selection = editor_selection->get_selected_nodes(); if (selection.size() != 1 || Object::cast_to<Node>(selection[0]) != p_canvas_item) { _reset_drag(); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 6bb725f7a0..b719a2ce30 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -2159,7 +2159,7 @@ ScriptTextEditor::ScriptTextEditor() { connection_info_dialog = memnew(ConnectionInfoDialog); - SET_DRAG_FORWARDING_GCD(code_editor, ScriptTextEditor); + SET_DRAG_FORWARDING_GCD(code_editor->get_text_editor(), ScriptTextEditor); } ScriptTextEditor::~ScriptTextEditor() { diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 9bad2f2fbf..d7559bc18e 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -256,10 +256,10 @@ void TextureRegionEditor::_region_draw() { margins[2] = node_ninepatch->get_patch_margin(SIDE_LEFT); margins[3] = node_ninepatch->get_patch_margin(SIDE_RIGHT); } else if (obj_styleBox.is_valid()) { - margins[0] = obj_styleBox->get_margin_size(SIDE_TOP); - margins[1] = obj_styleBox->get_margin_size(SIDE_BOTTOM); - margins[2] = obj_styleBox->get_margin_size(SIDE_LEFT); - margins[3] = obj_styleBox->get_margin_size(SIDE_RIGHT); + margins[0] = obj_styleBox->get_texture_margin(SIDE_TOP); + margins[1] = obj_styleBox->get_texture_margin(SIDE_BOTTOM); + margins[2] = obj_styleBox->get_texture_margin(SIDE_LEFT); + margins[3] = obj_styleBox->get_texture_margin(SIDE_RIGHT); } Vector2 pos[4] = { @@ -314,10 +314,10 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { margins[2] = node_ninepatch->get_patch_margin(SIDE_LEFT); margins[3] = node_ninepatch->get_patch_margin(SIDE_RIGHT); } else if (obj_styleBox.is_valid()) { - margins[0] = obj_styleBox->get_margin_size(SIDE_TOP); - margins[1] = obj_styleBox->get_margin_size(SIDE_BOTTOM); - margins[2] = obj_styleBox->get_margin_size(SIDE_LEFT); - margins[3] = obj_styleBox->get_margin_size(SIDE_RIGHT); + margins[0] = obj_styleBox->get_texture_margin(SIDE_TOP); + margins[1] = obj_styleBox->get_texture_margin(SIDE_BOTTOM); + margins[2] = obj_styleBox->get_texture_margin(SIDE_LEFT); + margins[3] = obj_styleBox->get_texture_margin(SIDE_RIGHT); } Vector2 pos[4] = { @@ -431,8 +431,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { undo_redo->add_do_method(node_ninepatch, "set_patch_margin", side[edited_margin], node_ninepatch->get_patch_margin(side[edited_margin])); undo_redo->add_undo_method(node_ninepatch, "set_patch_margin", side[edited_margin], prev_margin); } else if (obj_styleBox.is_valid()) { - undo_redo->add_do_method(obj_styleBox.ptr(), "set_margin_size", side[edited_margin], obj_styleBox->get_margin_size(side[edited_margin])); - undo_redo->add_undo_method(obj_styleBox.ptr(), "set_margin_size", side[edited_margin], prev_margin); + undo_redo->add_do_method(obj_styleBox.ptr(), "set_texture_margin", side[edited_margin], obj_styleBox->get_texture_margin(side[edited_margin])); + undo_redo->add_undo_method(obj_styleBox.ptr(), "set_texture_margin", side[edited_margin], prev_margin); obj_styleBox->emit_signal(CoreStringNames::get_singleton()->changed); } edited_margin = -1; @@ -474,7 +474,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { node_ninepatch->set_patch_margin(side[edited_margin], prev_margin); } if (obj_styleBox.is_valid()) { - obj_styleBox->set_margin_size(side[edited_margin], prev_margin); + obj_styleBox->set_texture_margin(side[edited_margin], prev_margin); } edited_margin = -1; } else { @@ -535,7 +535,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { node_ninepatch->set_patch_margin(side[edited_margin], new_margin); } if (obj_styleBox.is_valid()) { - obj_styleBox->set_margin_size(side[edited_margin], new_margin); + obj_styleBox->set_texture_margin(side[edited_margin], new_margin); } } else { Vector2 new_pos = mtx.affine_inverse().xform(mm->get_position()); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 40aac77a99..14ff59b442 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -3335,8 +3335,10 @@ void ThemeTypeEditor::set_edited_theme(const Ref<Theme> &p_theme) { } edited_theme = p_theme; - edited_theme->connect("changed", callable_mp(this, &ThemeTypeEditor::_update_type_list_debounced)); - _update_type_list(); + if (edited_theme.is_valid()) { + edited_theme->connect("changed", callable_mp(this, &ThemeTypeEditor::_update_type_list_debounced)); + _update_type_list(); + } add_type_dialog->set_edited_theme(edited_theme); } @@ -3496,7 +3498,9 @@ void ThemeEditor::edit(const Ref<Theme> &p_theme) { preview_tab->set_preview_theme(p_theme); } - theme_name->set_text(TTR("Theme:") + " " + theme->get_path().get_file()); + if (theme.is_valid()) { + theme_name->set_text(TTR("Theme:") + " " + theme->get_path().get_file()); + } } Ref<Theme> ThemeEditor::get_edited_theme() { diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index f5d3306376..4228046ba2 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -41,6 +41,7 @@ #include "core/os/os.h" #include "core/string/string_builder.h" #include "gdscript_warning.h" +#include "servers/text_server.h" #endif // DEBUG_ENABLED #ifdef TOOLS_ENABLED @@ -186,24 +187,6 @@ void GDScriptParser::push_error(const String &p_message, const Node *p_origin) { } #ifdef DEBUG_ENABLED -void GDScriptParser::push_warning(const Node *p_source, GDScriptWarning::Code p_code, const String &p_symbol1, const String &p_symbol2, const String &p_symbol3, const String &p_symbol4) { - ERR_FAIL_COND(p_source == nullptr); - Vector<String> symbols; - if (!p_symbol1.is_empty()) { - symbols.push_back(p_symbol1); - } - if (!p_symbol2.is_empty()) { - symbols.push_back(p_symbol2); - } - if (!p_symbol3.is_empty()) { - symbols.push_back(p_symbol3); - } - if (!p_symbol4.is_empty()) { - symbols.push_back(p_symbol4); - } - push_warning(p_source, p_code, symbols); -} - void GDScriptParser::push_warning(const Node *p_source, GDScriptWarning::Code p_code, const Vector<String> &p_symbols) { ERR_FAIL_COND(p_source == nullptr); if (is_ignoring_warnings) { @@ -2251,7 +2234,14 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_expression(bool p_can_assi } GDScriptParser::IdentifierNode *GDScriptParser::parse_identifier() { - return static_cast<IdentifierNode *>(parse_identifier(nullptr, false)); + IdentifierNode *identifier = static_cast<IdentifierNode *>(parse_identifier(nullptr, false)); +#ifdef DEBUG_ENABLED + // Check for spoofing here (if available in TextServer) since this isn't called inside expressions. This is only relevant for declarations. + if (identifier && TS->has_feature(TextServer::FEATURE_UNICODE_SECURITY) && TS->spoof_check(identifier->name.operator String())) { + push_warning(identifier, GDScriptWarning::CONFUSABLE_IDENTIFIER, identifier->name.operator String()); + } +#endif + return identifier; } GDScriptParser::ExpressionNode *GDScriptParser::parse_identifier(ExpressionNode *p_previous_operand, bool p_can_assign) { diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 0903f62061..f6d2a8feee 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -1361,8 +1361,11 @@ private: void clear(); void push_error(const String &p_message, const Node *p_origin = nullptr); #ifdef DEBUG_ENABLED - void push_warning(const Node *p_source, GDScriptWarning::Code p_code, const String &p_symbol1 = String(), const String &p_symbol2 = String(), const String &p_symbol3 = String(), const String &p_symbol4 = String()); void push_warning(const Node *p_source, GDScriptWarning::Code p_code, const Vector<String> &p_symbols); + template <typename... Symbols> + void push_warning(const Node *p_source, GDScriptWarning::Code p_code, const Symbols &...p_symbols) { + push_warning(p_source, p_code, Vector<String>{ p_symbols... }); + } #endif void make_completion_context(CompletionType p_type, Node *p_node, int p_argument = -1, bool p_force = false); diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index e17a804003..d7f1114fd3 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -31,10 +31,14 @@ #include "gdscript_tokenizer.h" #include "core/error/error_macros.h" +#include "core/string/char_utils.h" #ifdef TOOLS_ENABLED #include "editor/editor_settings.h" #endif +#ifdef DEBUG_ENABLED +#include "servers/text_server.h" +#endif static const char *token_names[] = { "Empty", // EMPTY, @@ -435,10 +439,12 @@ GDScriptTokenizer::Token GDScriptTokenizer::check_vcs_marker(char32_t p_test, To } GDScriptTokenizer::Token GDScriptTokenizer::annotation() { - if (!is_ascii_identifier_char(_peek())) { + if (is_unicode_identifier_start(_peek())) { + _advance(); // Consume start character. + } else { push_error("Expected annotation identifier after \"@\"."); } - while (is_ascii_identifier_char(_peek())) { + while (is_unicode_identifier_continue(_peek())) { // Consume all identifier characters. _advance(); } @@ -447,7 +453,6 @@ GDScriptTokenizer::Token GDScriptTokenizer::annotation() { return annotation; } -GDScriptTokenizer::Token GDScriptTokenizer::potential_identifier() { #define KEYWORDS(KEYWORD_GROUP, KEYWORD) \ KEYWORD_GROUP('a') \ KEYWORD("as", Token::AS) \ @@ -512,8 +517,21 @@ GDScriptTokenizer::Token GDScriptTokenizer::potential_identifier() { #define MIN_KEYWORD_LENGTH 2 #define MAX_KEYWORD_LENGTH 10 - // Consume all alphanumeric characters. - while (is_ascii_identifier_char(_peek())) { +#ifdef DEBUG_ENABLED +void GDScriptTokenizer::make_keyword_list() { +#define KEYWORD_LINE(keyword, token_type) keyword, +#define KEYWORD_GROUP_IGNORE(group) + keyword_list = { + KEYWORDS(KEYWORD_GROUP_IGNORE, KEYWORD_LINE) + }; +#undef KEYWORD_LINE +#undef KEYWORD_GROUP_IGNORE +} +#endif // DEBUG_ENABLED + +GDScriptTokenizer::Token GDScriptTokenizer::potential_identifier() { + // Consume all identifier characters. + while (is_unicode_identifier_continue(_peek())) { _advance(); } @@ -565,15 +583,28 @@ GDScriptTokenizer::Token GDScriptTokenizer::potential_identifier() { } // Not a keyword, so must be an identifier. - return make_identifier(name); + Token id = make_identifier(name); + +#ifdef DEBUG_ENABLED + // Additional checks for identifiers but only in debug and if it's available in TextServer. + if (TS->has_feature(TextServer::FEATURE_UNICODE_SECURITY)) { + int64_t confusable = TS->is_confusable(name, keyword_list); + if (confusable >= 0) { + push_error(vformat(R"(Identifier "%s" is visually similar to the GDScript keyword "%s" and thus not allowed.)", name, keyword_list[confusable])); + } + } +#endif // DEBUG_ENABLED + + return id; -#undef KEYWORDS -#undef MIN_KEYWORD_LENGTH -#undef MAX_KEYWORD_LENGTH #undef KEYWORD_GROUP_CASE #undef KEYWORD } +#undef MAX_KEYWORD_LENGTH +#undef MIN_KEYWORD_LENGTH +#undef KEYWORDS + void GDScriptTokenizer::newline(bool p_make_token) { // Don't overwrite previous newline, nor create if we want a line continuation. if (p_make_token && !pending_newline && !line_continuation) { @@ -720,7 +751,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() { error.rightmost_column = column + 1; push_error(error); has_error = true; - } else if (is_ascii_identifier_char(_peek())) { + } else if (is_unicode_identifier_start(_peek()) || is_unicode_identifier_continue(_peek())) { // Letter at the end of the number. push_error("Invalid numeric notation."); } @@ -1311,7 +1342,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::scan() { if (is_digit(c)) { return number(); - } else if (is_ascii_identifier_char(c)) { + } else if (is_unicode_identifier_start(c)) { return potential_identifier(); } @@ -1504,7 +1535,11 @@ GDScriptTokenizer::Token GDScriptTokenizer::scan() { } default: - return make_error(vformat(R"(Unknown character "%s".)", String(&c, 1))); + if (is_whitespace(c)) { + return make_error(vformat(R"(Invalid white space character "\\u%X".)", static_cast<int32_t>(c))); + } else { + return make_error(vformat(R"(Unknown character "%s".)", String(&c, 1))); + } } } @@ -1514,4 +1549,7 @@ GDScriptTokenizer::GDScriptTokenizer() { tab_size = EditorSettings::get_singleton()->get_setting("text_editor/behavior/indent/size"); } #endif // TOOLS_ENABLED +#ifdef DEBUG_ENABLED + make_keyword_list(); +#endif // DEBUG_ENABLED } diff --git a/modules/gdscript/gdscript_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h index 9588922122..608840d3f1 100644 --- a/modules/gdscript/gdscript_tokenizer.h +++ b/modules/gdscript/gdscript_tokenizer.h @@ -224,6 +224,9 @@ private: char32_t indent_char = '\0'; int position = 0; int length = 0; +#ifdef DEBUG_ENABLED + Vector<String> keyword_list; +#endif // DEBUG_ENABLED #ifdef TOOLS_ENABLED HashMap<int, CommentData> comments; @@ -239,6 +242,10 @@ private: void _skip_whitespace(); void check_indent(); +#ifdef DEBUG_ENABLED + void make_keyword_list(); +#endif // DEBUG_ENABLED + Token make_error(const String &p_message); void push_error(const String &p_message); void push_error(const Token &p_error); diff --git a/modules/gdscript/gdscript_warning.cpp b/modules/gdscript/gdscript_warning.cpp index 184cecb316..a6cbb7f6ae 100644 --- a/modules/gdscript/gdscript_warning.cpp +++ b/modules/gdscript/gdscript_warning.cpp @@ -155,6 +155,10 @@ String GDScriptWarning::get_message() const { CHECK_SYMBOLS(2); return vformat(R"(The function '%s()' is a static function but was called from an instance. Instead, it should be directly called from the type: '%s.%s()'.)", symbols[0], symbols[1], symbols[0]); } + case CONFUSABLE_IDENTIFIER: { + CHECK_SYMBOLS(1); + return vformat(R"(The identifier "%s" has misleading characters and might be confused with something else.)", symbols[0]); + } case WARNING_MAX: break; // Can't happen, but silences warning } @@ -219,6 +223,7 @@ String GDScriptWarning::get_name_from_code(Code p_code) { "SHADOWED_GLOBAL_IDENTIFIER", "INT_ASSIGNED_TO_ENUM", "STATIC_CALLED_ON_INSTANCE", + "CONFUSABLE_IDENTIFIER", }; static_assert((sizeof(names) / sizeof(*names)) == WARNING_MAX, "Amount of warning types don't match the amount of warning names."); diff --git a/modules/gdscript/gdscript_warning.h b/modules/gdscript/gdscript_warning.h index e3aee45f33..b485f02b9c 100644 --- a/modules/gdscript/gdscript_warning.h +++ b/modules/gdscript/gdscript_warning.h @@ -78,6 +78,7 @@ public: SHADOWED_GLOBAL_IDENTIFIER, // A global class or function has the same name as variable. INT_ASSIGNED_TO_ENUM, // An integer value was assigned to an enum-typed variable without casting. STATIC_CALLED_ON_INSTANCE, // A static method was called on an instance of a class instead of on the class itself. + CONFUSABLE_IDENTIFIER, // The identifier contains misleading characters that can be confused. E.g. "usеr" (has Cyrillic "е" instead of Latin "e"). WARNING_MAX, }; diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/lambda_unused_arg.out b/modules/gdscript/tests/scripts/analyzer/warnings/lambda_unused_arg.out index b018091c18..32e230fc80 100644 --- a/modules/gdscript/tests/scripts/analyzer/warnings/lambda_unused_arg.out +++ b/modules/gdscript/tests/scripts/analyzer/warnings/lambda_unused_arg.out @@ -2,4 +2,4 @@ GDTEST_OK >> WARNING >> Line: 2 >> UNUSED_PARAMETER ->> +>> The parameter 'unused' is never used in the function ''. If this is intended, prefix it with an underscore: '_unused' diff --git a/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.gd b/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.gd new file mode 100644 index 0000000000..4b1f284070 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.gd @@ -0,0 +1,3 @@ +func test(): + var аs # Using Cyrillic "а". + print(аs) diff --git a/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.out b/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.out new file mode 100644 index 0000000000..337dec2f4d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/identifier_similar_to_keyword.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Identifier "аs" is visually similar to the GDScript keyword "as" and thus not allowed. diff --git a/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.gd b/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.gd new file mode 100644 index 0000000000..523959a016 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.gd @@ -0,0 +1,35 @@ +const π = PI +var ㄥ = π + +func test(): + var փորձարկում = "test" + prints("փորձարկում", փորձարկում) + var امتحان = "test" + prints("امتحان", امتحان) + var পরীক্ষা = "test" + prints("পরীক্ষা", পরীক্ষা) + var тест = "test" + prints("тест", тест) + var जाँच = "test" + prints("जाँच", जाँच) + var 기준 = "test" + prints("기준", 기준) + var 测试 = "test" + prints("测试", 测试) + var テスト = "test" + prints("テスト", テスト) + var 試験 = "test" + prints("試験", 試験) + var പരീക്ഷ = "test" + prints("പരീക്ഷ", പരീക്ഷ) + var ทดสอบ = "test" + prints("ทดสอบ", ทดสอบ) + var δοκιμή = "test" + prints("δοκιμή", δοκιμή) + + const d = 1.1 + _process(d) + print(is_equal_approx(ㄥ, PI + (d * PI))) + +func _process(Δ: float) -> void: + ㄥ += Δ * π diff --git a/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.out b/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.out new file mode 100644 index 0000000000..c071380a8f --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unicode_identifiers.out @@ -0,0 +1,14 @@ +GDTEST_OK +փորձարկում test +امتحان test +পরীক্ষা test +тест test +जाँच test +기준 test +测试 test +テスト test +試験 test +പരീക്ഷ test +ทดสอบ test +δοκιμή test +true diff --git a/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.gd b/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.gd new file mode 100644 index 0000000000..e2caac8ffd --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.gd @@ -0,0 +1,5 @@ +func test(): + var port = 0 # Only latin characters. + var pοrt = 1 # The "ο" is Greek omicron. + + prints(port, pοrt) diff --git a/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.out b/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.out new file mode 100644 index 0000000000..c483396443 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/confusable_identifier.out @@ -0,0 +1,6 @@ +GDTEST_OK +>> WARNING +>> Line: 3 +>> CONFUSABLE_IDENTIFIER +>> The identifier "pοrt" has misleading characters and might be confused with something else. +0 1 diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 5634c51c61..b243ba933d 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -6072,6 +6072,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ const int track_idx = animation->get_track_count(); animation->add_track(Animation::TYPE_BLEND_SHAPE); animation->track_set_path(track_idx, blend_path); + animation->track_set_imported(track_idx, true); //helps merging later // Only LINEAR and STEP (NEAREST) can be supported out of the box by Godot's Animation, // the other modes have to be baked. diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp index 183958cf40..7ae26e6cf4 100644 --- a/platform/windows/joypad_windows.cpp +++ b/platform/windows/joypad_windows.cpp @@ -101,10 +101,12 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) { static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x28DE, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_XSWirelessGamepad = { MAKELONG(0x045E, 0x0B13), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; if (memcmp(p_guid, &IID_ValveStreamingGamepad, sizeof(*p_guid)) == 0 || memcmp(p_guid, &IID_X360WiredGamepad, sizeof(*p_guid)) == 0 || - memcmp(p_guid, &IID_X360WirelessGamepad, sizeof(*p_guid)) == 0) + memcmp(p_guid, &IID_X360WirelessGamepad, sizeof(*p_guid)) == 0 || + memcmp(p_guid, &IID_XSWirelessGamepad, sizeof(*p_guid)) == 0) return true; PRAWINPUTDEVICELIST dev_list = nullptr; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 2c5248f088..da29bc823f 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -475,7 +475,7 @@ ColorPicker::PickerShapeType ColorPicker::_get_actual_shape() const { void ColorPicker::_reset_theme() { Ref<StyleBoxFlat> style_box_flat(memnew(StyleBoxFlat)); - style_box_flat->set_default_margin(SIDE_TOP, 16 * get_theme_default_base_scale()); + style_box_flat->set_content_margin(SIDE_TOP, 16 * get_theme_default_base_scale()); style_box_flat->set_bg_color(Color(0.2, 0.23, 0.31).lerp(Color(0, 0, 0, 1), 0.3).clamp()); for (int i = 0; i < SLIDER_COUNT; i++) { sliders[i]->add_theme_icon_override("grabber", get_theme_icon(SNAME("bar_arrow"), SNAME("ColorPicker"))); @@ -894,7 +894,7 @@ void ColorPicker::set_colorize_sliders(bool p_colorize_sliders) { alpha_slider->add_theme_style_override("slider", style_box_empty); } else { Ref<StyleBoxFlat> style_box_flat(memnew(StyleBoxFlat)); - style_box_flat->set_default_margin(SIDE_TOP, 16 * get_theme_default_base_scale()); + style_box_flat->set_content_margin(SIDE_TOP, 16 * get_theme_default_base_scale()); style_box_flat->set_bg_color(Color(0.2, 0.23, 0.31).lerp(Color(0, 0, 0, 1), 0.3).clamp()); if (!slider_theme_modified) { diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp index 224e405d41..5b27983851 100644 --- a/scene/gui/menu_bar.cpp +++ b/scene/gui/menu_bar.cpp @@ -214,10 +214,10 @@ void MenuBar::_update_submenu(const String &p_menu_name, PopupMenu *p_child) { PopupMenu *pm = Object::cast_to<PopupMenu>(n); ERR_FAIL_COND_MSG(!pm, "Item subnode is not a PopupMenu: " + p_child->get_item_submenu(i) + "."); - DisplayServer::get_singleton()->global_menu_add_submenu_item(p_menu_name, p_child->get_item_text(i), p_menu_name + "/" + itos(i)); + DisplayServer::get_singleton()->global_menu_add_submenu_item(p_menu_name, atr(p_child->get_item_text(i)), p_menu_name + "/" + itos(i)); _update_submenu(p_menu_name + "/" + itos(i), pm); } else { - int index = DisplayServer::get_singleton()->global_menu_add_item(p_menu_name, p_child->get_item_text(i), callable_mp(p_child, &PopupMenu::activate_item), Callable(), i); + int index = DisplayServer::get_singleton()->global_menu_add_item(p_menu_name, atr(p_child->get_item_text(i)), callable_mp(p_child, &PopupMenu::activate_item), Callable(), i); if (p_child->is_item_checkable(i)) { DisplayServer::get_singleton()->global_menu_set_item_checkable(p_menu_name, index, true); @@ -290,7 +290,7 @@ void MenuBar::_update_menu() { if (menu_cache[i].hidden) { continue; } - String menu_name = String(popups[i]->get_meta("_menu_name", popups[i]->get_name())); + String menu_name = atr(String(popups[i]->get_meta("_menu_name", popups[i]->get_name()))); index = DisplayServer::get_singleton()->global_menu_add_submenu_item("_main", menu_name, root_name + "/" + itos(i), index); if (menu_cache[i].disabled) { @@ -525,7 +525,7 @@ void MenuBar::shape(Menu &p_menu) { } else { p_menu.text_buf->set_direction((TextServer::Direction)text_direction); } - p_menu.text_buf->add_string(p_menu.name, theme_cache.font, theme_cache.font_size, language); + p_menu.text_buf->add_string(atr(p_menu.name), theme_cache.font, theme_cache.font_size, language); } void MenuBar::_refresh_menu_names() { diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 4e8a44dd63..ddc11d97b9 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -594,17 +594,17 @@ void PopupMenu::_draw_items() { int content_left = content_center - content_size / 2; int content_right = content_center + content_size / 2; if (content_left > item_ofs.x) { - int sep_h = theme_cache.labeled_separator_left->get_center_size().height + theme_cache.labeled_separator_left->get_minimum_size().height; + int sep_h = theme_cache.labeled_separator_left->get_minimum_size().height; int sep_ofs = Math::floor((h - sep_h) / 2.0); theme_cache.labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(MAX(0, content_left - item_ofs.x), sep_h))); } if (content_right < display_width) { - int sep_h = theme_cache.labeled_separator_right->get_center_size().height + theme_cache.labeled_separator_right->get_minimum_size().height; + int sep_h = theme_cache.labeled_separator_right->get_minimum_size().height; int sep_ofs = Math::floor((h - sep_h) / 2.0); theme_cache.labeled_separator_right->draw(ci, Rect2(Point2(content_right, item_ofs.y + sep_ofs), Size2(MAX(0, display_width - content_right), sep_h))); } } else { - int sep_h = theme_cache.separator_style->get_center_size().height + theme_cache.separator_style->get_minimum_size().height; + int sep_h = theme_cache.separator_style->get_minimum_size().height; int sep_ofs = Math::floor((h - sep_h) / 2.0); theme_cache.separator_style->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(display_width, sep_h))); } diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index e617b2ca77..b8faf22a59 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -433,7 +433,7 @@ void ScrollBar::_notification(int p_what) { double ScrollBar::get_grabber_min_size() const { Ref<StyleBox> grabber = theme_cache.grabber_style; - Size2 gminsize = grabber->get_minimum_size() + grabber->get_center_size(); + Size2 gminsize = grabber->get_minimum_size(); return (orientation == VERTICAL) ? gminsize.height : gminsize.width; } @@ -500,7 +500,7 @@ Size2 ScrollBar::get_minimum_size() const { Size2 minsize; if (orientation == VERTICAL) { - minsize.width = MAX(incr->get_size().width, (bg->get_minimum_size() + bg->get_center_size()).width); + minsize.width = MAX(incr->get_size().width, bg->get_minimum_size().width); minsize.height += incr->get_size().height; minsize.height += decr->get_size().height; minsize.height += bg->get_minimum_size().height; @@ -508,7 +508,7 @@ Size2 ScrollBar::get_minimum_size() const { } if (orientation == HORIZONTAL) { - minsize.height = MAX(incr->get_size().height, (bg->get_center_size() + bg->get_minimum_size()).height); + minsize.height = MAX(incr->get_size().height, bg->get_minimum_size().height); minsize.width += incr->get_size().width; minsize.width += decr->get_size().width; minsize.width += bg->get_minimum_size().width; diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp index 45185de698..b0879c1931 100644 --- a/scene/gui/separator.cpp +++ b/scene/gui/separator.cpp @@ -51,7 +51,7 @@ void Separator::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { Size2i size = get_size(); - Size2i ssize = theme_cache.separator_style->get_minimum_size() + theme_cache.separator_style->get_center_size(); + Size2i ssize = theme_cache.separator_style->get_minimum_size(); if (orientation == VERTICAL) { theme_cache.separator_style->draw(get_canvas_item(), Rect2((size.x - ssize.x) / 2, 0, ssize.x, size.y)); diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 040559dab8..292a4cfea2 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -33,7 +33,7 @@ #include "core/os/keyboard.h" Size2 Slider::get_minimum_size() const { - Size2i ss = theme_cache.slider_style->get_minimum_size() + theme_cache.slider_style->get_center_size(); + Size2i ss = theme_cache.slider_style->get_minimum_size(); Size2i rs = theme_cache.grabber_icon->get_size(); if (orientation == HORIZONTAL) { @@ -212,7 +212,7 @@ void Slider::_notification(int p_what) { } if (orientation == VERTICAL) { - int widget_width = style->get_minimum_size().width + style->get_center_size().width; + int widget_width = style->get_minimum_size().width; double areasize = size.height - grabber->get_size().height; style->draw(ci, Rect2i(Point2i(size.width / 2 - widget_width / 2, 0), Size2i(widget_width, size.height))); grabber_area->draw(ci, Rect2i(Point2i((size.width - widget_width) / 2, size.height - areasize * ratio - grabber->get_size().height / 2), Size2i(widget_width, areasize * ratio + grabber->get_size().height / 2))); @@ -229,7 +229,7 @@ void Slider::_notification(int p_what) { } grabber->draw(ci, Point2i(size.width / 2 - grabber->get_size().width / 2 + get_theme_constant(SNAME("grabber_offset")), size.height - ratio * areasize - grabber->get_size().height)); } else { - int widget_height = style->get_minimum_size().height + style->get_center_size().height; + int widget_height = style->get_minimum_size().height; double areasize = size.width - grabber->get_size().width; style->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(size.width, widget_height))); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index d56b94b6fe..7bebf1cfd3 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -140,6 +140,7 @@ #include "scene/main/viewport.h" #include "scene/main/window.h" #include "scene/resources/animation_library.h" +#include "scene/resources/audio_stream_polyphonic.h" #include "scene/resources/audio_stream_wav.h" #include "scene/resources/bit_map.h" #include "scene/resources/bone_map.h" @@ -907,6 +908,8 @@ void register_scene_types() { #endif GDREGISTER_ABSTRACT_CLASS(VideoStream); GDREGISTER_CLASS(AudioStreamWAV); + GDREGISTER_CLASS(AudioStreamPolyphonic); + GDREGISTER_ABSTRACT_CLASS(AudioStreamPlaybackPolyphonic); OS::get_singleton()->yield(); // may take time to init diff --git a/scene/resources/audio_stream_polyphonic.cpp b/scene/resources/audio_stream_polyphonic.cpp new file mode 100644 index 0000000000..2e56ff3423 --- /dev/null +++ b/scene/resources/audio_stream_polyphonic.cpp @@ -0,0 +1,286 @@ +/**************************************************************************/ +/* audio_stream_polyphonic.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "audio_stream_polyphonic.h" +#include "scene/main/scene_tree.h" + +Ref<AudioStreamPlayback> AudioStreamPolyphonic::instantiate_playback() { + Ref<AudioStreamPlaybackPolyphonic> playback; + playback.instantiate(); + playback->streams.resize(polyphony); + return playback; +} + +String AudioStreamPolyphonic::get_stream_name() const { + return "AudioStreamPolyphonic"; +} + +bool AudioStreamPolyphonic::is_monophonic() const { + return true; // This avoids stream players to instantiate more than one of these. +} + +void AudioStreamPolyphonic::set_polyphony(int p_voices) { + ERR_FAIL_COND(p_voices < 0 || p_voices > 128); + polyphony = p_voices; +} +int AudioStreamPolyphonic::get_polyphony() const { + return polyphony; +} + +void AudioStreamPolyphonic::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_polyphony", "voices"), &AudioStreamPolyphonic::set_polyphony); + ClassDB::bind_method(D_METHOD("get_polyphony"), &AudioStreamPolyphonic::get_polyphony); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "polyphony", PROPERTY_HINT_RANGE, "1,128,1"), "set_polyphony", "get_polyphony"); +} + +AudioStreamPolyphonic::AudioStreamPolyphonic() { +} + +//////////////////////// + +void AudioStreamPlaybackPolyphonic::start(double p_from_pos) { + if (active) { + stop(); + } + + active = true; +} + +void AudioStreamPlaybackPolyphonic::stop() { + if (!active) { + return; + } + + bool locked = false; + for (Stream &s : streams) { + if (s.active.is_set()) { + // Need locking because something may still be mixing. + locked = true; + AudioServer::get_singleton()->lock(); + } + s.active.clear(); + s.finalizing.clear(); + s.finish_request.clear(); + s.stream_playback.unref(); + s.stream.unref(); + } + if (locked) { + AudioServer::get_singleton()->unlock(); + } + + active = false; +} + +bool AudioStreamPlaybackPolyphonic::is_playing() const { + return active; +} + +int AudioStreamPlaybackPolyphonic::get_loop_count() const { + return 0; +} + +double AudioStreamPlaybackPolyphonic::get_playback_position() const { + return 0; +} +void AudioStreamPlaybackPolyphonic::seek(double p_time) { + // Ignored. +} + +void AudioStreamPlaybackPolyphonic::tag_used_streams() { + for (Stream &s : streams) { + if (s.active.is_set()) { + s.stream_playback->tag_used_streams(); + } + } +} + +int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) { + if (!active) { + return 0; + } + + // Pre-clear buffer. + for (int i = 0; i < p_frames; i++) { + p_buffer[i] = AudioFrame(0, 0); + } + + for (Stream &s : streams) { + if (!s.active.is_set()) { + continue; + } + + float volume_db = s.volume_db; // Copy because it can be overriden at any time. + float next_volume = Math::db_to_linear(volume_db); + s.prev_volume_db = volume_db; + + if (s.finish_request.is_set()) { + if (s.pending_play.is_set()) { + // Did not get the chance to play, was finalized too soon. + s.active.clear(); + s.finalizing.set(); + continue; + } + next_volume = 0; + } + + if (s.pending_play.is_set()) { + s.stream_playback->start(s.play_offset); + s.pending_play.clear(); + } + float prev_volume = Math::db_to_linear(s.prev_volume_db); + + float volume_inc = (next_volume - prev_volume) / float(p_frames); + + int todo = p_frames; + int offset = 0; + float volume = prev_volume; + + while (todo) { + int to_mix = MIN(todo, int(INTERNAL_BUFFER_LEN)); + int mixed = s.stream_playback->mix(internal_buffer, s.pitch_scale, to_mix); + + for (int i = 0; i < to_mix; i++) { + p_buffer[offset + i] += internal_buffer[i] * volume; + volume += volume_inc; + } + + if (mixed < to_mix) { + // Stream is done. + s.active.clear(); + s.finalizing.set(); + break; + } + + todo -= to_mix; + offset += to_mix; + } + + if (s.finish_request.is_set()) { + s.active.clear(); + s.finalizing.set(); + } + } + + return p_frames; +} + +void AudioStreamPlaybackPolyphonic::_check_finalized_streams() { + if (!active) { + return; + } + + for (Stream &s : streams) { + if (!s.active.is_set() && s.finalizing.is_set()) { + s.stream_playback.unref(); + s.stream.unref(); + s.finalizing.clear(); + s.finish_request.clear(); + } + } +} + +AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(const Ref<AudioStream> &p_stream, float p_from_offset, float p_volume_db, float p_pitch_scale) { + ERR_FAIL_COND_V(p_stream.is_null(), INVALID_ID); + for (uint32_t i = 0; i < streams.size(); i++) { + if (!streams[i].active.is_set() && !streams[i].finish_request.is_set() && !streams[i].finalizing.is_set()) { + // Can use this stream, as it's not active. + streams[i].stream = p_stream; + streams[i].stream_playback = streams[i].stream->instantiate_playback(); + streams[i].play_offset = p_from_offset; + streams[i].volume_db = p_volume_db; + streams[i].prev_volume_db = p_volume_db; + streams[i].pitch_scale = p_pitch_scale; + streams[i].id = id_counter++; + streams[i].pending_play.set(); + streams[i].active.set(); + return (ID(i) << INDEX_SHIFT) | ID(streams[i].id); + } + } + + return INVALID_ID; +} + +AudioStreamPlaybackPolyphonic::Stream *AudioStreamPlaybackPolyphonic::_find_stream(int64_t p_id) { + uint32_t index = p_id >> INDEX_SHIFT; + if (index >= streams.size()) { + return nullptr; + } + if (!streams[index].active.is_set()) { + return nullptr; // Not active, no longer exists. + } + int64_t id = p_id & ID_MASK; + if (streams[index].id != id) { + return nullptr; + } + return &streams[index]; +} + +void AudioStreamPlaybackPolyphonic::set_stream_volume(ID p_stream_id, float p_volume_db) { + Stream *s = _find_stream(p_stream_id); + if (!s) { + return; + } + s->volume_db = p_volume_db; +} + +void AudioStreamPlaybackPolyphonic::set_stream_pitch_scale(ID p_stream_id, float p_pitch_scale) { + Stream *s = _find_stream(p_stream_id); + if (!s) { + return; + } + s->pitch_scale = p_pitch_scale; +} + +bool AudioStreamPlaybackPolyphonic::is_stream_playing(ID p_stream_id) const { + return const_cast<AudioStreamPlaybackPolyphonic *>(this)->_find_stream(p_stream_id) != nullptr; +} + +void AudioStreamPlaybackPolyphonic::stop_stream(ID p_stream_id) { + Stream *s = _find_stream(p_stream_id); + if (!s) { + return; + } + s->finish_request.set(); +} + +void AudioStreamPlaybackPolyphonic::_bind_methods() { + ClassDB::bind_method(D_METHOD("play_stream", "stream", "from_offset", "volume_db", "pitch_scale"), &AudioStreamPlaybackPolyphonic::play_stream, DEFVAL(0), DEFVAL(0), DEFVAL(1.0)); + ClassDB::bind_method(D_METHOD("set_stream_volume", "stream", "volume_db"), &AudioStreamPlaybackPolyphonic::set_stream_volume); + ClassDB::bind_method(D_METHOD("set_stream_pitch_scale", "stream", "pitch_scale"), &AudioStreamPlaybackPolyphonic::set_stream_pitch_scale); + ClassDB::bind_method(D_METHOD("is_stream_playing", "stream"), &AudioStreamPlaybackPolyphonic::is_stream_playing); + ClassDB::bind_method(D_METHOD("stop_stream", "stream"), &AudioStreamPlaybackPolyphonic::stop_stream); + + BIND_CONSTANT(INVALID_ID); +} + +AudioStreamPlaybackPolyphonic::AudioStreamPlaybackPolyphonic() { + SceneTree::get_singleton()->connect(SNAME("process_frame"), callable_mp(this, &AudioStreamPlaybackPolyphonic::_check_finalized_streams)); +} diff --git a/scene/resources/audio_stream_polyphonic.h b/scene/resources/audio_stream_polyphonic.h new file mode 100644 index 0000000000..b5ccc7eb7f --- /dev/null +++ b/scene/resources/audio_stream_polyphonic.h @@ -0,0 +1,122 @@ +/**************************************************************************/ +/* audio_stream_polyphonic.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef AUDIO_STREAM_POLYPHONIC_H +#define AUDIO_STREAM_POLYPHONIC_H + +#include "core/templates/local_vector.h" +#include "servers/audio/audio_stream.h" + +class AudioStreamPolyphonic : public AudioStream { + GDCLASS(AudioStreamPolyphonic, AudioStream) + int polyphony = 32; + + static void _bind_methods(); + +public: + virtual Ref<AudioStreamPlayback> instantiate_playback() override; + virtual String get_stream_name() const override; + virtual bool is_monophonic() const override; + + void set_polyphony(int p_voices); + int get_polyphony() const; + + AudioStreamPolyphonic(); +}; + +class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback { + GDCLASS(AudioStreamPlaybackPolyphonic, AudioStreamPlayback) + + enum { + INTERNAL_BUFFER_LEN = 128, + ID_MASK = 0xFFFFFFFF, + INDEX_SHIFT = 32 + }; + struct Stream { + SafeFlag active; + SafeFlag pending_play; + SafeFlag finish_request; + SafeFlag finalizing; + float play_offset = 0; + float pitch_scale = 1.0; + Ref<AudioStream> stream; + Ref<AudioStreamPlayback> stream_playback; + float prev_volume_db = 0; + float volume_db = 0; + uint32_t id = 0; + + Stream() : + active(false), pending_play(false), finish_request(false), finalizing(false) {} + }; + + LocalVector<Stream> streams; + AudioFrame internal_buffer[INTERNAL_BUFFER_LEN]; + + bool active = false; + uint32_t id_counter = 1; + + _FORCE_INLINE_ Stream *_find_stream(int64_t p_id); + + void _check_finalized_streams(); + + friend class AudioStreamPolyphonic; + +protected: + static void _bind_methods(); + +public: + typedef int64_t ID; + enum { + INVALID_ID = -1 + }; + + virtual void start(double p_from_pos = 0.0) override; + virtual void stop() override; + virtual bool is_playing() const override; + + virtual int get_loop_count() const override; //times it looped + + virtual double get_playback_position() const override; + virtual void seek(double p_time) override; + + virtual void tag_used_streams() override; + + virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; + + ID play_stream(const Ref<AudioStream> &p_stream, float p_from_offset = 0, float p_volume_db = 0, float p_pitch_scale = 1.0); + void set_stream_volume(ID p_stream_id, float p_volume_db); + void set_stream_pitch_scale(ID p_stream_id, float p_pitch_scale); + bool is_stream_playing(ID p_stream_id) const; + void stop_stream(ID p_stream_id); + + AudioStreamPlaybackPolyphonic(); +}; + +#endif // AUDIO_STREAM_POLYPHONIC_H diff --git a/scene/resources/camera_attributes.cpp b/scene/resources/camera_attributes.cpp index b5e302cce5..61df56523d 100644 --- a/scene/resources/camera_attributes.cpp +++ b/scene/resources/camera_attributes.cpp @@ -286,10 +286,10 @@ void CameraAttributesPractical::_bind_methods() { ADD_GROUP("DOF Blur", "dof_blur_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dof_blur_far_enabled"), "set_dof_blur_far_enabled", "is_dof_blur_far_enabled"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_distance", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp,suffix:m"), "set_dof_blur_far_distance", "get_dof_blur_far_distance"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_transition", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_far_transition", "get_dof_blur_far_transition"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_transition", PROPERTY_HINT_RANGE, "-1,8192,0.01,exp"), "set_dof_blur_far_transition", "get_dof_blur_far_transition"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dof_blur_near_enabled"), "set_dof_blur_near_enabled", "is_dof_blur_near_enabled"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_distance", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp,suffix:m"), "set_dof_blur_near_distance", "get_dof_blur_near_distance"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_transition", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_near_transition", "get_dof_blur_near_transition"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_transition", PROPERTY_HINT_RANGE, "-1,8192,0.01,exp"), "set_dof_blur_near_transition", "get_dof_blur_near_transition"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dof_blur_amount", "get_dof_blur_amount"); ADD_GROUP("Auto Exposure", "auto_exposure_"); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 4d3eec6333..7a865691d9 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -53,7 +53,7 @@ static const int default_corner_radius = 3; static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = default_margin, float p_margin_top = default_margin, float p_margin_right = default_margin, float p_margin_bottom = default_margin, int p_corner_radius = default_corner_radius, bool p_draw_center = true, int p_border_width = 0) { Ref<StyleBoxFlat> style(memnew(StyleBoxFlat)); style->set_bg_color(p_color); - style->set_default_margin_individual(p_margin_left * scale, p_margin_top * scale, p_margin_right * scale, p_margin_bottom * scale); + style->set_content_margin_individual(p_margin_left * scale, p_margin_top * scale, p_margin_right * scale, p_margin_bottom * scale); style->set_corner_radius_all(p_corner_radius); style->set_anti_aliased(true); @@ -67,10 +67,10 @@ static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = } static Ref<StyleBoxFlat> sb_expand(Ref<StyleBoxFlat> p_sbox, float p_left, float p_top, float p_right, float p_bottom) { - p_sbox->set_expand_margin_size(SIDE_LEFT, p_left * scale); - p_sbox->set_expand_margin_size(SIDE_TOP, p_top * scale); - p_sbox->set_expand_margin_size(SIDE_RIGHT, p_right * scale); - p_sbox->set_expand_margin_size(SIDE_BOTTOM, p_bottom * scale); + p_sbox->set_expand_margin(SIDE_LEFT, p_left * scale); + p_sbox->set_expand_margin(SIDE_TOP, p_top * scale); + p_sbox->set_expand_margin(SIDE_RIGHT, p_right * scale); + p_sbox->set_expand_margin(SIDE_BOTTOM, p_bottom * scale); return p_sbox; } @@ -93,7 +93,7 @@ static Ref<ImageTexture> generate_icon(int p_index) { static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) { Ref<StyleBox> style(memnew(StyleBoxEmpty)); - style->set_default_margin_individual(p_margin_left * scale, p_margin_top * scale, p_margin_right * scale, p_margin_bottom * scale); + style->set_content_margin_individual(p_margin_left * scale, p_margin_top * scale, p_margin_right * scale, p_margin_bottom * scale); return style; } @@ -148,7 +148,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const const Ref<StyleBoxFlat> button_disabled = make_flat_stylebox(style_disabled_color); Ref<StyleBoxFlat> focus = make_flat_stylebox(style_focus_color, default_margin, default_margin, default_margin, default_margin, default_corner_radius, false, 2); // Make the focus outline appear to be flush with the buttons it's focusing. - focus->set_expand_margin_size_all(2 * scale); + focus->set_expand_margin_all(2 * scale); theme->set_stylebox("normal", "Button", button_normal); theme->set_stylebox("hover", "Button", button_hover); @@ -279,9 +279,9 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // CheckBox Ref<StyleBox> cbx_empty = memnew(StyleBoxEmpty); - cbx_empty->set_default_margin_all(4 * scale); + cbx_empty->set_content_margin_all(4 * scale); Ref<StyleBox> cbx_focus = focus; - cbx_focus->set_default_margin_all(4 * scale); + cbx_focus->set_content_margin_all(4 * scale); theme->set_stylebox("normal", "CheckBox", cbx_empty); theme->set_stylebox("pressed", "CheckBox", cbx_empty); @@ -317,7 +317,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // CheckButton Ref<StyleBox> cb_empty = memnew(StyleBoxEmpty); - cb_empty->set_default_margin_individual(6 * scale, 4 * scale, 6 * scale, 4 * scale); + cb_empty->set_content_margin_individual(6 * scale, 4 * scale, 6 * scale, 4 * scale); theme->set_stylebox("normal", "CheckButton", cb_empty); theme->set_stylebox("pressed", "CheckButton", cb_empty); @@ -634,10 +634,10 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const Ref<StyleBoxLine> separator_horizontal = memnew(StyleBoxLine); separator_horizontal->set_thickness(Math::round(scale)); separator_horizontal->set_color(style_separator_color); - separator_horizontal->set_default_margin_individual(default_margin, 0, default_margin, 0); + separator_horizontal->set_content_margin_individual(default_margin, 0, default_margin, 0); Ref<StyleBoxLine> separator_vertical = separator_horizontal->duplicate(); separator_vertical->set_vertical(true); - separator_vertical->set_default_margin_individual(0, default_margin, 0, default_margin); + separator_vertical->set_content_margin_individual(0, default_margin, 0, default_margin); // Always display a border for PopupMenus so they can be distinguished from their background. Ref<StyleBoxFlat> style_popup_panel = make_flat_stylebox(style_popup_color); diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index cedf4319f8..991e060e94 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -189,6 +189,7 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { if (primitive == PRIMITIVE_TRIANGLES) { for (int j = 0; j < ic; j++) { int index = ir[j]; + ERR_FAIL_COND_V(index >= vc, Ref<TriangleMesh>()); facesw[widx++] = vr[index]; } } else { // PRIMITIVE_TRIANGLE_STRIP @@ -1121,17 +1122,6 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { } int idx = sname.substr(8, sl - 8).to_int(); - // This is a bit of a hack to ensure compatibility with older material - // overrides that start indexing at 1. - // We assume that idx 0 is always read first, if its not, this won't work. - if (idx == 0) { - surface_index_0 = true; - } - if (!surface_index_0) { - // This means the file was created when the indexing started at 1, so decrease by one. - idx--; - } - String what = sname.get_slicec('/', 1); if (what == "material") { surface_set_material(idx, p_value); diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 6390850b24..4f16986392 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -34,76 +34,65 @@ #include <limits.h> -float StyleBox::get_style_margin(Side p_side) const { - float ret = 0; - GDVIRTUAL_REQUIRED_CALL(_get_style_margin, p_side, ret); - return ret; -} +Size2 StyleBox::get_minimum_size() const { + Size2 min_size = Size2(get_margin(SIDE_LEFT) + get_margin(SIDE_RIGHT), get_margin(SIDE_TOP) + get_margin(SIDE_BOTTOM)); + Size2 custom_size; + GDVIRTUAL_CALL(_get_minimum_size, custom_size); -bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const { - bool ret = true; - GDVIRTUAL_CALL(_test_mask, p_point, p_rect, ret); - return ret; -} + if (min_size.x < custom_size.x) { + min_size.x = custom_size.x; + } + if (min_size.y < custom_size.y) { + min_size.y = custom_size.y; + } -void StyleBox::draw(RID p_canvas_item, const Rect2 &p_rect) const { - GDVIRTUAL_REQUIRED_CALL(_draw, p_canvas_item, p_rect); + return min_size; } -void StyleBox::set_default_margin(Side p_side, float p_value) { +void StyleBox::set_content_margin(Side p_side, float p_value) { ERR_FAIL_INDEX((int)p_side, 4); - margin[p_side] = p_value; + content_margin[p_side] = p_value; emit_changed(); } -void StyleBox::set_default_margin_all(float p_value) { +void StyleBox::set_content_margin_all(float p_value) { for (int i = 0; i < 4; i++) { - margin[i] = p_value; + content_margin[i] = p_value; } emit_changed(); } -void StyleBox::set_default_margin_individual(float p_left, float p_top, float p_right, float p_bottom) { - margin[SIDE_LEFT] = p_left; - margin[SIDE_TOP] = p_top; - margin[SIDE_RIGHT] = p_right; - margin[SIDE_BOTTOM] = p_bottom; +void StyleBox::set_content_margin_individual(float p_left, float p_top, float p_right, float p_bottom) { + content_margin[SIDE_LEFT] = p_left; + content_margin[SIDE_TOP] = p_top; + content_margin[SIDE_RIGHT] = p_right; + content_margin[SIDE_BOTTOM] = p_bottom; emit_changed(); } -float StyleBox::get_default_margin(Side p_side) const { +float StyleBox::get_content_margin(Side p_side) const { ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); - return margin[p_side]; + return content_margin[p_side]; } float StyleBox::get_margin(Side p_side) const { ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); - if (margin[p_side] < 0) { + if (content_margin[p_side] < 0) { return get_style_margin(p_side); } else { - return margin[p_side]; + return content_margin[p_side]; } } -CanvasItem *StyleBox::get_current_item_drawn() const { - return CanvasItem::get_current_item_drawn(); -} - -Size2 StyleBox::get_minimum_size() const { - return Size2(get_margin(SIDE_LEFT) + get_margin(SIDE_RIGHT), get_margin(SIDE_TOP) + get_margin(SIDE_BOTTOM)); -} - Point2 StyleBox::get_offset() const { return Point2(get_margin(SIDE_LEFT), get_margin(SIDE_TOP)); } -Size2 StyleBox::get_center_size() const { - Size2 ret; - GDVIRTUAL_CALL(_get_center_size, ret); - return ret; +void StyleBox::draw(RID p_canvas_item, const Rect2 &p_rect) const { + GDVIRTUAL_REQUIRED_CALL(_draw, p_canvas_item, p_rect); } Rect2 StyleBox::get_draw_rect(const Rect2 &p_rect) const { @@ -114,37 +103,46 @@ Rect2 StyleBox::get_draw_rect(const Rect2 &p_rect) const { return p_rect; } +CanvasItem *StyleBox::get_current_item_drawn() const { + return CanvasItem::get_current_item_drawn(); +} + +bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const { + bool ret = true; + GDVIRTUAL_CALL(_test_mask, p_point, p_rect, ret); + return ret; +} + void StyleBox::_bind_methods() { - ClassDB::bind_method(D_METHOD("test_mask", "point", "rect"), &StyleBox::test_mask); + ClassDB::bind_method(D_METHOD("get_minimum_size"), &StyleBox::get_minimum_size); - ClassDB::bind_method(D_METHOD("set_default_margin", "margin", "offset"), &StyleBox::set_default_margin); - ClassDB::bind_method(D_METHOD("set_default_margin_all", "offset"), &StyleBox::set_default_margin_all); - ClassDB::bind_method(D_METHOD("get_default_margin", "margin"), &StyleBox::get_default_margin); + ClassDB::bind_method(D_METHOD("set_content_margin", "margin", "offset"), &StyleBox::set_content_margin); + ClassDB::bind_method(D_METHOD("set_content_margin_all", "offset"), &StyleBox::set_content_margin_all); + ClassDB::bind_method(D_METHOD("get_content_margin", "margin"), &StyleBox::get_content_margin); ClassDB::bind_method(D_METHOD("get_margin", "margin"), &StyleBox::get_margin); - ClassDB::bind_method(D_METHOD("get_minimum_size"), &StyleBox::get_minimum_size); - ClassDB::bind_method(D_METHOD("get_center_size"), &StyleBox::get_center_size); ClassDB::bind_method(D_METHOD("get_offset"), &StyleBox::get_offset); - ClassDB::bind_method(D_METHOD("get_current_item_drawn"), &StyleBox::get_current_item_drawn); ClassDB::bind_method(D_METHOD("draw", "canvas_item", "rect"), &StyleBox::draw); + ClassDB::bind_method(D_METHOD("get_current_item_drawn"), &StyleBox::get_current_item_drawn); + + ClassDB::bind_method(D_METHOD("test_mask", "point", "rect"), &StyleBox::test_mask); ADD_GROUP("Content Margins", "content_margin_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_left", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_default_margin", "get_default_margin", SIDE_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_top", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_default_margin", "get_default_margin", SIDE_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_right", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_default_margin", "get_default_margin", SIDE_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_bottom", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_default_margin", "get_default_margin", SIDE_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_left", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_content_margin", "get_content_margin", SIDE_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_top", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_content_margin", "get_content_margin", SIDE_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_right", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_content_margin", "get_content_margin", SIDE_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_bottom", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_content_margin", "get_content_margin", SIDE_BOTTOM); - GDVIRTUAL_BIND(_get_style_margin, "side") - GDVIRTUAL_BIND(_test_mask, "point", "rect") - GDVIRTUAL_BIND(_get_center_size) - GDVIRTUAL_BIND(_get_draw_rect, "rect") GDVIRTUAL_BIND(_draw, "to_canvas_item", "rect") + GDVIRTUAL_BIND(_get_draw_rect, "rect") + GDVIRTUAL_BIND(_get_minimum_size) + GDVIRTUAL_BIND(_test_mask, "point", "rect") } StyleBox::StyleBox() { for (int i = 0; i < 4; i++) { - margin[i] = -1; + content_margin[i] = -1; } } @@ -165,38 +163,38 @@ Ref<Texture2D> StyleBoxTexture::get_texture() const { return texture; } -void StyleBoxTexture::set_margin_size(Side p_side, float p_size) { +void StyleBoxTexture::set_texture_margin(Side p_side, float p_size) { ERR_FAIL_INDEX((int)p_side, 4); - margin[p_side] = p_size; + texture_margin[p_side] = p_size; emit_changed(); } -void StyleBoxTexture::set_margin_size_all(float p_size) { +void StyleBoxTexture::set_texture_margin_all(float p_size) { for (int i = 0; i < 4; i++) { - margin[i] = p_size; + texture_margin[i] = p_size; } emit_changed(); } -void StyleBoxTexture::set_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) { - margin[SIDE_LEFT] = p_left; - margin[SIDE_TOP] = p_top; - margin[SIDE_RIGHT] = p_right; - margin[SIDE_BOTTOM] = p_bottom; +void StyleBoxTexture::set_texture_margin_individual(float p_left, float p_top, float p_right, float p_bottom) { + texture_margin[SIDE_LEFT] = p_left; + texture_margin[SIDE_TOP] = p_top; + texture_margin[SIDE_RIGHT] = p_right; + texture_margin[SIDE_BOTTOM] = p_bottom; emit_changed(); } -float StyleBoxTexture::get_margin_size(Side p_side) const { +float StyleBoxTexture::get_texture_margin(Side p_side) const { ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); - return margin[p_side]; + return texture_margin[p_side]; } float StyleBoxTexture::get_style_margin(Side p_side) const { ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); - return margin[p_side]; + return texture_margin[p_side]; } Rect2 StyleBoxTexture::get_draw_rect(const Rect2 &p_rect) const { @@ -218,7 +216,10 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { rect.size.x += expand_margin[SIDE_LEFT] + expand_margin[SIDE_RIGHT]; rect.size.y += expand_margin[SIDE_TOP] + expand_margin[SIDE_BOTTOM]; - RenderingServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[SIDE_LEFT], margin[SIDE_TOP]), Vector2(margin[SIDE_RIGHT], margin[SIDE_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center, modulate); + Vector2 start_offset = Vector2(texture_margin[SIDE_LEFT], texture_margin[SIDE_TOP]); + Vector2 end_offset = Vector2(texture_margin[SIDE_RIGHT], texture_margin[SIDE_BOTTOM]); + + RenderingServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), start_offset, end_offset, RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center, modulate); } void StyleBoxTexture::set_draw_center(bool p_enabled) { @@ -230,21 +231,29 @@ bool StyleBoxTexture::is_draw_center_enabled() const { return draw_center; } -Size2 StyleBoxTexture::get_center_size() const { - if (texture.is_null()) { - return Size2(); +Size2 StyleBoxTexture::get_minimum_size() const { + Size2 min_size = StyleBox::get_minimum_size(); + + // Make sure that the min size is no smaller than the used texture region. + if (texture.is_valid()) { + if (min_size.x < region_rect.size.x) { + min_size.x = region_rect.size.x; + } + if (min_size.y < region_rect.size.y) { + min_size.y = region_rect.size.y; + } } - return region_rect.size - get_minimum_size(); + return min_size; } -void StyleBoxTexture::set_expand_margin_size(Side p_side, float p_size) { +void StyleBoxTexture::set_expand_margin(Side p_side, float p_size) { ERR_FAIL_INDEX((int)p_side, 4); expand_margin[p_side] = p_size; emit_changed(); } -void StyleBoxTexture::set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) { +void StyleBoxTexture::set_expand_margin_individual(float p_left, float p_top, float p_right, float p_bottom) { expand_margin[SIDE_LEFT] = p_left; expand_margin[SIDE_TOP] = p_top; expand_margin[SIDE_RIGHT] = p_right; @@ -252,14 +261,14 @@ void StyleBoxTexture::set_expand_margin_size_individual(float p_left, float p_to emit_changed(); } -void StyleBoxTexture::set_expand_margin_size_all(float p_expand_margin_size) { +void StyleBoxTexture::set_expand_margin_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(Side p_side) const { +float StyleBoxTexture::get_expand_margin(Side p_side) const { ERR_FAIL_INDEX_V((int)p_side, 4, 0); return expand_margin[p_side]; } @@ -313,13 +322,13 @@ void StyleBoxTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_texture", "texture"), &StyleBoxTexture::set_texture); ClassDB::bind_method(D_METHOD("get_texture"), &StyleBoxTexture::get_texture); - ClassDB::bind_method(D_METHOD("set_margin_size", "margin", "size"), &StyleBoxTexture::set_margin_size); - ClassDB::bind_method(D_METHOD("set_margin_size_all", "size"), &StyleBoxTexture::set_margin_size_all); - ClassDB::bind_method(D_METHOD("get_margin_size", "margin"), &StyleBoxTexture::get_margin_size); + ClassDB::bind_method(D_METHOD("set_texture_margin", "margin", "size"), &StyleBoxTexture::set_texture_margin); + ClassDB::bind_method(D_METHOD("set_texture_margin_all", "size"), &StyleBoxTexture::set_texture_margin_all); + ClassDB::bind_method(D_METHOD("get_texture_margin", "margin"), &StyleBoxTexture::get_texture_margin); - 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("get_expand_margin_size", "margin"), &StyleBoxTexture::get_expand_margin_size); + ClassDB::bind_method(D_METHOD("set_expand_margin", "margin", "size"), &StyleBoxTexture::set_expand_margin); + ClassDB::bind_method(D_METHOD("set_expand_margin_all", "size"), &StyleBoxTexture::set_expand_margin_all); + ClassDB::bind_method(D_METHOD("get_expand_margin", "margin"), &StyleBoxTexture::get_expand_margin); ClassDB::bind_method(D_METHOD("set_region_rect", "region"), &StyleBoxTexture::set_region_rect); ClassDB::bind_method(D_METHOD("get_region_rect"), &StyleBoxTexture::get_region_rect); @@ -338,17 +347,17 @@ void StyleBoxTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); - ADD_GROUP("Margins", "margin_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_left", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_margin_size", "get_margin_size", SIDE_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_top", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_margin_size", "get_margin_size", SIDE_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_right", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_margin_size", "get_margin_size", SIDE_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_margin_size", "get_margin_size", SIDE_BOTTOM); + ADD_GROUP("Texture Margins", "texture_margin_"); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "texture_margin_left", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_texture_margin", "get_texture_margin", SIDE_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "texture_margin_top", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_texture_margin", "get_texture_margin", SIDE_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "texture_margin_right", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_texture_margin", "get_texture_margin", SIDE_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "texture_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_texture_margin", "get_texture_margin", SIDE_BOTTOM); ADD_GROUP("Expand Margins", "expand_margin_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_expand_margin_size", "get_expand_margin_size", SIDE_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_expand_margin_size", "get_expand_margin_size", SIDE_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_right", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_expand_margin_size", "get_expand_margin_size", SIDE_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_expand_margin_size", "get_expand_margin_size", SIDE_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_expand_margin", "get_expand_margin", SIDE_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_expand_margin", "get_expand_margin", SIDE_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_right", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_expand_margin", "get_expand_margin", SIDE_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1,suffix:px"), "set_expand_margin", "get_expand_margin", SIDE_BOTTOM); ADD_GROUP("Axis Stretch", "axis_stretch_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_stretch_horizontal", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_h_axis_stretch_mode", "get_h_axis_stretch_mode"); @@ -450,13 +459,13 @@ int StyleBoxFlat::get_corner_radius(const Corner p_corner) const { return corner_radius[p_corner]; } -void StyleBoxFlat::set_expand_margin_size(Side p_side, float p_size) { +void StyleBoxFlat::set_expand_margin(Side p_side, float p_size) { ERR_FAIL_INDEX((int)p_side, 4); expand_margin[p_side] = p_size; emit_changed(); } -void StyleBoxFlat::set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) { +void StyleBoxFlat::set_expand_margin_individual(float p_left, float p_top, float p_right, float p_bottom) { expand_margin[SIDE_LEFT] = p_left; expand_margin[SIDE_TOP] = p_top; expand_margin[SIDE_RIGHT] = p_right; @@ -464,14 +473,14 @@ void StyleBoxFlat::set_expand_margin_size_individual(float p_left, float p_top, emit_changed(); } -void StyleBoxFlat::set_expand_margin_size_all(float p_expand_margin_size) { +void StyleBoxFlat::set_expand_margin_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(Side p_side) const { +float StyleBoxFlat::get_expand_margin(Side p_side) const { ERR_FAIL_INDEX_V((int)p_side, 4, 0.0); return expand_margin[p_side]; } @@ -549,10 +558,6 @@ int StyleBoxFlat::get_corner_detail() const { return corner_detail; } -Size2 StyleBoxFlat::get_center_size() const { - return Size2(); -} - inline void set_inner_corner_radius(const Rect2 style_rect, const Rect2 inner_rect, const real_t corner_radius[4], real_t *inner_corner_radius) { real_t border_left = inner_rect.position.x - style_rect.position.x; real_t border_top = inner_rect.position.y - style_rect.position.y; @@ -891,9 +896,9 @@ void StyleBoxFlat::_bind_methods() { ClassDB::bind_method(D_METHOD("set_corner_radius", "corner", "radius"), &StyleBoxFlat::set_corner_radius); 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("get_expand_margin", "margin"), &StyleBoxFlat::get_expand_margin_size); + ClassDB::bind_method(D_METHOD("set_expand_margin", "margin", "size"), &StyleBoxFlat::set_expand_margin); + ClassDB::bind_method(D_METHOD("set_expand_margin_all", "size"), &StyleBoxFlat::set_expand_margin_all); + ClassDB::bind_method(D_METHOD("get_expand_margin", "margin"), &StyleBoxFlat::get_expand_margin); ClassDB::bind_method(D_METHOD("set_draw_center", "draw_center"), &StyleBoxFlat::set_draw_center); ClassDB::bind_method(D_METHOD("is_draw_center_enabled"), &StyleBoxFlat::is_draw_center_enabled); @@ -1041,10 +1046,6 @@ float StyleBoxLine::get_style_margin(Side p_side) const { return 0; } -Size2 StyleBoxLine::get_center_size() const { - return Size2(); -} - void StyleBoxLine::draw(RID p_canvas_item, const Rect2 &p_rect) const { RenderingServer *vs = RenderingServer::get_singleton(); Rect2i r = p_rect; diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index 5a80b4d4e2..91033617ab 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -41,36 +41,34 @@ class StyleBox : public Resource { GDCLASS(StyleBox, Resource); RES_BASE_EXTENSION("stylebox"); OBJ_SAVE_TYPE(StyleBox); - float margin[4]; + float content_margin[4]; protected: - virtual float get_style_margin(Side p_side) const; + virtual float get_style_margin(Side p_side) const { return 0; } static void _bind_methods(); - GDVIRTUAL1RC(float, _get_style_margin, Side) - GDVIRTUAL2RC(bool, _test_mask, Point2, Rect2) - GDVIRTUAL0RC(Size2, _get_center_size) - GDVIRTUAL1RC(Rect2, _get_draw_rect, Rect2) GDVIRTUAL2C(_draw, RID, Rect2) + GDVIRTUAL1RC(Rect2, _get_draw_rect, Rect2) + GDVIRTUAL0RC(Size2, _get_minimum_size) + GDVIRTUAL2RC(bool, _test_mask, Point2, Rect2) public: - virtual bool test_mask(const Point2 &p_point, const Rect2 &p_rect) const; + virtual Size2 get_minimum_size() const; - void set_default_margin(Side p_side, float p_value); - void set_default_margin_all(float p_value); - void set_default_margin_individual(float p_left, float p_top, float p_right, float p_bottom); - float get_default_margin(Side p_side) const; + void set_content_margin(Side p_side, float p_value); + void set_content_margin_all(float p_value); + void set_content_margin_individual(float p_left, float p_top, float p_right, float p_bottom); + float get_content_margin(Side p_side) const; float get_margin(Side p_side) const; - virtual Size2 get_center_size() const; + Point2 get_offset() const; - virtual Rect2 get_draw_rect(const Rect2 &p_rect) const; virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const; + virtual Rect2 get_draw_rect(const Rect2 &p_rect) const; CanvasItem *get_current_item_drawn() const; - Size2 get_minimum_size() const; - Point2 get_offset() const; + virtual bool test_mask(const Point2 &p_point, const Rect2 &p_rect) const; StyleBox(); }; @@ -96,7 +94,7 @@ public: private: float expand_margin[4] = {}; - float margin[4] = {}; + float texture_margin[4] = {}; Rect2 region_rect; Ref<Texture2D> texture; bool draw_center = true; @@ -109,15 +107,17 @@ protected: static void _bind_methods(); public: - void set_expand_margin_size(Side p_expand_side, 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(Side p_expand_side) const; + virtual Size2 get_minimum_size() const override; - void set_margin_size(Side p_side, float p_size); - void set_margin_size_all(float p_size); - void set_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom); - float get_margin_size(Side p_side) const; + void set_expand_margin(Side p_expand_side, float p_size); + void set_expand_margin_all(float p_expand_margin_size); + void set_expand_margin_individual(float p_left, float p_top, float p_right, float p_bottom); + float get_expand_margin(Side p_expand_side) const; + + void set_texture_margin(Side p_side, float p_size); + void set_texture_margin_all(float p_size); + void set_texture_margin_individual(float p_left, float p_top, float p_right, float p_bottom); + float get_texture_margin(Side p_side) const; void set_region_rect(const Rect2 &p_region_rect); Rect2 get_region_rect() const; @@ -127,7 +127,6 @@ public: void set_draw_center(bool p_enabled); bool is_draw_center_enabled() const; - virtual Size2 get_center_size() const override; void set_h_axis_stretch_mode(AxisStretchMode p_mode); AxisStretchMode get_h_axis_stretch_mode() const; @@ -198,10 +197,10 @@ public: void set_corner_detail(const int &p_corner_detail); int get_corner_detail() const; - void set_expand_margin_size(Side p_expand_side, 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(Side p_expand_side) const; + void set_expand_margin(Side p_expand_side, float p_size); + void set_expand_margin_all(float p_expand_margin_size); + void set_expand_margin_individual(float p_left, float p_top, float p_right, float p_bottom); + float get_expand_margin(Side p_expand_side) const; void set_draw_center(bool p_enabled); bool is_draw_center_enabled() const; @@ -223,8 +222,6 @@ public: void set_aa_size(const real_t p_aa_size); real_t get_aa_size() const; - virtual Size2 get_center_size() const override; - virtual Rect2 get_draw_rect(const Rect2 &p_rect) const override; virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const override; @@ -261,8 +258,6 @@ public: void set_grow_end(float p_grow); float get_grow_end() const; - virtual Size2 get_center_size() const override; - virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const override; StyleBoxLine(); diff --git a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl index d32e6d717f..46c53c11ae 100644 --- a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl +++ b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl @@ -1798,7 +1798,7 @@ void fragment_shader(in SceneData scene_data) { shadow = float(shadow1 >> ((i - 4u) * 8u) & 0xFFu) / 255.0; } - shadow = shadow * directional_lights.data[i].shadow_opacity + 1.0 - directional_lights.data[i].shadow_opacity; + shadow = mix(1.0, shadow, directional_lights.data[i].shadow_opacity); #endif blur_shadow(shadow); diff --git a/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl index 5e64d4e651..2966a2ff65 100644 --- a/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl +++ b/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl @@ -1515,6 +1515,8 @@ void main() { } else { shadow = float(shadow1 >> ((i - 4) * 8) & 0xFF) / 255.0; } + + shadow = mix(1.0, shadow, directional_lights.data[i].shadow_opacity); #endif blur_shadow(shadow); |