|
29 | 29 | /**************************************************************************/ |
30 | 30 |
|
31 | 31 | #include "canvas_item.h" |
| 32 | +#include "canvas_item.compat.inc" |
32 | 33 |
|
33 | 34 | #include "scene/2d/canvas_group.h" |
34 | 35 | #include "scene/main/canvas_layer.h" |
@@ -726,11 +727,40 @@ void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_fil |
726 | 727 | } |
727 | 728 | } |
728 | 729 |
|
729 | | -void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color) { |
| 730 | +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) { |
730 | 731 | ERR_THREAD_GUARD; |
731 | 732 | ERR_DRAW_GUARD; |
732 | 733 |
|
733 | | - RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color); |
| 734 | + if (p_filled) { |
| 735 | + if (p_width != -1.0) { |
| 736 | + WARN_PRINT("The draw_circle() \"width\" argument has no effect when \"filled\" is \"true\"."); |
| 737 | + } |
| 738 | + |
| 739 | + RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color); |
| 740 | + } else if (p_width >= 2.0 * p_radius) { |
| 741 | + RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius + 0.5 * p_width, p_color); |
| 742 | + } else { |
| 743 | + // Tessellation count is hardcoded. Keep in sync with the same variable in `RendererCanvasCull::canvas_item_add_circle()`. |
| 744 | + const int circle_segments = 64; |
| 745 | + |
| 746 | + Vector<Vector2> points; |
| 747 | + points.resize(circle_segments + 1); |
| 748 | + |
| 749 | + Vector2 *points_ptr = points.ptrw(); |
| 750 | + const real_t circle_point_step = Math_TAU / circle_segments; |
| 751 | + |
| 752 | + for (int i = 0; i < circle_segments; i++) { |
| 753 | + float angle = i * circle_point_step; |
| 754 | + points_ptr[i].x = Math::cos(angle) * p_radius; |
| 755 | + points_ptr[i].y = Math::sin(angle) * p_radius; |
| 756 | + points_ptr[i] += p_pos; |
| 757 | + } |
| 758 | + points_ptr[circle_segments] = points_ptr[0]; |
| 759 | + |
| 760 | + Vector<Color> colors = { p_color }; |
| 761 | + |
| 762 | + RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, points, colors, p_width, p_antialiased); |
| 763 | + } |
734 | 764 | } |
735 | 765 |
|
736 | 766 | void CanvasItem::draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate) { |
@@ -1163,7 +1193,7 @@ void CanvasItem::_bind_methods() { |
1163 | 1193 | ClassDB::bind_method(D_METHOD("draw_multiline", "points", "color", "width"), &CanvasItem::draw_multiline, DEFVAL(-1.0)); |
1164 | 1194 | ClassDB::bind_method(D_METHOD("draw_multiline_colors", "points", "colors", "width"), &CanvasItem::draw_multiline_colors, DEFVAL(-1.0)); |
1165 | 1195 | ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled", "width"), &CanvasItem::draw_rect, DEFVAL(true), DEFVAL(-1.0)); |
1166 | | - ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color"), &CanvasItem::draw_circle); |
| 1196 | + ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color", "filled", "width", "antialiased"), &CanvasItem::draw_circle, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false)); |
1167 | 1197 | ClassDB::bind_method(D_METHOD("draw_texture", "texture", "position", "modulate"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1))); |
1168 | 1198 | 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)); |
1169 | 1199 | 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)); |
|
0 commit comments