Skip to content

Commit

Permalink
add torus
Browse files Browse the repository at this point in the history
  • Loading branch information
trp02 committed Nov 30, 2023
1 parent e2c40ff commit 1ca3f23
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Extensions/PrimitiveDrawing/Extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions Extensions/PrimitiveDrawing/JsExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1ca3f23

Please sign in to comment.