CrabUI
Loading...
Searching...
No Matches
CUIAnchor.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 /// <summary>
14 /// CUIAnchor is just a Vector2
15 /// This is a static class containing some helper methods
16 /// </summary>
17 public class CUIAnchor
18 {
19 public static Vector2 TopLeft = new Vector2(0.0f, 0.0f);
20 public static Vector2 TopCenter = new Vector2(0.5f, 0.0f);
21 public static Vector2 TopRight = new Vector2(1.0f, 0.0f);
22 public static Vector2 CenterLeft = new Vector2(0.0f, 0.5f);
23 public static Vector2 Center = new Vector2(0.5f, 0.5f);
24 public static Vector2 CenterRight = new Vector2(1.0f, 0.5f);
25 public static Vector2 BottomLeft = new Vector2(0.0f, 1.0f);
26 public static Vector2 BottomCenter = new Vector2(0.5f, 1.0f);
27 public static Vector2 BottomRight = new Vector2(1.0f, 1.0f);
28
29 public static Vector2 Direction(Vector2 anchor)
30 {
31 return (Center - anchor) * 2;
32 }
33
34 public static Vector2 PosIn(CUIComponent host) => PosIn(host.Real, host.Anchor);
35 public static Vector2 PosIn(CUIRect rect, Vector2 anchor)
36 {
37 return new Vector2(
38 rect.Left + rect.Width * anchor.X,
39 rect.Top + rect.Height * anchor.Y
40 );
41 }
42
43 public static Vector2 AnchorFromPos(CUIRect rect, Vector2 pos)
44 {
45 return (pos - rect.Position) / rect.Size;
46 }
47
48 public static Vector2 GetChildPos(CUIRect parent, Vector2 anchor, Vector2 offset, Vector2 childSize)
49 {
50 return PosIn(parent, anchor) + offset - PosIn(new CUIRect(childSize), anchor);
51 }
52
53 public static Vector2 GetChildPos(CUIRect parent, Vector2 parentAnchor, Vector2 offset, Vector2 childSize, Vector2 anchor)
54 {
55 return PosIn(parent, parentAnchor) + offset - PosIn(new CUIRect(childSize), anchor);
56 }
57 }
58}
CUIAnchor is just a Vector2 This is a static class containing some helper methods.
Definition CUIAnchor.cs:18
Base class for all components.
Vector2 Anchor
this point of this component
CUIRect Real
Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent....
Rectangle with float.
Definition CUIRect.cs:17