From c2232b839de30174293018414e385f7a742cdb2c Mon Sep 17 00:00:00 2001 From: Matthew Roush Date: Mon, 20 Jul 2026 17:29:17 -0400 Subject: [PATCH] [rshapes] Add `DrawEllipseLinesEx()` Add DrawEllipseLinesEx() to the API for consistency with other shape drawing functions. --- src/raylib.h | 1 + src/rshapes.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index 154158131..994acb7fe 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1313,6 +1313,7 @@ RLAPI void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, C RLAPI void DrawEllipseV(Vector2 center, float radiusH, float radiusV, Color color); // Draw ellipse (Vector version) RLAPI void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse outline RLAPI void DrawEllipseLinesV(Vector2 center, float radiusH, float radiusV, Color color); // Draw ellipse outline (Vector version) +RLAPI void DrawEllipseLinesEx(Vector2 center, float radiusH, float radiusV, float thick, Color color); // Draw ellipse outline with line thickness RLAPI void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring RLAPI void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring outline diff --git a/src/rshapes.c b/src/rshapes.c index 65040f452..15e8f6e39 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -1690,6 +1690,76 @@ void DrawEllipseLinesV(Vector2 center, float radiusH, float radiusV, Color color rlEnd(); } +// Draw ellipse outline with thickness +void DrawEllipseLinesEx(Vector2 center, float radiusH, float radiusV, float thick, Color color) +{ + float outerRadiusH = radiusH, innerRadiusH = radiusH - thick; + float outerRadiusV = radiusV, innerRadiusV = radiusV - thick; + + if (thick >= 0.0f) { + // Just a filled-in ellipse + if (innerRadiusH <= 0.0f || innerRadiusV <= 0.0f) + { + DrawEllipseV(center, radiusH, radiusV, color); + return; + } + } + else + { + // The outline is growing outside of the ellipse, so swap the inner and outer radius + float tmp = outerRadiusH; + outerRadiusH = innerRadiusH; + innerRadiusH = tmp; + + tmp = outerRadiusV; + outerRadiusV = innerRadiusV; + innerRadiusV = tmp; + } + +#if SUPPORT_QUADS_DRAW_MODE + rlSetTexture(GetShapesTexture().id); + Rectangle shapeRect = GetShapesTextureRectangle(); + + rlBegin(RL_QUADS); + + rlColor4ub(color.r, color.g, color.b, color.a); + + for (int i = 0; i < 360; i += 10) + { + rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*i)*innerRadiusH, center.y + sinf(DEG2RAD*i)*innerRadiusV); + + rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*(i + 10))*innerRadiusH, center.y + sinf(DEG2RAD*(i + 10))*innerRadiusV); + + rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*(i + 10))*outerRadiusH, center.y + sinf(DEG2RAD*(i + 10))*outerRadiusV); + + rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*i)*outerRadiusH, center.y + sinf(DEG2RAD*i)*outerRadiusV); + } + rlEnd(); + + rlSetTexture(0); +#else + rlBegin(RL_TRIANGLES); + + rlColor4ub(color.r, color.g, color.b, color.a); + + for (int i = 0; i < 360; i += 10) + { + rlVertex2f(center.x + cosf(DEG2RAD*i)*innerRadiusH, center.y + sinf(DEG2RAD*i)*innerRadiusV); + rlVertex2f(center.x + cosf(DEG2RAD*(i + 10))*innerRadiusH, center.y + sinf(DEG2RAD*(i + 10))*innerRadiusV); + rlVertex2f(center.x + cosf(DEG2RAD*(i + 10))*outerRadiusH, center.y + sinf(DEG2RAD*(i + 10))*outerRadiusV); + + rlVertex2f(center.x + cosf(DEG2RAD*i)*innerRadiusH, center.y + sinf(DEG2RAD*i)*innerRadiusV); + rlVertex2f(center.x + cosf(DEG2RAD*(i + 10))*outerRadiusH, center.y + sinf(DEG2RAD*(i + 10))*outerRadiusV); + rlVertex2f(center.x + cosf(DEG2RAD*i)*outerRadiusH, center.y + sinf(DEG2RAD*i)*outerRadiusV); + } + rlEnd(); +#endif +} + // Draw ring void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color) {