From 8cad35a757f502b65f108b8c7a57312b715d5acb Mon Sep 17 00:00:00 2001 From: Matorio <209939889+Matorio@users.noreply.github.com> Date: Sun, 7 Dec 2025 00:04:38 -0500 Subject: [PATCH] Rectangle uniform scaling New "ExpandRectangle" and "ShrinkRectangle" functions to save repetitive tasks. --- src/raylib.h | 2 ++ src/rtextures.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index 244e45e14..d88fe0d5f 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1455,6 +1455,8 @@ RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle // Color/pixel related functions RLAPI bool ColorIsEqual(Color col1, Color col2); // Check if two colors are equal RLAPI Color Fade(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f +RLAPI Rectangle ExpandRectangle(Rectangle rec, float expand); // Expand a rectangle uniformly +RLAPI Rectangle ShrinkRectangle(Rectangle rec, float shrink); // Shrink a rectangle uniformly RLAPI int ColorToInt(Color color); // Get hexadecimal value for a Color (0xRRGGBBAA) RLAPI Vector4 ColorNormalize(Color color); // Get Color normalized as float [0..1] RLAPI Color ColorFromNormalized(Vector4 normalized); // Get Color from normalized values [0..1] diff --git a/src/rtextures.c b/src/rtextures.c index 17065822a..c11b2e8aa 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -4859,6 +4859,24 @@ Color Fade(Color color, float alpha) return result; } +// Expand a rectangle uniformly +Rectangle ExpandRectangle(Rectangle rec, float expand) +{ + rec.x -= expand / 2.0f; + rec.y -= expand / 2.0f; + rec.width += expand; + rec.height += expand; +} + +// Shrink a rectangle uniformly +Rectangle ShrinkRectangle(Rectangle rec, float shrink) +{ + rec.x += shrink / 2.0f; + rec.y += shrink / 2.0f; + rec.width -= shrink; + rec.height -= shrink; +} + // Get hexadecimal value for a Color int ColorToInt(Color color) {