summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRob Loach <[email protected]>2022-09-19 12:41:17 -0400
committerGitHub <[email protected]>2022-09-19 18:41:17 +0200
commit2093fdcc536e68a131c15e196460e338609e1a76 (patch)
treef6bf600217adff6d07468b2363dc7a9812455df0
parent0e5cd442be3b90c041a5874fbec52659f214827e (diff)
downloadraylib-2093fdcc536e68a131c15e196460e338609e1a76.tar.gz
raylib-2093fdcc536e68a131c15e196460e338609e1a76.zip
Added: `ImageDrawCircleLines`, `ImageDrawCircleLinesV` (#2713)
This adds `ImageDrawCircleLines()` and `ImageDrawCircleLinesV()` to draw outlines of circles, and updates `ImageDrawCircle()` draw a filled circle to match the effect of `DrawCircle()` and `DrawCircleLines()`.
-rw-r--r--examples/textures/textures_image_drawing.c2
-rw-r--r--src/raylib.h2
-rw-r--r--src/rtextures.c37
3 files changed, 36 insertions, 5 deletions
diff --git a/examples/textures/textures_image_drawing.c b/examples/textures/textures_image_drawing.c
index 203b3cd3..190fb859 100644
--- a/examples/textures/textures_image_drawing.c
+++ b/examples/textures/textures_image_drawing.c
@@ -42,7 +42,7 @@ int main(void)
// Draw on the image with a few image draw methods
ImageDrawPixel(&parrots, 10, 10, RAYWHITE);
- ImageDrawCircle(&parrots, 10, 10, 5, RAYWHITE);
+ ImageDrawCircleLines(&parrots, 10, 10, 5, RAYWHITE);
ImageDrawRectangle(&parrots, 5, 20, 10, 10, RAYWHITE);
UnloadImage(cat); // Unload image from RAM
diff --git a/src/raylib.h b/src/raylib.h
index ac5d6e6a..7e4fdf3f 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -1287,6 +1287,8 @@ RLAPI void ImageDrawLine(Image *dst, int startPosX, int startPosY, int endPosX,
RLAPI void ImageDrawLineV(Image *dst, Vector2 start, Vector2 end, Color color); // Draw line within an image (Vector version)
RLAPI void ImageDrawCircle(Image *dst, int centerX, int centerY, int radius, Color color); // Draw circle within an image
RLAPI void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color); // Draw circle within an image (Vector version)
+RLAPI void ImageDrawCircleLines(Image *dst, int centerX, int centerY, int radius, Color color); // Draw circle outline within an image
+RLAPI void ImageDrawCircleLinesV(Image *dst, Vector2 center, int radius, Color color); // Draw circle outline within an image (Vector version)
RLAPI void ImageDrawRectangle(Image *dst, int posX, int posY, int width, int height, Color color); // Draw rectangle within an image
RLAPI void ImageDrawRectangleV(Image *dst, Vector2 position, Vector2 size, Color color); // Draw rectangle within an image (Vector version)
RLAPI void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color); // Draw rectangle within an image
diff --git a/src/rtextures.c b/src/rtextures.c
index 12ba4923..5a77ac7b 100644
--- a/src/rtextures.c
+++ b/src/rtextures.c
@@ -2716,7 +2716,36 @@ void ImageDrawLineV(Image *dst, Vector2 start, Vector2 end, Color color)
}
// Draw circle within an image
-void ImageDrawCircle(Image *dst, int centerX, int centerY, int radius, Color color)
+void ImageDrawCircle(Image* dst, int centerX, int centerY, int radius, Color color)
+{
+ int x = 0, y = radius;
+ int decesionParameter = 3 - 2 * radius;
+
+ while (y >= x)
+ {
+ ImageDrawRectangle(dst, centerX - x, centerY + y, x * 2, 1, color);
+ ImageDrawRectangle(dst, centerX - x, centerY - y, x * 2, 1, color);
+ ImageDrawRectangle(dst, centerX - y, centerY + x, y * 2, 1, color);
+ ImageDrawRectangle(dst, centerX - y, centerY - x, y * 2, 1, color);
+ x++;
+
+ if (decesionParameter > 0) {
+ y--;
+ decesionParameter = decesionParameter + 4 * (x - y) + 10;
+ } else {
+ decesionParameter = decesionParameter + 4 * x + 6;
+ }
+ }
+}
+
+// Draw circle within an image (Vector version)
+void ImageDrawCircleV(Image* dst, Vector2 center, int radius, Color color)
+{
+ ImageDrawCircle(dst, (int)center.x, (int)center.y, radius, color);
+}
+
+// Draw circle outline within an image
+void ImageDrawCircleLines(Image *dst, int centerX, int centerY, int radius, Color color)
{
int x = 0, y = radius;
int decesionParameter = 3 - 2*radius;
@@ -2742,10 +2771,10 @@ void ImageDrawCircle(Image *dst, int centerX, int centerY, int radius, Color col
}
}
-// Draw circle within an image (Vector version)
-void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color)
+// Draw circle outline within an image (Vector version)
+void ImageDrawCircleLinesV(Image *dst, Vector2 center, int radius, Color color)
{
- ImageDrawCircle(dst, (int)center.x, (int)center.y, radius, color);
+ ImageDrawCircleLines(dst, (int)center.x, (int)center.y, radius, color);
}
// Draw rectangle within an image