WARNING: BREAKING: REDESIGNED: ImageDraw() API, align with DrawTexture()

This commit is contained in:
Ray
2026-06-07 21:53:07 +02:00
parent 26d82cf55d
commit aebfd788c7
3 changed files with 28 additions and 9 deletions
+3 -1
View File
@@ -1437,9 +1437,11 @@ RLAPI void ImageDrawCircle(Image *dst, int centerX, int centerY, int radius, Col
RLAPI void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color); // Draw a filled circle within an image (Vector version) RLAPI void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color); // Draw a filled 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 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 ImageDrawCircleLinesV(Image *dst, Vector2 center, int radius, Color color); // Draw circle outline within an image (Vector version)
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); // Draw a source image into a destination image (tint applied to source)
RLAPI void ImageDrawCircleGradient(Image *dst, Vector2 center, float radius, Color inner, Color outer); // Draw a gradient-filled circle within an image RLAPI void ImageDrawCircleGradient(Image *dst, Vector2 center, float radius, Color inner, Color outer); // Draw a gradient-filled circle within an image
RLAPI void ImageDrawImage(Image *dst, Image src, int posX, int posY, Color tint); // Draw an image within an image
RLAPI void ImageDrawImageRec(Image *dst, Image src, Rectangle srcRec, Vector2 position, Color tint); // Draw a part of an image defined by a rectangle within an image
RLAPI void ImageDrawImagePro(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Vector2 origin, float rotation, Color tint); // Draw a part of an image defined by a rectangle into destination rectangle, with scaling and rotation, within an image
RLAPI void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) within an image (destination) RLAPI void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) within an image (destination)
RLAPI void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text (custom sprite font) within an image (destination) RLAPI void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text (custom sprite font) within an image (destination)
+1 -1
View File
@@ -2673,7 +2673,7 @@ static Font LoadBMFont(const char *fileName)
{ {
Rectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight }; Rectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight };
Rectangle dstRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight }; Rectangle dstRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight };
ImageDraw(&fullFont, imFonts[i], srcRec, dstRec, WHITE); ImageDrawImagePro(&fullFont, imFonts[i], srcRec, dstRec, (Vector2){ 0 }, 0.0f, WHITE);
} }
} }
+24 -7
View File
@@ -1500,7 +1500,8 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
if ((codepoint != ' ') && (codepoint != '\t')) if ((codepoint != ' ') && (codepoint != '\t'))
{ {
Rectangle rec = { (float)(textOffsetX + font.glyphs[index].offsetX), (float)(textOffsetY + font.glyphs[index].offsetY), (float)font.recs[index].width, (float)font.recs[index].height }; Rectangle rec = { (float)(textOffsetX + font.glyphs[index].offsetX), (float)(textOffsetY + font.glyphs[index].offsetY), (float)font.recs[index].width, (float)font.recs[index].height };
ImageDraw(&imText, font.glyphs[index].image, (Rectangle){ 0, 0, (float)font.glyphs[index].image.width, (float)font.glyphs[index].image.height }, rec, tint); ImageDrawImagePro(&imText, font.glyphs[index].image, (Rectangle){ 0, 0, (float)font.glyphs[index].image.width, (float)font.glyphs[index].image.height },
rec, (Vector2){ 0 }, 0.0f, tint);
} }
if (font.glyphs[index].advanceX == 0) textOffsetX += (int)(font.recs[index].width + spacing); if (font.glyphs[index].advanceX == 0) textOffsetX += (int)(font.recs[index].width + spacing);
@@ -3941,15 +3942,31 @@ void ImageDrawCircleLinesV(Image *dst, Vector2 center, int radius, Color color)
ImageDrawCircleLines(dst, (int)center.x, (int)center.y, radius, color); ImageDrawCircleLines(dst, (int)center.x, (int)center.y, radius, color);
} }
// Draw an image (source) within an image (destination)
// Draw a gradient-filled circle within an image // Draw a gradient-filled circle within an image
void ImageDrawCircleGradient(Image *dst, Vector2 center, float radius, Color inner, Color outer) void ImageDrawCircleGradient(Image *dst, Vector2 center, float radius, Color inner, Color outer)
{ {
// TODO: Implement gradient circle drawing // TODO: Implement gradient circle drawing
} }
// Draw an image within an image
void ImageDrawImage(Image *dst, Image src, int posX, int posY, Color tint)
{
Rectangle srcRec = { 0, 0, src.width, src.height };
Rectangle dstRec = { posX, posY, srcRec.width, srcRec.height };
ImageDrawImagePro(dst, src, srcRec, dstRec, (Vector2){ 0 }, 0.0f, tint);
}
// Draw a part of an image defined by a rectangle within an image
void ImageDrawImageRec(Image *dst, Image src, Rectangle srcRec, Vector2 position, Color tint)
{
Rectangle dstRec = { position.x, position.y, srcRec.width, srcRec.height };
ImageDrawImagePro(dst, src, srcRec, dstRec, (Vector2){ 0 }, 0.0f, tint);
}
// Draw a part of an image defined by a rectangle into destination rectangle, with scaling and rotation, within an image
// NOTE: Color tint is applied to source image // NOTE: Color tint is applied to source image
void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint) // TODO: WARNING: origin and rotation are not implemented
void ImageDrawImagePro(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Vector2 origin, float rotation, Color tint)
{ {
// Security check to avoid program crash // Security check to avoid program crash
if ((dst->data == NULL) || (dst->width == 0) || (dst->height == 0) || if ((dst->data == NULL) || (dst->width == 0) || (dst->height == 0) ||
@@ -4010,7 +4027,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
// [x] Consider fast path: no alpha blending required cases (src has no alpha) // [x] Consider fast path: no alpha blending required cases (src has no alpha)
// [x] Consider fast path: same src/dst format with no alpha -> direct line copy // [x] Consider fast path: same src/dst format with no alpha -> direct line copy
// [-] GetPixelColor(): Get Vector4 instead of Color, easier for ColorAlphaBlend() // [-] GetPixelColor(): Get Vector4 instead of Color, easier for ColorAlphaBlend()
// [ ] TODO: Support 16bit and 32bit (float) channels drawing // [-] Support 16bit and 32bit (float) channels drawing
Color colSrc = { 0 }; Color colSrc = { 0 };
Color colDst = { 0 }; Color colDst = { 0 };
@@ -4094,7 +4111,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
mipmapDstRec.x /= 2; mipmapDstRec.x /= 2;
mipmapDstRec.y /= 2; mipmapDstRec.y /= 2;
ImageDraw(&mipmapDst, mipmapSrc, mipmapSrcRec, mipmapDstRec, tint); ImageDrawImagePro(&mipmapDst, mipmapSrc, mipmapSrcRec, mipmapDstRec, (Vector2){ 0 }, 0.0f, tint);
} }
} }
} }
@@ -4121,7 +4138,7 @@ void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position,
Rectangle srcRec = { 0.0f, 0.0f, (float)imText.width, (float)imText.height }; Rectangle srcRec = { 0.0f, 0.0f, (float)imText.width, (float)imText.height };
Rectangle dstRec = { position.x, position.y, (float)imText.width, (float)imText.height }; Rectangle dstRec = { position.x, position.y, (float)imText.width, (float)imText.height };
ImageDraw(dst, imText, srcRec, dstRec, WHITE); ImageDrawImagePro(dst, imText, srcRec, dstRec, (Vector2){ 0 }, 0.0f, WHITE);
UnloadImage(imText); UnloadImage(imText);
} }
@@ -4247,7 +4264,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layout)
ImageMipmaps(&faces); ImageMipmaps(&faces);
} }
for (int i = 0; i < 6; i++) ImageDraw(&faces, mipmapped, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE); for (int i = 0; i < 6; i++) ImageDrawImagePro(&faces, mipmapped, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, (Vector2){ 0 }, 0.0f, WHITE);
UnloadImage(mipmapped); UnloadImage(mipmapped);
} }