diff --git a/Extensions/PrimitiveDrawing/Extension.cpp b/Extensions/PrimitiveDrawing/Extension.cpp index 5c2c075b4fa2..a158b90b636b 100644 --- a/Extensions/PrimitiveDrawing/Extension.cpp +++ b/Extensions/PrimitiveDrawing/Extension.cpp @@ -158,6 +158,28 @@ void DeclarePrimitiveDrawingExtension(gd::PlatformExtension& extension) { .AddParameter("expression", _("Bottom Y position")) .AddParameter("expression", _("Chamfer (in pixels)")) .SetFunctionName("DrawChamferRectangle"); + + + obj.AddAction("Torus", + _("Torus"), + _("Draw a torus on screen"), + _("Draw at _PARAM1_;_PARAM2_ a torus with inner radius:" + "_PARAM3_ and outer radius _PARAM4_ and " + "with start arc _PARAM5_ and end arc _PARAM6_" + "with _PARAM0_"), + _("Drawing"), + "res/actions/torus24.png", + "res/actions/torus.png") + + .AddParameter("object", _("Shape Painter object"), "Drawer") + .AddParameter("expression", _("X position of center")) + .AddParameter("expression", _("Y position of center")) + .AddParameter("expression", _("Inner Radius (in pixels)")) + .AddParameter("expression", _("Outer Radius (in pixels)")) + .AddParameter("expression", _("Start Arc (in degrees)")) + .AddParameter("expression", _("End Arc (in degrees)")) + .SetFunctionName("DrawTorus"); + obj.AddAction("RegularPolygon", _("Regular Polygon"), diff --git a/Extensions/PrimitiveDrawing/JsExtension.cpp b/Extensions/PrimitiveDrawing/JsExtension.cpp index 59c1c718b25b..fb8bd528bff2 100644 --- a/Extensions/PrimitiveDrawing/JsExtension.cpp +++ b/Extensions/PrimitiveDrawing/JsExtension.cpp @@ -54,6 +54,8 @@ class PrimitiveDrawingJsExtension : public gd::PlatformExtension { .SetFunctionName("drawChamferRectangle"); GetAllActionsForObject("PrimitiveDrawing::Drawer")["PrimitiveDrawing::RegularPolygon"] .SetFunctionName("drawRegularPolygon"); + GetAllActionsForObject("PrimitiveDrawing::Drawer")["PrimitiveDrawing::Torus"] + .SetFunctionName("drawTorus"); GetAllActionsForObject("PrimitiveDrawing::Drawer")["PrimitiveDrawing::Star"] .SetFunctionName("drawStar"); GetAllActionsForObject("PrimitiveDrawing::Drawer")["PrimitiveDrawing::Arc"] diff --git a/Extensions/PrimitiveDrawing/shapepainterruntimeobject-pixi-renderer.ts b/Extensions/PrimitiveDrawing/shapepainterruntimeobject-pixi-renderer.ts index e9504d583ce8..caac5bd201b3 100644 --- a/Extensions/PrimitiveDrawing/shapepainterruntimeobject-pixi-renderer.ts +++ b/Extensions/PrimitiveDrawing/shapepainterruntimeobject-pixi-renderer.ts @@ -155,6 +155,32 @@ namespace gdjs { this.invalidateBounds(); } + drawTorus( + x1: float, + y1: float, + innerRadius: float, + outerRadius: float, + startArc: float, + endArc: float + ) { + this.updateOutline(); + this._graphics.beginFill( + this._object._fillColor, + this._object._fillOpacity / 255 + ); + this._graphics.drawTorus( + x1, + y1, + innerRadius, + outerRadius, + startArc ? gdjs.toRad(startArc) : 0, + endArc ? gdjs.toRad(endArc) : 0 + ); + this._graphics.closePath(); + this._graphics.endFill(); + this.invalidateBounds(); + } + drawRegularPolygon( x1: float, y1: float, diff --git a/Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts b/Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts index 544456e8e4e5..3cf1b135bd93 100644 --- a/Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts +++ b/Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts @@ -242,6 +242,24 @@ namespace gdjs { ); } + drawTorus( + centerX: float, + centerY: float, + innerRadius: float, + outerRadius: float, + startArc: float, + endArc: float + ) { + this._renderer.drawTorus( + centerX, + centerY, + innerRadius, + outerRadius, + startArc, + endArc + ); + } + drawRegularPolygon( centerX: float, centerY: float,