CrabUI
Loading...
Searching...
No Matches
CUIBoundaries.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5
6using Barotrauma;
7using Microsoft.Xna.Framework;
8using Microsoft.Xna.Framework.Input;
9using Microsoft.Xna.Framework.Graphics;
10
11namespace CrabUI
12{
13 //TODO should be 2 different structs i think
14 /// <summary>
15 /// Defining Boundaries, not the same as rect
16 /// containing min/max x, y, z
17 /// </summary>
18 public struct CUIBoundaries
19 {
20 public static Func<CUIRect, CUIBoundaries> Free = (Rect) => new CUIBoundaries(null, null, null, null);
21 public static Func<CUIRect, CUIBoundaries> Box = (Rect) => new CUIBoundaries(0, Rect.Width, 0, Rect.Height);
22 public static Func<CUIRect, CUIBoundaries> HorizontalTube = (Rect) => new CUIBoundaries(null, null, 0, Rect.Height);
23 public static Func<CUIRect, CUIBoundaries> VerticalTube = (Rect) => new CUIBoundaries(0, Rect.Width, null, null);
24
25
26 public float? MinX;
27 public float? MaxX;
28 public float? MinY;
29 public float? MaxY;
30
31 //TODO minZ is hardcoded in CUI3DOffset, untangle this crap
32 // unusable for now
33 public float? MinZ;
34 public float? MaxZ;
35
36 public CUIRect Check(float x, float y, float w, float h)
37 {
38 if (MaxX.HasValue && x + w > MaxX.Value) x = MaxX.Value - w;
39 if (MaxY.HasValue && y + h > MaxY.Value) y = MaxY.Value - h;
40 if (MinX.HasValue && x < MinX.Value) x = MinX.Value;
41 if (MinY.HasValue && y < MinY.Value) y = MinY.Value;
42
43 return new CUIRect(x, y, w, h);
44 }
45
46
47 public CUI3DOffset Check(CUI3DOffset offset) => Check(offset.X, offset.Y, offset.Z);
48 public CUI3DOffset Check(float x, float y, float z)
49 {
50 if (MaxX.HasValue && x > MaxX.Value) x = MaxX.Value;
51 if (MaxY.HasValue && y > MaxY.Value) y = MaxY.Value;
52 if (MaxZ.HasValue && z > MaxZ.Value) z = MaxZ.Value;
53
54 if (MinX.HasValue && x < MinX.Value) x = MinX.Value;
55 if (MinY.HasValue && y < MinY.Value) y = MinY.Value;
56 if (MinZ.HasValue && z < MinZ.Value) z = MinZ.Value;
57
58 return new CUI3DOffset(x, y, z);
59 }
60
61 //HACK Why the fuck vars defined in this order?
62 // probably to not confuse them with pos and size
63 public CUIBoundaries(
64 float? minX = null, float? maxX = null,
65 float? minY = null, float? maxY = null,
66 float? minZ = null, float? maxZ = null
67 )
68 {
69 MinX = minX;
70 MaxX = maxX;
71 MinY = minY;
72 MaxY = maxY;
73 MinZ = minZ;
74 MaxZ = maxZ;
75 }
76
77 public override string ToString() => $"[{MinX},{MaxX},{MinY},{MaxY},{MinZ},{MaxZ}]";
78 }
79}
Offset of child components with X, Y, Z.
Defining Boundaries, not the same as rect containing min/max x, y, z.
Rectangle with float.
Definition CUIRect.cs:17