From ef5519b8f79aeccc9a8bcca59ef76e5eda761500 Mon Sep 17 00:00:00 2001 From: Matorio <209939889+Matorio@users.noreply.github.com> Date: Sun, 17 Aug 2025 00:35:38 -0500 Subject: [PATCH] Sizing and position Added a few sizing utils to "Rectangle" Added "GetScreenCenter" to "Raylib.Utils" --- Raylib-cs/types/Raylib.Utils.cs | 8 +++++++ Raylib-cs/types/Rectangle.cs | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/Raylib-cs/types/Raylib.Utils.cs b/Raylib-cs/types/Raylib.Utils.cs index 51c8952..3c144b7 100644 --- a/Raylib-cs/types/Raylib.Utils.cs +++ b/Raylib-cs/types/Raylib.Utils.cs @@ -1561,4 +1561,12 @@ public static unsafe partial class Raylib UnloadFileText(data); return text; } + + public static Vector2 GetScreenCenter() + { + Vector2 center = new Vector2(); + center.X = GetScreenWidth() / 2.0f; + center.Y = GetScreenHeight() / 2.0f; + return center; + } } diff --git a/Raylib-cs/types/Rectangle.cs b/Raylib-cs/types/Rectangle.cs index 232c940..d2ec02a 100644 --- a/Raylib-cs/types/Rectangle.cs +++ b/Raylib-cs/types/Rectangle.cs @@ -14,6 +14,24 @@ public struct Rectangle public float Width; public float Height; + public static Rectangle Grow(Rectangle rec, float growth) + { + rec.X -= growth; + rec.Y -= growth; + rec.Width += growth * 2.0f; + rec.Height += growth * 2.0f; + return rec; + } + + public static Rectangle Shrink(Rectangle rec, float shrink) + { + rec.X += shrink; + rec.Y += shrink; + rec.Width-= shrink * 2.0f; + rec.Height -= shrink * 2.0f; + return rec; + } + public Rectangle(float x, float y, float width, float height) { this.X = x; @@ -72,6 +90,17 @@ public struct Rectangle } } + public readonly Vector2 Center + { + get + { + Vector2 center = new Vector2(); + center.X = X + (Width / 2.0f); + center.Y = Y + (Height / 2.0f); + return center; + } + } + public readonly void Draw(Color color) { Raylib.DrawRectangleRec(this, color); @@ -173,6 +202,16 @@ public struct Rectangle return Raylib.GetCollisionRec(this, rectangle2); } + public void Grow(float growth) + { + this = Rectangle.Grow(this, growth); + } + + public void Shrink(float shrink) + { + this = Rectangle.Shrink(this, shrink); + } + public readonly override string ToString() { return $"{{X:{X} Y:{Y} Width:{Width} Height:{Height}}}";