Add an action to draw a torus with the shape painter object (#5981)

- Thanks @trp02
This commit is contained in:
TRP
2023-12-04 08:11:41 -05:00
committed by GitHub
parent ed4635664c
commit bd898463f5
6 changed files with 69 additions and 0 deletions

View File

@@ -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"),

View File

@@ -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"]

View File

@@ -155,6 +155,33 @@ 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
);
//@ts-ignore from @pixi/graphics-extras
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,

View File

@@ -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,

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB