21 public static Rectangle
CreateRect(
float x,
float y,
float w,
float h)
23 return new Rectangle((
int)Math.Round(x), (
int)Math.Round(y), (
int)Math.Round(w), (
int)Math.Round(h));
32 public float Right => Left + Width;
33 public float Bottom => Top + Height;
35 public Vector2 Size =>
new Vector2(Width, Height);
36 public Vector2 Position =>
new Vector2(Left, Top);
37 public Vector2 Center =>
new Vector2(Left + Width / 2, Top + Height / 2);
38 public Rectangle Box =>
new Rectangle((
int)Left, (
int)Top, (
int)Width, (
int)Height);
40 public Vector2 LeftTop =>
new Vector2(Left, Top);
41 public Vector2 LeftCenter =>
new Vector2(Left, Top + Height / 2);
42 public Vector2 LeftBottom =>
new Vector2(Left, Top + Height);
43 public Vector2 CenterTop =>
new Vector2(Left + Width / 2, Top);
44 public Vector2 CenterCenter =>
new Vector2(Left + Width / 2, Top + Height / 2);
45 public Vector2 CenterBottom =>
new Vector2(Left + Width / 2, Top + Height);
46 public Vector2 RightTop =>
new Vector2(Left + Width, Top);
47 public Vector2 RightCenter =>
new Vector2(Left + Width, Top + Height / 2);
48 public Vector2 RightBottom =>
new Vector2(Left + Width, Top + Height);
52 public CUIRect Shift(Vector2 shift)
54 return new CUIRect(Left + shift.X, Top + shift.Y, Width, Height);
57 public bool Contains(
float x,
float y)
59 return Left < x && x < Right && Top < y && y < Bottom;
61 public bool Contains(Vector2 pos)
63 return Left < pos.X && pos.X < Right && Top < pos.Y && pos.Y < Bottom;
65 public bool Intersect(CUIRect r)
67 return r.Right >= Left && r.Left <= Right && r.Bottom >= Top && r.Top <= Bottom;
70 public Rectangle Zoom(
float Z)
72 Vector2 ScreenCenter = CUI.GameScreenSize / 2.0f;
73 Vector2 PosDif = Position - ScreenCenter;
74 Vector2 newPos = PosDif * Z + ScreenCenter;
77 (
int)newPos.X, (
int)newPos.Y,
78 (
int)(Width / Z), (
int)(Height / Z)
85 public CUIRect(Vector2 size) : this(0, 0, size.X, size.Y) { }
86 public CUIRect(Vector2 position, Vector2 size) : this(position.X, position.Y, size.X, size.Y) { }
87 public CUIRect(
float x,
float y,
float w,
float h)
91 Width = Math.Max(0f, w);
92 Height = Math.Max(0f, h);
97 public override string ToString() => $
"[{Left},{Top},{Width},{Height}]";
108 string content = s.Substring(
110 s.IndexOf(
']') - s.IndexOf(
'[') - 1
113 var components = content.Split(
',').Select(a => a.Trim());
115 string sx = components.ElementAtOrDefault(0);
116 string sy = components.ElementAtOrDefault(1);
117 string sw = components.ElementAtOrDefault(2);
118 string sh = components.ElementAtOrDefault(3);
125 if (sx ==
null || sx ==
"") x =
null;
126 else x =
float.Parse(sx);
128 if (sy ==
null || sy ==
"") y =
null;
129 else y =
float.Parse(sy);
131 if (sw ==
null || sw ==
"") w =
null;
132 else w =
float.Parse(sw);
134 if (sh ==
null || sh ==
"") h =
null;
135 else h =
float.Parse(sh);
143 public float? Height;
147 get =>
new Vector2(Width ?? 0, Height ?? 0);
148 set { Width = value.X; Height = value.Y; }
150 public Vector2 Position
152 get =>
new Vector2(Left ?? 0, Top ?? 0);
153 set { Left = value.X; Top = value.Y; }
156 public Vector2 Center =>
new Vector2(
157 (Left ?? 0) + (Width ?? 0) / 2,
158 (Top ?? 0) + (Height ?? 0) / 2
161 public CUINullRect(Vector2 position, Vector2 size) :
this(position.X, position.Y, size.X, size.Y) { }
163 public CUINullRect(
float? x =
null,
float? y =
null,
float? w =
null,
float? h =
null)
171 public override string ToString() => $
"[{Left},{Top},{Width},{Height}]";