Watch
2
0
Fork
You've already forked raylib-cs
0

Sizing and position

Added a few sizing utils to "Rectangle"
Added "GetScreenCenter" to "Raylib.Utils"
This commit is contained in:
Matorio 2025-08-17 00:35:38 -05:00
commit ef5519b8f7
2 changed files with 47 additions and 0 deletions

View file

@ -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}}}";