mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Add methods to draw ellipses
This commit is contained in:
parent
9dde5688a5
commit
9f7c3d00dd
9 changed files with 114 additions and 40 deletions
|
@ -44,7 +44,7 @@
|
||||||
<param index="6" name="width" type="float" default="-1.0" />
|
<param index="6" name="width" type="float" default="-1.0" />
|
||||||
<param index="7" name="antialiased" type="bool" default="false" />
|
<param index="7" name="antialiased" type="bool" default="false" />
|
||||||
<description>
|
<description>
|
||||||
Draws an unfilled arc between the given angles with a uniform [param color] and [param width] and optional antialiasing (supported only for positive [param width]). The larger the value of [param point_count], the smoother the curve. [param center] is defined in local space. See also [method draw_circle].
|
Draws an unfilled arc between the given angles with a uniform [param color] and [param width] and optional antialiasing (supported only for positive [param width]). The larger the value of [param point_count], the smoother the curve. [param center] is defined in local space. For elliptical arcs, see [method draw_ellipse_arc]. See also [method draw_circle].
|
||||||
If [param width] is negative, it will be ignored and the arc will be drawn using [constant RenderingServer.PRIMITIVE_LINE_STRIP]. This means that when the CanvasItem is scaled, the arc will remain thin. If this behavior is not desired, then pass a positive [param width] like [code]1.0[/code].
|
If [param width] is negative, it will be ignored and the arc will be drawn using [constant RenderingServer.PRIMITIVE_LINE_STRIP]. This means that when the CanvasItem is scaled, the arc will remain thin. If this behavior is not desired, then pass a positive [param width] like [code]1.0[/code].
|
||||||
The arc is drawn from [param start_angle] towards the value of [param end_angle] so in clockwise direction if [code]start_angle < end_angle[/code] and counter-clockwise otherwise. Passing the same angles but in reversed order will produce the same arc. If absolute difference of [param start_angle] and [param end_angle] is greater than [constant @GDScript.TAU] radians, then a full circle arc is drawn (i.e. arc will not overlap itself).
|
The arc is drawn from [param start_angle] towards the value of [param end_angle] so in clockwise direction if [code]start_angle < end_angle[/code] and counter-clockwise otherwise. Passing the same angles but in reversed order will produce the same arc. If absolute difference of [param start_angle] and [param end_angle] is greater than [constant @GDScript.TAU] radians, then a full circle arc is drawn (i.e. arc will not overlap itself).
|
||||||
</description>
|
</description>
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
<param index="4" name="width" type="float" default="-1.0" />
|
<param index="4" name="width" type="float" default="-1.0" />
|
||||||
<param index="5" name="antialiased" type="bool" default="false" />
|
<param index="5" name="antialiased" type="bool" default="false" />
|
||||||
<description>
|
<description>
|
||||||
Draws a circle, with [param position] defined in local space. See also [method draw_arc], [method draw_polyline], and [method draw_polygon].
|
Draws a circle, with [param position] defined in local space. See also [method draw_ellipse], [method draw_arc], [method draw_polyline], and [method draw_polygon].
|
||||||
If [param filled] is [code]true[/code], the circle will be filled with the [param color] specified. If [param filled] is [code]false[/code], the circle will be drawn as a stroke with the [param color] and [param width] specified.
|
If [param filled] is [code]true[/code], the circle will be filled with the [param color] specified. If [param filled] is [code]false[/code], the circle will be drawn as a stroke with the [param color] and [param width] specified.
|
||||||
If [param width] is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive [param width] like [code]1.0[/code].
|
If [param width] is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive [param width] like [code]1.0[/code].
|
||||||
If [param antialiased] is [code]true[/code], half transparent "feathers" will be attached to the boundary, making outlines smooth.
|
If [param antialiased] is [code]true[/code], half transparent "feathers" will be attached to the boundary, making outlines smooth.
|
||||||
|
@ -118,6 +118,40 @@
|
||||||
[b]Note:[/b] [param antialiased] is only effective if [param width] is greater than [code]0.0[/code].
|
[b]Note:[/b] [param antialiased] is only effective if [param width] is greater than [code]0.0[/code].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="draw_ellipse">
|
||||||
|
<return type="void" />
|
||||||
|
<param index="0" name="position" type="Vector2" />
|
||||||
|
<param index="1" name="major" type="float" />
|
||||||
|
<param index="2" name="minor" type="float" />
|
||||||
|
<param index="3" name="color" type="Color" />
|
||||||
|
<param index="4" name="filled" type="bool" default="true" />
|
||||||
|
<param index="5" name="width" type="float" default="-1.0" />
|
||||||
|
<param index="6" name="antialiased" type="bool" default="false" />
|
||||||
|
<description>
|
||||||
|
Draws an ellipse with semi-major axis [param major] and semi-minor axis [param minor]. See also [method draw_circle], [method draw_ellipse_arc], [method draw_polyline], and [method draw_polygon].
|
||||||
|
If [param filled] is [code]true[/code], the ellipse will be filled with the [param color] specified. If [param filled] is [code]false[/code], the ellipse will be drawn as a stroke with the [param color] and [param width] specified.
|
||||||
|
If [param width] is negative, then two-point primitives will be drawn instead of four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive [param width] like [code]1.0[/code].
|
||||||
|
If [param antialiased] is [code]true[/code], half transparent "feathers" will be attached to the boundary, making outlines smooth.
|
||||||
|
[b]Note:[/b] [param width] is only effective if [param filled] is [code]false[/code].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="draw_ellipse_arc">
|
||||||
|
<return type="void" />
|
||||||
|
<param index="0" name="center" type="Vector2" />
|
||||||
|
<param index="1" name="major" type="float" />
|
||||||
|
<param index="2" name="minor" type="float" />
|
||||||
|
<param index="3" name="start_angle" type="float" />
|
||||||
|
<param index="4" name="end_angle" type="float" />
|
||||||
|
<param index="5" name="point_count" type="int" />
|
||||||
|
<param index="6" name="color" type="Color" />
|
||||||
|
<param index="7" name="width" type="float" default="-1.0" />
|
||||||
|
<param index="8" name="antialiased" type="bool" default="false" />
|
||||||
|
<description>
|
||||||
|
Draws an unfilled elliptical arc between the given angles with a uniform [param color] and [param width] and optional antialiasing (supported only for positive [param width]). The larger the value of [param point_count], the smoother the curve. For circular arcs, see [method draw_arc]. See also [method draw_ellipse].
|
||||||
|
If [param width] is negative, it will be ignored and the arc will be drawn using [constant RenderingServer.PRIMITIVE_LINE_STRIP]. This means that when the CanvasItem is scaled, the arc will remain thin. If this behavior is not desired, then pass a positive [param width] like [code]1.0[/code].
|
||||||
|
The arc is drawn from [param start_angle] towards the value of [param end_angle] so in clockwise direction if [code]start_angle < end_angle[/code] and counter-clockwise otherwise. Passing the same angles but in reversed order will produce the same arc. If absolute difference of [param start_angle] and [param end_angle] is greater than [constant @GDScript.TAU] radians, then a full ellipse is drawn (i.e. arc will not overlap itself).
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="draw_end_animation">
|
<method name="draw_end_animation">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -227,6 +227,18 @@
|
||||||
If [param ignore] is [code]true[/code], ignore clipping on items drawn with this canvas item until this is called again with [param ignore] set to [code]false[/code].
|
If [param ignore] is [code]true[/code], ignore clipping on items drawn with this canvas item until this is called again with [param ignore] set to [code]false[/code].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="canvas_item_add_ellipse">
|
||||||
|
<return type="void" />
|
||||||
|
<param index="0" name="item" type="RID" />
|
||||||
|
<param index="1" name="pos" type="Vector2" />
|
||||||
|
<param index="2" name="major" type="float" />
|
||||||
|
<param index="3" name="minor" type="float" />
|
||||||
|
<param index="4" name="color" type="Color" />
|
||||||
|
<param index="5" name="antialiased" type="bool" default="false" />
|
||||||
|
<description>
|
||||||
|
Draws an ellipse with semi-major axis [param major] and semi-minor axis [param minor] on the [CanvasItem] pointed to by the [param item] [RID]. See also [method CanvasItem.draw_ellipse].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="canvas_item_add_lcd_texture_rect_region">
|
<method name="canvas_item_add_lcd_texture_rect_region">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<param index="0" name="item" type="RID" />
|
<param index="0" name="item" type="RID" />
|
||||||
|
|
|
@ -776,8 +776,10 @@ void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vect
|
||||||
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width, p_antialiased);
|
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width, p_antialiased);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasItem::draw_arc(const Vector2 &p_center, real_t p_radius, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width, bool p_antialiased) {
|
void CanvasItem::draw_ellipse_arc(const Vector2 &p_center, real_t p_major, real_t p_minor, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width, bool p_antialiased) {
|
||||||
ERR_THREAD_GUARD;
|
ERR_THREAD_GUARD;
|
||||||
|
ERR_DRAW_GUARD;
|
||||||
|
|
||||||
Vector<Point2> points;
|
Vector<Point2> points;
|
||||||
points.resize(p_point_count);
|
points.resize(p_point_count);
|
||||||
Point2 *points_ptr = points.ptrw();
|
Point2 *points_ptr = points.ptrw();
|
||||||
|
@ -786,12 +788,19 @@ void CanvasItem::draw_arc(const Vector2 &p_center, real_t p_radius, real_t p_sta
|
||||||
const real_t delta_angle = CLAMP(p_end_angle - p_start_angle, -Math::TAU, Math::TAU);
|
const real_t delta_angle = CLAMP(p_end_angle - p_start_angle, -Math::TAU, Math::TAU);
|
||||||
for (int i = 0; i < p_point_count; i++) {
|
for (int i = 0; i < p_point_count; i++) {
|
||||||
real_t theta = (i / (p_point_count - 1.0f)) * delta_angle + p_start_angle;
|
real_t theta = (i / (p_point_count - 1.0f)) * delta_angle + p_start_angle;
|
||||||
points_ptr[i] = p_center + Vector2(Math::cos(theta), Math::sin(theta)) * p_radius;
|
points_ptr[i] = p_center + Vector2(p_major * Math::cos(theta), p_minor * Math::sin(theta));
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_polyline(points, p_color, p_width, p_antialiased);
|
draw_polyline(points, p_color, p_width, p_antialiased);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CanvasItem::draw_arc(const Vector2 &p_center, real_t p_radius, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width, bool p_antialiased) {
|
||||||
|
ERR_THREAD_GUARD;
|
||||||
|
ERR_DRAW_GUARD;
|
||||||
|
|
||||||
|
draw_ellipse_arc(p_center, p_radius, p_radius, p_start_angle, p_end_angle, p_point_count, p_color, p_width, p_antialiased);
|
||||||
|
}
|
||||||
|
|
||||||
void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width, bool p_antialiased) {
|
void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width, bool p_antialiased) {
|
||||||
ERR_THREAD_GUARD;
|
ERR_THREAD_GUARD;
|
||||||
ERR_DRAW_GUARD;
|
ERR_DRAW_GUARD;
|
||||||
|
@ -836,18 +845,18 @@ void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_fil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color, bool p_filled, real_t p_width, bool p_antialiased) {
|
void CanvasItem::draw_ellipse(const Point2 &p_pos, real_t p_major, real_t p_minor, const Color &p_color, bool p_filled, real_t p_width, bool p_antialiased) {
|
||||||
ERR_THREAD_GUARD;
|
ERR_THREAD_GUARD;
|
||||||
ERR_DRAW_GUARD;
|
ERR_DRAW_GUARD;
|
||||||
|
|
||||||
if (p_filled) {
|
if (p_filled) {
|
||||||
if (p_width != -1.0) {
|
if (p_width != -1.0) {
|
||||||
WARN_PRINT("The draw_circle() \"width\" argument has no effect when \"filled\" is \"true\".");
|
WARN_PRINT("The \"width\" argument has no effect when \"filled\" is \"true\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color, p_antialiased);
|
RenderingServer::get_singleton()->canvas_item_add_ellipse(canvas_item, p_pos, p_major, p_minor, p_color, p_antialiased);
|
||||||
} else if (p_width >= 2.0 * p_radius) {
|
} else if (p_width >= 2.0 * MAX(p_major, p_minor)) {
|
||||||
RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius + 0.5 * p_width, p_color, p_antialiased);
|
RenderingServer::get_singleton()->canvas_item_add_ellipse(canvas_item, p_pos, p_major + 0.5 * p_width, p_minor + 0.5 * p_width, p_color, p_antialiased);
|
||||||
} else {
|
} else {
|
||||||
// Tessellation count is hardcoded. Keep in sync with the same variable in `RendererCanvasCull::canvas_item_add_circle()`.
|
// Tessellation count is hardcoded. Keep in sync with the same variable in `RendererCanvasCull::canvas_item_add_circle()`.
|
||||||
const int circle_segments = 64;
|
const int circle_segments = 64;
|
||||||
|
@ -860,8 +869,8 @@ void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &
|
||||||
|
|
||||||
for (int i = 0; i < circle_segments; i++) {
|
for (int i = 0; i < circle_segments; i++) {
|
||||||
float angle = i * circle_point_step;
|
float angle = i * circle_point_step;
|
||||||
points_ptr[i].x = Math::cos(angle) * p_radius;
|
points_ptr[i].x = Math::cos(angle) * p_major;
|
||||||
points_ptr[i].y = Math::sin(angle) * p_radius;
|
points_ptr[i].y = Math::sin(angle) * p_minor;
|
||||||
points_ptr[i] += p_pos;
|
points_ptr[i] += p_pos;
|
||||||
}
|
}
|
||||||
points_ptr[circle_segments] = points_ptr[0];
|
points_ptr[circle_segments] = points_ptr[0];
|
||||||
|
@ -872,6 +881,13 @@ void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color, bool p_filled, real_t p_width, bool p_antialiased) {
|
||||||
|
ERR_THREAD_GUARD;
|
||||||
|
ERR_DRAW_GUARD;
|
||||||
|
|
||||||
|
draw_ellipse(p_pos, p_radius, p_radius, p_color, p_filled, p_width, p_antialiased);
|
||||||
|
}
|
||||||
|
|
||||||
void CanvasItem::draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate) {
|
void CanvasItem::draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate) {
|
||||||
ERR_THREAD_GUARD;
|
ERR_THREAD_GUARD;
|
||||||
ERR_DRAW_GUARD;
|
ERR_DRAW_GUARD;
|
||||||
|
@ -1378,11 +1394,13 @@ void CanvasItem::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("draw_dashed_line", "from", "to", "color", "width", "dash", "aligned", "antialiased"), &CanvasItem::draw_dashed_line, DEFVAL(-1.0), DEFVAL(2.0), DEFVAL(true), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_dashed_line", "from", "to", "color", "width", "dash", "aligned", "antialiased"), &CanvasItem::draw_dashed_line, DEFVAL(-1.0), DEFVAL(2.0), DEFVAL(true), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_polyline", "points", "color", "width", "antialiased"), &CanvasItem::draw_polyline, DEFVAL(-1.0), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_polyline", "points", "color", "width", "antialiased"), &CanvasItem::draw_polyline, DEFVAL(-1.0), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_polyline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_polyline_colors, DEFVAL(-1.0), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_polyline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_polyline_colors, DEFVAL(-1.0), DEFVAL(false));
|
||||||
|
ClassDB::bind_method(D_METHOD("draw_ellipse_arc", "center", "major", "minor", "start_angle", "end_angle", "point_count", "color", "width", "antialiased"), &CanvasItem::draw_ellipse_arc, DEFVAL(-1.0), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_arc", "center", "radius", "start_angle", "end_angle", "point_count", "color", "width", "antialiased"), &CanvasItem::draw_arc, DEFVAL(-1.0), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_arc", "center", "radius", "start_angle", "end_angle", "point_count", "color", "width", "antialiased"), &CanvasItem::draw_arc, DEFVAL(-1.0), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_multiline", "points", "color", "width", "antialiased"), &CanvasItem::draw_multiline, DEFVAL(-1.0), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_multiline", "points", "color", "width", "antialiased"), &CanvasItem::draw_multiline, DEFVAL(-1.0), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_multiline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_multiline_colors, DEFVAL(-1.0), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_multiline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_multiline_colors, DEFVAL(-1.0), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled", "width", "antialiased"), &CanvasItem::draw_rect, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled", "width", "antialiased"), &CanvasItem::draw_rect, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color", "filled", "width", "antialiased"), &CanvasItem::draw_circle, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color", "filled", "width", "antialiased"), &CanvasItem::draw_circle, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false));
|
||||||
|
ClassDB::bind_method(D_METHOD("draw_ellipse", "position", "major", "minor", "color", "filled", "width", "antialiased"), &CanvasItem::draw_ellipse, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_texture", "texture", "position", "modulate"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)));
|
ClassDB::bind_method(D_METHOD("draw_texture", "texture", "position", "modulate"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)));
|
||||||
ClassDB::bind_method(D_METHOD("draw_texture_rect", "texture", "rect", "tile", "modulate", "transpose"), &CanvasItem::draw_texture_rect, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_texture_rect", "texture", "rect", "tile", "modulate", "transpose"), &CanvasItem::draw_texture_rect, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_texture_rect_region", "texture", "rect", "src_rect", "modulate", "transpose", "clip_uv"), &CanvasItem::draw_texture_rect_region, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false), DEFVAL(true));
|
ClassDB::bind_method(D_METHOD("draw_texture_rect_region", "texture", "rect", "src_rect", "modulate", "transpose", "clip_uv"), &CanvasItem::draw_texture_rect_region, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false), DEFVAL(true));
|
||||||
|
|
|
@ -304,10 +304,12 @@ public:
|
||||||
void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0, bool p_antialiased = false);
|
void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
|
void draw_ellipse_arc(const Vector2 &p_center, real_t p_major, real_t p_minor, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
void draw_arc(const Vector2 &p_center, real_t p_radius, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
void draw_arc(const Vector2 &p_center, real_t p_radius, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
void draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
void draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
void draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0, bool p_antialiased = false);
|
void draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
void draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled = true, real_t p_width = -1.0, bool p_antialiased = false);
|
void draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled = true, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
|
void draw_ellipse(const Point2 &p_pos, real_t p_major, real_t p_minor, const Color &p_color, bool p_filled = true, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
void draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color, bool p_filled = true, real_t p_width = -1.0, bool p_antialiased = false);
|
void draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color, bool p_filled = true, real_t p_width = -1.0, bool p_antialiased = false);
|
||||||
void draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1));
|
void draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1));
|
||||||
void draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
|
void draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
|
||||||
|
|
|
@ -1419,56 +1419,56 @@ void RendererCanvasCull::canvas_item_add_rect(RID p_item, const Rect2 &p_rect, c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererCanvasCull::canvas_item_add_circle(RID p_item, const Point2 &p_pos, float p_radius, const Color &p_color, bool p_antialiased) {
|
void RendererCanvasCull::canvas_item_add_ellipse(RID p_item, const Point2 &p_pos, float p_major, float p_minor, const Color &p_color, bool p_antialiased) {
|
||||||
Item *canvas_item = canvas_item_owner.get_or_null(p_item);
|
Item *canvas_item = canvas_item_owner.get_or_null(p_item);
|
||||||
ERR_FAIL_NULL(canvas_item);
|
ERR_FAIL_NULL(canvas_item);
|
||||||
|
|
||||||
static const int circle_segments = 64;
|
static const int ellipse_segments = 64;
|
||||||
|
|
||||||
{
|
{
|
||||||
Item::CommandPolygon *circle = canvas_item->alloc_command<Item::CommandPolygon>();
|
Item::CommandPolygon *ellipse = canvas_item->alloc_command<Item::CommandPolygon>();
|
||||||
ERR_FAIL_NULL(circle);
|
ERR_FAIL_NULL(ellipse);
|
||||||
|
|
||||||
circle->primitive = RS::PRIMITIVE_TRIANGLES;
|
ellipse->primitive = RS::PRIMITIVE_TRIANGLES;
|
||||||
|
|
||||||
Vector<int> indices;
|
Vector<int> indices;
|
||||||
Vector<Vector2> points;
|
Vector<Vector2> points;
|
||||||
|
|
||||||
points.resize(circle_segments + 2);
|
points.resize(ellipse_segments + 2);
|
||||||
Vector2 *points_ptr = points.ptrw();
|
Vector2 *points_ptr = points.ptrw();
|
||||||
|
|
||||||
// Store circle center in the last point.
|
// Store ellipse center in the last point.
|
||||||
points_ptr[circle_segments + 1] = p_pos;
|
points_ptr[ellipse_segments + 1] = p_pos;
|
||||||
|
|
||||||
const real_t circle_point_step = Math::TAU / circle_segments;
|
const real_t ellipse_point_step = Math::TAU / ellipse_segments;
|
||||||
|
|
||||||
for (int i = 0; i < circle_segments + 1; i++) {
|
for (int i = 0; i < ellipse_segments + 1; i++) {
|
||||||
float angle = i * circle_point_step;
|
float angle = i * ellipse_point_step;
|
||||||
points_ptr[i].x = Math::cos(angle) * p_radius;
|
points_ptr[i].x = Math::cos(angle) * p_major;
|
||||||
points_ptr[i].y = Math::sin(angle) * p_radius;
|
points_ptr[i].y = Math::sin(angle) * p_minor;
|
||||||
points_ptr[i] += p_pos;
|
points_ptr[i] += p_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
indices.resize(circle_segments * 3);
|
indices.resize(ellipse_segments * 3);
|
||||||
int *indices_ptr = indices.ptrw();
|
int *indices_ptr = indices.ptrw();
|
||||||
|
|
||||||
for (int i = 0; i < circle_segments; i++) {
|
for (int i = 0; i < ellipse_segments; i++) {
|
||||||
indices_ptr[i * 3 + 0] = circle_segments + 1;
|
indices_ptr[i * 3 + 0] = ellipse_segments + 1;
|
||||||
indices_ptr[i * 3 + 1] = i;
|
indices_ptr[i * 3 + 1] = i;
|
||||||
indices_ptr[i * 3 + 2] = i + 1;
|
indices_ptr[i * 3 + 2] = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Color> color;
|
Vector<Color> color;
|
||||||
color.push_back(p_color);
|
color.push_back(p_color);
|
||||||
circle->polygon.create(indices, points, color);
|
ellipse->polygon.create(indices, points, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_antialiased) {
|
if (p_antialiased) {
|
||||||
float border_size = FEATHER_SIZE;
|
float border_size = FEATHER_SIZE;
|
||||||
|
|
||||||
const float diameter = p_radius * 2.0f;
|
const float max_axis = fmax(p_major, p_minor) * 2.0f;
|
||||||
if (0.0f <= diameter && diameter < 1.0f) {
|
if (0.0f <= max_axis && max_axis < 1.0f) {
|
||||||
border_size *= p_radius;
|
border_size *= max_axis * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::CommandPolygon *feather = canvas_item->alloc_command<Item::CommandPolygon>();
|
Item::CommandPolygon *feather = canvas_item->alloc_command<Item::CommandPolygon>();
|
||||||
|
@ -1481,25 +1481,25 @@ void RendererCanvasCull::canvas_item_add_circle(RID p_item, const Point2 &p_pos,
|
||||||
Vector<Color> colors;
|
Vector<Color> colors;
|
||||||
Vector<Vector2> points;
|
Vector<Vector2> points;
|
||||||
|
|
||||||
points.resize(2 * circle_segments + 2);
|
points.resize(2 * ellipse_segments + 2);
|
||||||
colors.resize(2 * circle_segments + 2);
|
colors.resize(2 * ellipse_segments + 2);
|
||||||
|
|
||||||
const real_t circle_point_step = Math::TAU / circle_segments;
|
const real_t ellipse_point_step = Math::TAU / ellipse_segments;
|
||||||
|
|
||||||
Vector2 *points_ptr = points.ptrw();
|
Vector2 *points_ptr = points.ptrw();
|
||||||
Color *colors_ptr = colors.ptrw();
|
Color *colors_ptr = colors.ptrw();
|
||||||
|
|
||||||
for (int i = 0; i < circle_segments + 1; i++) {
|
for (int i = 0; i < ellipse_segments + 1; i++) {
|
||||||
const float angle = i * circle_point_step;
|
const float angle = i * ellipse_point_step;
|
||||||
const float c = Math::cos(angle);
|
const float c = Math::cos(angle);
|
||||||
const float s = Math::sin(angle);
|
const float s = Math::sin(angle);
|
||||||
|
|
||||||
points_ptr[i * 2].x = c * p_radius;
|
points_ptr[i * 2].x = c * p_major;
|
||||||
points_ptr[i * 2].y = s * p_radius;
|
points_ptr[i * 2].y = s * p_minor;
|
||||||
points_ptr[i * 2] += p_pos;
|
points_ptr[i * 2] += p_pos;
|
||||||
|
|
||||||
points_ptr[i * 2 + 1].x = c * (p_radius + border_size);
|
points_ptr[i * 2 + 1].x = c * (p_major + border_size);
|
||||||
points_ptr[i * 2 + 1].y = s * (p_radius + border_size);
|
points_ptr[i * 2 + 1].y = s * (p_minor + border_size);
|
||||||
points_ptr[i * 2 + 1] += p_pos;
|
points_ptr[i * 2 + 1] += p_pos;
|
||||||
|
|
||||||
colors_ptr[i * 2] = p_color;
|
colors_ptr[i * 2] = p_color;
|
||||||
|
@ -1510,6 +1510,10 @@ void RendererCanvasCull::canvas_item_add_circle(RID p_item, const Point2 &p_pos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RendererCanvasCull::canvas_item_add_circle(RID p_item, const Point2 &p_pos, float p_radius, const Color &p_color, bool p_antialiased) {
|
||||||
|
canvas_item_add_ellipse(p_item, p_pos, p_radius, p_radius, p_color, p_antialiased);
|
||||||
|
}
|
||||||
|
|
||||||
void RendererCanvasCull::canvas_item_add_texture_rect(RID p_item, const Rect2 &p_rect, RID p_texture, bool p_tile, const Color &p_modulate, bool p_transpose) {
|
void RendererCanvasCull::canvas_item_add_texture_rect(RID p_item, const Rect2 &p_rect, RID p_texture, bool p_tile, const Color &p_modulate, bool p_transpose) {
|
||||||
Item *canvas_item = canvas_item_owner.get_or_null(p_item);
|
Item *canvas_item = canvas_item_owner.get_or_null(p_item);
|
||||||
ERR_FAIL_NULL(canvas_item);
|
ERR_FAIL_NULL(canvas_item);
|
||||||
|
|
|
@ -259,6 +259,7 @@ public:
|
||||||
void canvas_item_add_polyline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = -1.0, bool p_antialiased = false);
|
void canvas_item_add_polyline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = -1.0, bool p_antialiased = false);
|
||||||
void canvas_item_add_multiline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = -1.0, bool p_antialiased = false);
|
void canvas_item_add_multiline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = -1.0, bool p_antialiased = false);
|
||||||
void canvas_item_add_rect(RID p_item, const Rect2 &p_rect, const Color &p_color, bool p_antialiased);
|
void canvas_item_add_rect(RID p_item, const Rect2 &p_rect, const Color &p_color, bool p_antialiased);
|
||||||
|
void canvas_item_add_ellipse(RID p_item, const Point2 &p_pos, float p_major, float p_minor, const Color &p_color, bool p_antialiased = false);
|
||||||
void canvas_item_add_circle(RID p_item, const Point2 &p_pos, float p_radius, const Color &p_color, bool p_antialiased);
|
void canvas_item_add_circle(RID p_item, const Point2 &p_pos, float p_radius, const Color &p_color, bool p_antialiased);
|
||||||
void canvas_item_add_texture_rect(RID p_item, const Rect2 &p_rect, RID p_texture, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
|
void canvas_item_add_texture_rect(RID p_item, const Rect2 &p_rect, RID p_texture, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
|
||||||
void canvas_item_add_texture_rect_region(RID p_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = false);
|
void canvas_item_add_texture_rect_region(RID p_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = false);
|
||||||
|
|
|
@ -982,6 +982,7 @@ public:
|
||||||
FUNC5(canvas_item_add_polyline, RID, const Vector<Point2> &, const Vector<Color> &, float, bool)
|
FUNC5(canvas_item_add_polyline, RID, const Vector<Point2> &, const Vector<Color> &, float, bool)
|
||||||
FUNC5(canvas_item_add_multiline, RID, const Vector<Point2> &, const Vector<Color> &, float, bool)
|
FUNC5(canvas_item_add_multiline, RID, const Vector<Point2> &, const Vector<Color> &, float, bool)
|
||||||
FUNC4(canvas_item_add_rect, RID, const Rect2 &, const Color &, bool)
|
FUNC4(canvas_item_add_rect, RID, const Rect2 &, const Color &, bool)
|
||||||
|
FUNC6(canvas_item_add_ellipse, RID, const Point2 &, float, float, const Color &, bool)
|
||||||
FUNC5(canvas_item_add_circle, RID, const Point2 &, float, const Color &, bool)
|
FUNC5(canvas_item_add_circle, RID, const Point2 &, float, const Color &, bool)
|
||||||
FUNC6(canvas_item_add_texture_rect, RID, const Rect2 &, RID, bool, const Color &, bool)
|
FUNC6(canvas_item_add_texture_rect, RID, const Rect2 &, RID, bool, const Color &, bool)
|
||||||
FUNC7(canvas_item_add_texture_rect_region, RID, const Rect2 &, RID, const Rect2 &, const Color &, bool, bool)
|
FUNC7(canvas_item_add_texture_rect_region, RID, const Rect2 &, RID, const Rect2 &, const Color &, bool, bool)
|
||||||
|
|
|
@ -3304,6 +3304,7 @@ void RenderingServer::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_multiline", "item", "points", "colors", "width", "antialiased"), &RenderingServer::canvas_item_add_multiline, DEFVAL(-1.0), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_multiline", "item", "points", "colors", "width", "antialiased"), &RenderingServer::canvas_item_add_multiline, DEFVAL(-1.0), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_rect", "item", "rect", "color", "antialiased"), &RenderingServer::canvas_item_add_rect, DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_rect", "item", "rect", "color", "antialiased"), &RenderingServer::canvas_item_add_rect, DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_circle", "item", "pos", "radius", "color", "antialiased"), &RenderingServer::canvas_item_add_circle, DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_circle", "item", "pos", "radius", "color", "antialiased"), &RenderingServer::canvas_item_add_circle, DEFVAL(false));
|
||||||
|
ClassDB::bind_method(D_METHOD("canvas_item_add_ellipse", "item", "pos", "major", "minor", "color", "antialiased"), &RenderingServer::canvas_item_add_ellipse, DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect", "item", "rect", "texture", "tile", "modulate", "transpose"), &RenderingServer::canvas_item_add_texture_rect, DEFVAL(false), DEFVAL(Color(1, 1, 1)), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect", "item", "rect", "texture", "tile", "modulate", "transpose"), &RenderingServer::canvas_item_add_texture_rect, DEFVAL(false), DEFVAL(Color(1, 1, 1)), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_msdf_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate", "outline_size", "px_range", "scale"), &RenderingServer::canvas_item_add_msdf_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(1.0), DEFVAL(1.0));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_msdf_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate", "outline_size", "px_range", "scale"), &RenderingServer::canvas_item_add_msdf_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(1.0), DEFVAL(1.0));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_lcd_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate"), &RenderingServer::canvas_item_add_lcd_texture_rect_region);
|
ClassDB::bind_method(D_METHOD("canvas_item_add_lcd_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate"), &RenderingServer::canvas_item_add_lcd_texture_rect_region);
|
||||||
|
|
|
@ -1579,6 +1579,7 @@ public:
|
||||||
virtual void canvas_item_add_polyline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = -1.0, bool p_antialiased = false) = 0;
|
virtual void canvas_item_add_polyline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = -1.0, bool p_antialiased = false) = 0;
|
||||||
virtual void canvas_item_add_multiline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = -1.0, bool p_antialiased = false) = 0;
|
virtual void canvas_item_add_multiline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = -1.0, bool p_antialiased = false) = 0;
|
||||||
virtual void canvas_item_add_rect(RID p_item, const Rect2 &p_rect, const Color &p_color, bool p_antialiased = false) = 0;
|
virtual void canvas_item_add_rect(RID p_item, const Rect2 &p_rect, const Color &p_color, bool p_antialiased = false) = 0;
|
||||||
|
virtual void canvas_item_add_ellipse(RID p_item, const Point2 &p_pos, float p_major, float p_minor, const Color &p_color, bool p_antialiased = false) = 0;
|
||||||
virtual void canvas_item_add_circle(RID p_item, const Point2 &p_pos, float p_radius, const Color &p_color, bool p_antialiased = false) = 0;
|
virtual void canvas_item_add_circle(RID p_item, const Point2 &p_pos, float p_radius, const Color &p_color, bool p_antialiased = false) = 0;
|
||||||
virtual void canvas_item_add_texture_rect(RID p_item, const Rect2 &p_rect, RID p_texture, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) = 0;
|
virtual void canvas_item_add_texture_rect(RID p_item, const Rect2 &p_rect, RID p_texture, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) = 0;
|
||||||
virtual void canvas_item_add_texture_rect_region(RID p_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = false) = 0;
|
virtual void canvas_item_add_texture_rect_region(RID p_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = false) = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue