Sizing and position
Added a few sizing utils to "Rectangle" Added "GetScreenCenter" to "Raylib.Utils"
This commit is contained in:
parent
e2bbeee1b2
commit
ef5519b8f7
2 changed files with 47 additions and 0 deletions
|
|
@ -1561,4 +1561,12 @@ public static unsafe partial class Raylib
|
||||||
UnloadFileText(data);
|
UnloadFileText(data);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vector2 GetScreenCenter()
|
||||||
|
{
|
||||||
|
Vector2 center = new Vector2();
|
||||||
|
center.X = GetScreenWidth() / 2.0f;
|
||||||
|
center.Y = GetScreenHeight() / 2.0f;
|
||||||
|
return center;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,24 @@ public struct Rectangle
|
||||||
public float Width;
|
public float Width;
|
||||||
public float Height;
|
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)
|
public Rectangle(float x, float y, float width, float height)
|
||||||
{
|
{
|
||||||
this.X = x;
|
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)
|
public readonly void Draw(Color color)
|
||||||
{
|
{
|
||||||
Raylib.DrawRectangleRec(this, color);
|
Raylib.DrawRectangleRec(this, color);
|
||||||
|
|
@ -173,6 +202,16 @@ public struct Rectangle
|
||||||
return Raylib.GetCollisionRec(this, rectangle2);
|
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()
|
public readonly override string ToString()
|
||||||
{
|
{
|
||||||
return $"{{X:{X} Y:{Y} Width:{Width} Height:{Height}}}";
|
return $"{{X:{X} Y:{Y} Width:{Width} Height:{Height}}}";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue