diff options
Diffstat (limited to 'doc/classes/CanvasItem.xml')
-rw-r--r-- | doc/classes/CanvasItem.xml | 219 |
1 files changed, 105 insertions, 114 deletions
diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml index f2ce2a6fb9..87b157db4e 100644 --- a/doc/classes/CanvasItem.xml +++ b/doc/classes/CanvasItem.xml @@ -9,10 +9,12 @@ Canvas items are drawn in tree order. By default, children are on top of their parents so a root [CanvasItem] will be drawn behind everything. This behavior can be changed on a per-item basis. A [CanvasItem] can also be hidden, which will also hide its children. It provides many ways to change parameters such as modulation (for itself and its children) and self modulation (only for itself), as well as its blend mode. Ultimately, a transform notification can be requested, which will notify the node that its global position changed in case the parent tree changed. + [b]Note:[/b] Unless otherwise specified, all methods that have angle parameters must have angles specified as [i]radians[/i]. To convert degrees to radians, use [method @GlobalScope.deg2rad]. </description> <tutorials> - <link>https://docs.godotengine.org/en/latest/tutorials/2d/2d_transforms.html</link> - <link>https://docs.godotengine.org/en/latest/tutorials/2d/custom_drawing_in_2d.html</link> + <link title="Viewport and canvas transforms">https://docs.godotengine.org/en/latest/tutorials/2d/2d_transforms.html</link> + <link title="Custom drawing in 2D">https://docs.godotengine.org/en/latest/tutorials/2d/custom_drawing_in_2d.html</link> + <link title="Audio Spectrum Demo">https://godotengine.org/asset-library/asset/528</link> </tutorials> <methods> <method name="_draw" qualifiers="virtual"> @@ -39,22 +41,30 @@ </argument> <argument index="6" name="width" type="float" default="1.0"> </argument> + <argument index="7" name="antialiased" type="bool" default="false"> + </argument> <description> Draws an arc between the given angles. The larger the value of [code]point_count[/code], the smoother the curve. </description> </method> - <method name="draw_char"> + <method name="draw_char" qualifiers="const"> <return type="float"> </return> <argument index="0" name="font" type="Font"> </argument> - <argument index="1" name="position" type="Vector2"> + <argument index="1" name="pos" type="Vector2"> </argument> <argument index="2" name="char" type="String"> </argument> - <argument index="3" name="next" type="String"> + <argument index="3" name="next" type="String" default=""""> + </argument> + <argument index="4" name="size" type="int" default="-1"> </argument> - <argument index="4" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> + <argument index="5" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> + </argument> + <argument index="6" name="outline_size" type="int" default="0"> + </argument> + <argument index="7" name="outline_modulate" type="Color" default="Color( 1, 1, 1, 0 )"> </argument> <description> Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character. @@ -84,16 +94,6 @@ </argument> <argument index="3" name="texture" type="Texture2D" default="null"> </argument> - <argument index="4" name="normal_map" type="Texture2D" default="null"> - </argument> - <argument index="5" name="specular_map" type="Texture2D" default="null"> - </argument> - <argument index="6" name="specular_shininess" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <argument index="7" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0"> - </argument> - <argument index="8" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0"> - </argument> <description> Draws a colored polygon of any amount of points, convex or concave. </description> @@ -120,19 +120,9 @@ </argument> <argument index="1" name="texture" type="Texture2D"> </argument> - <argument index="2" name="normal_map" type="Texture2D" default="null"> - </argument> - <argument index="3" name="specular_map" type="Texture2D" default="null"> + <argument index="2" name="transform" type="Transform2D" default="Transform2D( 1, 0, 0, 1, 0, 0 )"> </argument> - <argument index="4" name="specular_shininess" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <argument index="5" name="transform" type="Transform2D" default="Transform2D( 1, 0, 0, 1, 0, 0 )"> - </argument> - <argument index="6" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <argument index="7" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0"> - </argument> - <argument index="8" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0"> + <argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> </argument> <description> Draws a [Mesh] in 2D, using the provided texture. See [MeshInstance2D] for related documentation. @@ -164,22 +154,41 @@ Draws multiple, parallel lines with a uniform [code]width[/code] and segment-by-segment coloring. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code]. </description> </method> - <method name="draw_multimesh"> + <method name="draw_multiline_string" qualifiers="const"> <return type="void"> </return> - <argument index="0" name="multimesh" type="MultiMesh"> + <argument index="0" name="font" type="Font"> </argument> - <argument index="1" name="texture" type="Texture2D"> + <argument index="1" name="pos" type="Vector2"> </argument> - <argument index="2" name="normal_map" type="Texture2D" default="null"> + <argument index="2" name="text" type="String"> </argument> - <argument index="3" name="specular_map" type="Texture2D" default="null"> + <argument index="3" name="align" type="int" enum="HAlign" default="0"> </argument> - <argument index="4" name="specular_shininess" type="Color" default="Color( 1, 1, 1, 1 )"> + <argument index="4" name="width" type="float" default="-1"> </argument> - <argument index="5" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0"> + <argument index="5" name="max_lines" type="int" default="-1"> </argument> - <argument index="6" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0"> + <argument index="6" name="size" type="int" default="-1"> + </argument> + <argument index="7" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> + </argument> + <argument index="8" name="outline_size" type="int" default="0"> + </argument> + <argument index="9" name="outline_modulate" type="Color" default="Color( 1, 1, 1, 0 )"> + </argument> + <argument index="10" name="flags" type="int" default="51"> + </argument> + <description> + Breaks [code]text[/code] to the lines and draws it using the specified [code]font[/code] at the [code]position[/code] (top-left corner). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width. + </description> + </method> + <method name="draw_multimesh"> + <return type="void"> + </return> + <argument index="0" name="multimesh" type="MultiMesh"> + </argument> + <argument index="1" name="texture" type="Texture2D"> </argument> <description> Draws a [MultiMesh] in 2D with the provided texture. See [MultiMeshInstance2D] for related documentation. @@ -196,16 +205,6 @@ </argument> <argument index="3" name="texture" type="Texture2D" default="null"> </argument> - <argument index="4" name="normal_map" type="Texture2D" default="null"> - </argument> - <argument index="5" name="specular_map" type="Texture2D" default="null"> - </argument> - <argument index="6" name="specular_shininess" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <argument index="7" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0"> - </argument> - <argument index="8" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0"> - </argument> <description> Draws a polygon of any amount of points, convex or concave. </description> @@ -219,6 +218,8 @@ </argument> <argument index="2" name="width" type="float" default="1.0"> </argument> + <argument index="3" name="antialiased" type="bool" default="false"> + </argument> <description> Draws interconnected line segments with a uniform [code]color[/code] and [code]width[/code]. </description> @@ -232,6 +233,8 @@ </argument> <argument index="2" name="width" type="float" default="1.0"> </argument> + <argument index="3" name="antialiased" type="bool" default="false"> + </argument> <description> Draws interconnected line segments with a uniform [code]width[/code] and segment-by-segment coloring. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code]. </description> @@ -249,16 +252,6 @@ </argument> <argument index="4" name="width" type="float" default="1.0"> </argument> - <argument index="5" name="normal_map" type="Texture2D" default="null"> - </argument> - <argument index="6" name="specular_map" type="Texture2D" default="null"> - </argument> - <argument index="7" name="specular_shininess" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <argument index="8" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0"> - </argument> - <argument index="9" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0"> - </argument> <description> Draws a custom primitive. 1 point for a point, 2 points for a line, 3 points for a triangle, and 4 points for a quad. </description> @@ -284,9 +277,9 @@ </return> <argument index="0" name="position" type="Vector2"> </argument> - <argument index="1" name="rotation" type="float"> + <argument index="1" name="rotation" type="float" default="0.0"> </argument> - <argument index="2" name="scale" type="Vector2"> + <argument index="2" name="scale" type="Vector2" default="Vector2( 1, 1 )"> </argument> <description> Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this. @@ -301,21 +294,51 @@ Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this. </description> </method> - <method name="draw_string"> + <method name="draw_string" qualifiers="const"> <return type="void"> </return> <argument index="0" name="font" type="Font"> </argument> - <argument index="1" name="position" type="Vector2"> + <argument index="1" name="pos" type="Vector2"> </argument> <argument index="2" name="text" type="String"> </argument> - <argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> + <argument index="3" name="align" type="int" enum="HAlign" default="0"> + </argument> + <argument index="4" name="width" type="float" default="-1"> + </argument> + <argument index="5" name="size" type="int" default="-1"> + </argument> + <argument index="6" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> </argument> - <argument index="4" name="clip_w" type="int" default="-1"> + <argument index="7" name="outline_size" type="int" default="0"> + </argument> + <argument index="8" name="outline_modulate" type="Color" default="Color( 1, 1, 1, 0 )"> + </argument> + <argument index="9" name="flags" type="int" default="3"> </argument> <description> - Draws a string using a custom font. + Draws [code]text[/code] using the specified [code]font[/code] at the [code]position[/code] (bottom-left corner using the baseline of the font). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width. + [b]Example using the default project font:[/b] + [codeblocks] + [gdscript] + # If using this method in a script that redraws constantly, move the + # `default_font` declaration to a member variable assigned in `_ready()` + # so the Control is only created once. + var default_font = Control.new().get_font("font") + var default_font_size = Control.new().get_font_size("font_size") + draw_string(default_font, Vector2(64, 64), "Hello world", HALIGN_LEFT, -1, font_size) + [/gdscript] + [csharp] + // If using this method in a script that redraws constantly, move the + // `default_font` declaration to a member variable assigned in `_ready()` + // so the Control is only created once. + Font defaultFont = new Control().GetFont("font"); + int defaultFontSize = new Control().GetFontSize("font_size"); + DrawString(defaultFont, new Vector2(64, 64), "Hello world", HALIGN_LEFT, -1, defaultFontSize); + [/csharp] + [/codeblocks] + See also [method Font.draw_string]. </description> </method> <method name="draw_style_box"> @@ -338,16 +361,6 @@ </argument> <argument index="2" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )"> </argument> - <argument index="3" name="normal_map" type="Texture2D" default="null"> - </argument> - <argument index="4" name="specular_map" type="Texture2D" default="null"> - </argument> - <argument index="5" name="specular_shininess" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <argument index="6" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0"> - </argument> - <argument index="7" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0"> - </argument> <description> Draws a texture at a given position. </description> @@ -365,16 +378,6 @@ </argument> <argument index="4" name="transpose" type="bool" default="false"> </argument> - <argument index="5" name="normal_map" type="Texture2D" default="null"> - </argument> - <argument index="6" name="specular_map" type="Texture2D" default="null"> - </argument> - <argument index="7" name="specular_shininess" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <argument index="8" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0"> - </argument> - <argument index="9" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0"> - </argument> <description> Draws a textured rectangle at a given position, optionally modulated by a color. If [code]transpose[/code] is [code]true[/code], the texture will have its X and Y coordinates swapped. </description> @@ -392,17 +395,7 @@ </argument> <argument index="4" name="transpose" type="bool" default="false"> </argument> - <argument index="5" name="normal_map" type="Texture2D" default="null"> - </argument> - <argument index="6" name="specular_map" type="Texture2D" default="null"> - </argument> - <argument index="7" name="specular_shininess" type="Color" default="Color( 1, 1, 1, 1 )"> - </argument> - <argument index="8" name="clip_uv" type="bool" default="true"> - </argument> - <argument index="9" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0"> - </argument> - <argument index="10" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0"> + <argument index="5" name="clip_uv" type="bool" default="true"> </argument> <description> Draws a textured rectangle region at a given position, optionally modulated by a color. If [code]transpose[/code] is [code]true[/code], the texture will have its X and Y coordinates swapped. @@ -506,13 +499,6 @@ Returns [code]true[/code] if local transform notifications are communicated to children. </description> </method> - <method name="is_set_as_toplevel" qualifiers="const"> - <return type="bool"> - </return> - <description> - Returns [code]true[/code] if the node is set as top-level. See [method set_as_toplevel]. - </description> - </method> <method name="is_transform_notification_enabled" qualifiers="const"> <return type="bool"> </return> @@ -524,7 +510,7 @@ <return type="bool"> </return> <description> - Returns [code]true[/code] if the node is present in the [SceneTree], its [member visible] property is [code]true[/code] and its inherited visibility is also [code]true[/code]. + Returns [code]true[/code] if the node is present in the [SceneTree], its [member visible] property is [code]true[/code] and all its antecedents are also visible. If any antecedent is hidden, this node will not be visible in the scene tree. </description> </method> <method name="make_canvas_position_local" qualifiers="const"> @@ -545,15 +531,6 @@ Transformations issued by [code]event[/code]'s inputs are applied in local space instead of global space. </description> </method> - <method name="set_as_toplevel"> - <return type="void"> - </return> - <argument index="0" name="enable" type="bool"> - </argument> - <description> - If [code]enable[/code] is [code]true[/code], the node won't inherit its transform from parent canvas items. - </description> - </method> <method name="set_notify_local_transform"> <return type="void"> </return> @@ -588,6 +565,8 @@ </method> </methods> <members> + <member name="clip_children" type="bool" setter="set_clip_children" getter="is_clipping_children" default="false"> + </member> <member name="light_mask" type="int" setter="set_light_mask" getter="get_light_mask" default="1"> The rendering layers in which this [CanvasItem] responds to [Light2D] nodes. </member> @@ -607,14 +586,20 @@ If [code]true[/code], the object draws on top of its parent. </member> <member name="texture_filter" type="int" setter="set_texture_filter" getter="get_texture_filter" enum="CanvasItem.TextureFilter" default="0"> + The texture filtering mode to use on this [CanvasItem]. </member> <member name="texture_repeat" type="int" setter="set_texture_repeat" getter="get_texture_repeat" enum="CanvasItem.TextureRepeat" default="0"> + The texture repeating mode to use on this [CanvasItem]. + </member> + <member name="top_level" type="bool" setter="set_as_top_level" getter="is_set_as_top_level" default="false"> + If [code]true[/code], the node will not inherit its transform from parent [CanvasItem]s. </member> <member name="use_parent_material" type="bool" setter="set_use_parent_material" getter="get_use_parent_material" default="false"> If [code]true[/code], the parent [CanvasItem]'s [member material] property is used as this one's material. </member> <member name="visible" type="bool" setter="set_visible" getter="is_visible" default="true"> - If [code]true[/code], this [CanvasItem] is drawn. For controls that inherit [Popup], the correct way to make them visible is to call one of the multiple [code]popup*()[/code] functions instead. + If [code]true[/code], this [CanvasItem] is drawn. The node is only visible if all of its antecedents are visible as well (in other words, [method is_visible_in_tree] must return [code]true[/code]). + [b]Note:[/b] For controls that inherit [Popup], the correct way to make them visible is to call one of the multiple [code]popup*()[/code] functions instead. </member> </members> <signals> @@ -623,14 +608,14 @@ Emitted when the [CanvasItem] must redraw. This can only be connected realtime, as deferred will not allow drawing. </description> </signal> - <signal name="hide"> + <signal name="hidden"> <description> Emitted when becoming hidden. </description> </signal> <signal name="item_rect_changed"> <description> - Emitted when the item rect has changed. + Emitted when the item's [Rect2] boundaries (position or size) have changed, or when an action is taking place that may have impacted these boundaries (e.g. changing [member Sprite2D.texture]). </description> </signal> <signal name="visibility_changed"> @@ -665,12 +650,18 @@ The texture filter blends between the nearest four pixels. Use this for most cases where you want to avoid a pixelated style. </constant> <constant name="TEXTURE_FILTER_NEAREST_WITH_MIPMAPS" value="3" enum="TextureFilter"> + The texture filter reads from the nearest pixel in the nearest mipmap. This is the fastest way to read from textures with mipmaps. </constant> <constant name="TEXTURE_FILTER_LINEAR_WITH_MIPMAPS" value="4" enum="TextureFilter"> + The texture filter blends between the nearest 4 pixels and between the nearest 2 mipmaps. Use this for non-pixel art textures that may be viewed at a low scale (e.g. due to [Camera2D] zoom), as mipmaps are important to smooth out pixels that are smaller than on-screen pixels. </constant> <constant name="TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC" value="5" enum="TextureFilter"> + The texture filter reads from the nearest pixel, but selects a mipmap based on the angle between the surface and the camera view. This reduces artifacts on surfaces that are almost in line with the camera. + [b]Note:[/b] This texture filter is rarely useful in 2D projects. [constant TEXTURE_FILTER_NEAREST_WITH_MIPMAPS] is usually more appropriate. </constant> <constant name="TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC" value="6" enum="TextureFilter"> + The texture filter blends between the nearest 4 pixels and selects a mipmap based on the angle between the surface and the camera view. This reduces artifacts on surfaces that are almost in line with the camera. This is the slowest of the filtering options, but results in the highest quality texturing. + [b]Note:[/b] This texture filter is rarely useful in 2D projects. [constant TEXTURE_FILTER_LINEAR_WITH_MIPMAPS] is usually more appropriate. </constant> <constant name="TEXTURE_FILTER_MAX" value="7" enum="TextureFilter"> Represents the size of the [enum TextureFilter] enum. |