summaryrefslogtreecommitdiffhomepage
path: root/src/textures.c
diff options
context:
space:
mode:
authorRay <[email protected]>2018-06-02 12:47:05 +0200
committerRay <[email protected]>2018-06-02 12:47:05 +0200
commitafc41817521fd86799ce96b049cce7c581a1f108 (patch)
treec2cd86edcccdb8851b405b41963fb576a0014666 /src/textures.c
parent2536bea379387e525e3107ee07355292ee87a566 (diff)
downloadraylib-afc41817521fd86799ce96b049cce7c581a1f108.tar.gz
raylib-afc41817521fd86799ce96b049cce7c581a1f108.zip
Work on ImageResizeCanvas()
Diffstat (limited to 'src/textures.c')
-rw-r--r--src/textures.c58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/textures.c b/src/textures.c
index 239b7cf5..c4e77458 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -1067,18 +1067,58 @@ void ImageResizeNN(Image *image,int newWidth,int newHeight)
free(pixels);
}
-// Resize canvas, using anchor point and color filling
-void ImageResizeCanvas(Image *image, int newWidth,int newHeight, int anchor, Color color)
+// Resize canvas and fill with color
+// NOTE: Resize offset is relative to the top-left corner of the original image
+void ImageResizeCanvas(Image *image, int newWidth,int newHeight, int offsetX, int offsetY, Color color)
{
Image imTemp = GenImageColor(newWidth, newHeight, color);
- Rectangle rec = { 0, 0, image->width, image->height };
+ Rectangle srcRec = { 0, 0, image->width, image->height };
+ Rectangle dstRec = { offsetX, offsetY, srcRec.width, srcRec.height };
- // TODO: consider anchor properly
-
- ImageDraw(&imTemp, *image, rec, rec);
- ImageFormat(&imTemp, image->format);
- UnloadImage(*image);
- *image = imTemp;
+ if ((newWidth > image->width) && (newHeight > image->height))
+ {
+ // Consider anchor properly
+ /*
+ switch (anchor)
+ {
+ case 0: break; // TOP-LEFT corner --> dstRec = srcRec
+ case 1: dstRec.x = (newWidth - image->width)/2; break; // TOP side
+ case 2: dstRec.x = newWidth - image->width; break; // TOP-RIGHT corner
+ case 3: dstRec.y = (newHeight - image->height)/2; break; // LEFT side
+ case 4: // CENTER
+ {
+ dstRec.x = (newWidth - image->width)/2;
+ dstRec.y = (newHeight - image->height)/2;
+ } break;
+ case 5: // RIGHT side
+ {
+ dstRec.x = newWidth - image->width;
+ dstRec.y = (newHeight - image->height)/2;
+ } break;
+ case 6: dstRec.y = newHeight - image->height; break; // BOTTOM-LEFT corner
+ case 7: // BOTTOM side
+ {
+ dstRec.x = (newWidth - image->width)/2;
+ dstRec.y = newHeight - image->height;
+ } break;
+ case 8: // BOTTOM-RIGHT side
+ {
+ dstRec.x = newWidth - image->width;
+ dstRec.y = newHeight - image->height;
+ } break;
+ default: break;
+ }
+ */
+ ImageDraw(&imTemp, *image, srcRec, dstRec);
+ ImageFormat(&imTemp, image->format);
+ UnloadImage(*image);
+ *image = imTemp;
+ }
+ else
+ {
+ // TODO: ImageCrop(), define proper cropping rectangle
+ }
+
}
// Generate all mipmap levels for a provided image