Client LuaCsForBarotrauma
RectTransform.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using Microsoft.Xna.Framework;
6 using System.Xml.Linq;
7 
8 namespace Barotrauma
9 {
10  public enum Anchor
11  {
15  }
16 
17  public enum Pivot
18  {
22  }
23 
24  public enum ScaleBasis
25  {
26  Normal,
29  }
30 
31  public class RectTransform
32  {
33  #region Fields and Properties
39  public GUIComponent GUIComponent { get; set; }
40 
41  private RectTransform parent;
43  {
44  get { return parent; }
45  set
46  {
47  if (parent == value || value == this) { return; }
48  // Remove the child from the old parent
49  RemoveFromHierarchy(displayErrors: false);
50  parent = value;
51  if (parent != null && !parent.children.Contains(this))
52  {
53  parent.children.Add(this);
54  RecalculateAll(false, true, true);
55  Parent.ChildrenChanged?.Invoke(this);
56  }
57  ParentChanged?.Invoke(parent);
58  }
59  }
60 
61  protected readonly List<RectTransform> children = new List<RectTransform>();
62  public IEnumerable<RectTransform> Children => children;
63 
64  public int CountChildren => children.Count;
65 
66  private Vector2 relativeSize = Vector2.One;
70  public Vector2 RelativeSize
71  {
72  get { return relativeSize; }
73  set
74  {
75  if (relativeSize.NearlyEquals(value)) { return; }
76  relativeSize = value;
77  RecalculateAll(resize: true, scale: false, withChildren: true);
78  }
79  }
80 
81  private Point? minSize;
86  public Point MinSize
87  {
88  get { return minSize ?? Point.Zero; }
89  set
90  {
91  if (minSize == value) { return; }
92  minSize = value;
93  RecalculateAll(true, false, true);
94  }
95  }
96 
97  public readonly static Point MaxPoint = new Point(int.MaxValue, int.MaxValue);
98  private Point? maxSize;
99 
104  public Point MaxSize
105  {
106  get { return maxSize ?? MaxPoint; }
107  set
108  {
109  if (maxSize == value) { return; }
110  maxSize = value;
111  RecalculateAll(true, false, true);
112  }
113  }
114 
115  private Point nonScaledSize;
119  public Point NonScaledSize
120  {
121  get { return nonScaledSize; }
122  set
123  {
124  if (nonScaledSize == value) { return; }
125  nonScaledSize = value.Clamp(MinSize, MaxSize);
129  RecalculateChildren(resize: true, scale: false);
130  }
131  }
135  public Point ScaledSize => NonScaledSize.Multiply(Scale);
136 
147  public static Vector2 globalScale = Vector2.One;
148 
149  private Vector2 localScale = Vector2.One;
150  public Vector2 LocalScale
151  {
152  get { return localScale; }
153  set
154  {
155  if (localScale.NearlyEquals(value)) { return; }
156  localScale = value;
157  RecalculateAll(resize: false, scale: true, withChildren: true);
158  ScaleChanged?.Invoke();
159  }
160  }
161 
162  public Vector2 Scale { get; private set; }
163 
164  private Vector2 relativeOffset = Vector2.Zero;
165  private Point absoluteOffset = Point.Zero;
166  private Point screenSpaceOffset = Point.Zero;
171  public Vector2 RelativeOffset
172  {
173  get { return relativeOffset; }
174  set
175  {
176  if (relativeOffset.NearlyEquals(value)) { return; }
177  relativeOffset = value;
178  recalculateRect = true;
179  RecalculateChildren(false, false);
180  }
181  }
187  public Point AbsoluteOffset
188  {
189  get { return absoluteOffset; }
190  set
191  {
192  if (absoluteOffset == value) { return; }
193  absoluteOffset = value;
194  recalculateRect = true;
195  RecalculateChildren(false, false);
196  }
197  }
201  public Point ScreenSpaceOffset
202  {
203  get { return screenSpaceOffset; }
204  set
205  {
206  if (screenSpaceOffset == value) { return; }
207  screenSpaceOffset = value;
208  recalculateRect = true;
209  RecalculateChildren(false, false);
210  }
211  }
215  public Point PivotOffset { get; private set; }
219  public Point AnchorPoint { get; private set; }
220 
221  public Point TopLeft
222  {
223  get
224  {
225  Point absoluteOffset = ConvertOffsetRelativeToAnchor(AbsoluteOffset, Anchor);
226  Point relativeOffset = ParentRect.MultiplySize(RelativeOffset);
227  relativeOffset = ConvertOffsetRelativeToAnchor(relativeOffset, Anchor);
228  return AnchorPoint + PivotOffset + absoluteOffset + relativeOffset + ScreenSpaceOffset;
229  }
230  }
231 
232  protected Point NonScaledTopLeft
233  {
234  get
235  {
236  Point absoluteOffset = ConvertOffsetRelativeToAnchor(AbsoluteOffset, Anchor);
237  Point relativeOffset = new Point(
238  (int)(NonScaledParentSize.X * RelativeOffset.X),
239  (int)(NonScaledParentSize.Y * RelativeOffset.Y));
240  relativeOffset = ConvertOffsetRelativeToAnchor(relativeOffset, Anchor);
241  return AnchorPoint + PivotOffset + absoluteOffset + relativeOffset + ScreenSpaceOffset;
242  }
243  }
244 
245  private bool recalculateRect = true;
246  private Rectangle _rect;
248  {
249  get
250  {
251  if (recalculateRect)
252  {
253  _rect = new Rectangle(TopLeft, ScaledSize);
254  recalculateRect = false;
255  }
256  return _rect;
257  }
258  }
259  public Rectangle ParentRect => Parent != null ? Parent.Rect : UIRect;
262  protected Point NonScaledParentSize => parent?.NonScaledSize ?? new Point(GUI.UIWidth, GameMain.GraphicsHeight);
263  protected Rectangle NonScaledParentRect => parent != null ? Parent.NonScaledRect : UIRect;
265  protected Rectangle UIRect => new Rectangle(0, 0, GUI.UIWidth, GameMain.GraphicsHeight);
266 
267  private Pivot pivot;
273  public Pivot Pivot
274  {
275  get { return pivot; }
276  set
277  {
278  if (pivot == value) { return; }
279  pivot = value;
281  }
282  }
283 
284  private Anchor anchor;
290  public Anchor Anchor
291  {
292  get { return anchor; }
293  set
294  {
295  if (anchor == value) { return; }
296  anchor = value;
298  }
299  }
300 
301  private ScaleBasis _scaleBasis;
303  {
304  get { return _scaleBasis; }
305  set
306  {
307  _scaleBasis = value;
311  }
312  }
313 
314  public bool IsLastChild
315  {
316  get
317  {
318  if (Parent == null) { return false; }
319  var last = Parent.Children.LastOrDefault();
320  if (last == null) { return false; }
321  return last == this;
322  }
323  }
324 
325  public bool IsFirstChild
326  {
327  get
328  {
329  if (Parent == null) { return false; }
330  var first = Parent.Children.FirstOrDefault();
331  if (first == null) { return false; }
332  return first == this;
333  }
334  }
335  #endregion
336 
337  #region Events
338  public event Action<RectTransform> ParentChanged;
342  public event Action<RectTransform> ChildrenChanged;
343  public event Action ScaleChanged;
344  public event Action SizeChanged;
345 
346  public void ResetSizeChanged()
347  {
348  SizeChanged = null;
349  }
350  #endregion
351 
352  #region Initialization
353  public RectTransform(Vector2 relativeSize, RectTransform parent, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null, Point? minSize = null, Point? maxSize = null, ScaleBasis scaleBasis = ScaleBasis.Normal)
354  {
355  Init(parent, anchor, pivot);
356  _scaleBasis = scaleBasis;
357  this.relativeSize = relativeSize;
358  this.minSize = minSize;
359  this.maxSize = maxSize;
364  parent?.ChildrenChanged?.Invoke(this);
365  }
366 
371  public RectTransform(Point absoluteSize, RectTransform parent = null, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null, ScaleBasis scaleBasis = ScaleBasis.Normal, bool isFixedSize = false)
372  {
373  Init(parent, anchor, pivot);
374  _scaleBasis = scaleBasis;
375  this.nonScaledSize = absoluteSize;
378  if (scaleBasis != ScaleBasis.Normal)
379  {
381  }
384  IsFixedSize = isFixedSize;
385  parent?.ChildrenChanged?.Invoke(this);
386  }
387 
388  public static RectTransform Load(XElement element, RectTransform parent, Anchor defaultAnchor = Anchor.TopLeft)
389  {
390  Enum.TryParse(element.GetAttributeString("anchor", defaultAnchor.ToString()), out Anchor anchor);
391  Enum.TryParse(element.GetAttributeString("pivot", anchor.ToString()), out Pivot pivot);
392 
393  Point? minSize = null, maxSize = null;
394  ScaleBasis scaleBasis = ScaleBasis.Normal;
395  if (element.Attribute("minsize") != null)
396  {
397  minSize = element.GetAttributePoint("minsize", Point.Zero);
398  }
399  if (element.Attribute("maxsize") != null)
400  {
401  maxSize = element.GetAttributePoint("maxsize", new Point(1000, 1000));
402  }
403  string sb = element.GetAttributeString("scalebasis", null);
404  if (sb != null)
405  {
406  Enum.TryParse(sb, ignoreCase: true, out scaleBasis);
407  }
408  RectTransform rectTransform;
409  if (element.Attribute("absolutesize") != null)
410  {
411  rectTransform = new RectTransform(element.GetAttributePoint("absolutesize", new Point(1000, 1000)), parent, anchor, pivot, scaleBasis)
412  {
413  minSize = minSize,
414  maxSize = maxSize
415  };
416  }
417  else
418  {
419  rectTransform = new RectTransform(element.GetAttributeVector2("relativesize", Vector2.One), parent, anchor, pivot, minSize, maxSize, scaleBasis);
420  }
421  rectTransform.RelativeOffset = element.GetAttributeVector2("relativeoffset", Vector2.Zero);
422  rectTransform.AbsoluteOffset = element.GetAttributePoint("absoluteoffset", Point.Zero);
423  return rectTransform;
424  }
425 
426  private void Init(RectTransform parent = null, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null)
427  {
428  this.parent = parent;
429  parent?.children.Add(this);
430  Anchor = anchor;
431  Pivot = pivot ?? MatchPivotToAnchor(Anchor);
432  }
433  #endregion
434 
435  #region Protected methods
436  protected void RecalculateScale()
437  {
438  var scale = LocalScale * globalScale;
439  var parents = GetParents();
440  Scale = parents.Any() ? parents.Select(rt => rt.LocalScale).Aggregate((parent, child) => parent * child) * scale : scale;
441  recalculateRect = true;
442  ScaleChanged?.Invoke();
443  }
444 
445  protected void RecalculatePivotOffset()
446  {
448  recalculateRect = true;
449  }
450 
451  protected void RecalculateAnchorPoint()
452  {
454  recalculateRect = true;
455  }
456 
457  protected void RecalculateRelativeSize()
458  {
459  relativeSize = new Vector2(NonScaledSize.X, NonScaledSize.Y) / new Vector2(NonScaledParentUIRect.Width, NonScaledParentUIRect.Height);
460  recalculateRect = true;
461  SizeChanged?.Invoke();
462  }
463 
464  protected void RecalculateAbsoluteSize()
465  {
466  Point size = NonScaledParentUIRect.Size;
467  switch (ScaleBasis)
468  {
469  case ScaleBasis.BothWidth:
470  size.Y = size.X;
471  break;
472  case ScaleBasis.BothHeight:
473  size.X = size.Y;
474  break;
475  case ScaleBasis.Smallest:
476  if (size.X < size.Y)
477  {
478  size.Y = size.X;
479  }
480  else
481  {
482  size.X = size.Y;
483  }
484  break;
485  case ScaleBasis.Largest:
486  if (size.X > size.Y)
487  {
488  size.Y = size.X;
489  }
490  else
491  {
492  size.X = size.Y;
493  }
494  break;
495  }
496  size = size.Multiply(RelativeSize);
497  nonScaledSize = size.Clamp(MinSize, MaxSize);
498  recalculateRect = true;
499  SizeChanged?.Invoke();
500  }
501 
507  public bool IsFixedSize { get; set; }
508 
509  protected void RecalculateAll(bool resize, bool scale = true, bool withChildren = true)
510  {
511  if (scale)
512  {
514  }
515  if (resize && !IsFixedSize)
516  {
518  }
521  if (withChildren)
522  {
523  RecalculateChildren(resize, scale);
524  }
525  }
526 
527  private bool RemoveFromHierarchy(bool displayErrors = true)
528  {
529  if (Parent == null)
530  {
531  if (displayErrors)
532  {
533  DebugConsole.ThrowError("Parent null" + Environment.StackTrace.CleanupStackTrace());
534  }
535  return false;
536  }
537  if (!Parent.children.Contains(this))
538  {
539  if (displayErrors)
540  {
541  DebugConsole.ThrowError("The children of the parent does not contain this child. This should not be possible! " + Environment.StackTrace.CleanupStackTrace());
542  }
543  return false;
544  }
545  if (!Parent.children.Remove(this))
546  {
547  if (displayErrors)
548  {
549  DebugConsole.ThrowError("Unable to remove the child from the parent. " + Environment.StackTrace.CleanupStackTrace());
550  }
551  return false;
552  }
553  return true;
554  }
555  #endregion
556 
557  #region Public instance methods
558  public void SetPosition(Anchor anchor, Pivot? pivot = null)
559  {
560  Anchor = anchor;
561  Pivot = pivot ?? MatchPivotToAnchor(anchor);
562  ScreenSpaceOffset = Point.Zero;
563  recalculateRect = true;
564  RecalculateChildren(false, false);
565  }
566 
567  public void Resize(Point absoluteSize, bool resizeChildren = true)
568  {
569  nonScaledSize = absoluteSize.Clamp(MinSize, MaxSize);
571  RecalculateAll(resize: false, scale: false, withChildren: false);
572  RecalculateChildren(resizeChildren, false);
573  }
574 
575  public void Resize(Vector2 relativeSize, bool resizeChildren = true)
576  {
577  this.relativeSize = relativeSize;
578  RecalculateAll(resize: true, scale: false, withChildren: false);
579  RecalculateChildren(resizeChildren, false);
580  }
581 
582  public void ChangeScale(Vector2 newScale)
583  {
584  LocalScale = newScale;
585  }
586 
587  public void ResetScale()
588  {
589  ChangeScale(Vector2.One);
590  }
591 
596  public void RecalculateScale(bool withChildren)
597  {
599  if (withChildren)
600  {
601  RecalculateChildren(resize: false, scale: true);
602  }
603  }
604 
609  public void Translate(Point translation)
610  {
611  ScreenSpaceOffset += translation;
612  }
613 
617  public IEnumerable<RectTransform> GetParents()
618  {
619  var parents = new List<RectTransform>();
620  if (Parent != null)
621  {
622  parents.Add(Parent);
623  return parents.Concat(Parent.GetParents());
624  }
625  else
626  {
627  return parents;
628  }
629  }
630 
634  public IEnumerable<RectTransform> GetAllChildren()
635  {
636  return children.Concat(children.SelectManyRecursive(c => c.children));
637  }
638 
639  public int GetChildIndex(RectTransform rectT)
640  {
641  return children.IndexOf(rectT);
642  }
643 
644  public RectTransform GetChild(int index)
645  {
646  return children[index];
647  }
648 
649  public bool IsParentOf(RectTransform rectT, bool recursive = true)
650  {
651  if (children.Contains(rectT)) { return true; }
652  if (recursive)
653  {
654  foreach (var child in children)
655  {
656  if (child.IsParentOf(rectT)) { return true; }
657  }
658  }
659  return false;
660  }
661 
662  public bool IsChildOf(RectTransform rectT, bool recursive = true)
663  {
664  if (Parent == null) { return false; }
665  return Parent == rectT || (recursive && Parent.IsChildOf(rectT));
666  }
667 
668  public void ClearChildren()
669  {
670  children.ForEachMod(c => c.Parent = null);
671  }
672 
673  public void SortChildren(Comparison<RectTransform> comparison)
674  {
675  children.Sort(comparison);
676  RecalculateAll(false, false, true);
677  Parent.ChildrenChanged?.Invoke(this);
678  }
679 
680  public void ReverseChildren()
681  {
682  children.Reverse();
683  RecalculateAll(false, false, true);
684  Parent.ChildrenChanged?.Invoke(this);
685  }
686 
687  public void SetAsLastChild()
688  {
689  if (IsLastChild) { return; }
690  if (!RemoveFromHierarchy(displayErrors: true)) { return; }
691  parent.children.Add(this);
692  RecalculateAll(false, true, true);
693  parent.ChildrenChanged?.Invoke(this);
694  }
695 
696  public void SetAsFirstChild()
697  {
698  if (IsFirstChild) { return; }
700  }
701 
702  public bool RepositionChildInHierarchy(int index)
703  {
704  if (!RemoveFromHierarchy(displayErrors: true)) { return false; }
705  try
706  {
707  Parent.children.Insert(index, this);
708  }
709  catch (ArgumentOutOfRangeException e)
710  {
711  DebugConsole.ThrowError(e.ToString());
712  return false;
713  }
714  RecalculateAll(false, true, true);
715  Parent.ChildrenChanged?.Invoke(this);
716  return true;
717  }
718 
719  public void RecalculateChildren(bool resize, bool scale = true)
720  {
721  for (int i = 0; i < children.Count; i++)
722  {
723  children[i].RecalculateAll(resize, scale, withChildren: true);
724  }
725  }
726 
727  public void AddChildrenToGUIUpdateList(bool ignoreChildren = false, int order = 0)
728  {
729  for (int i = 0; i < children.Count; i++)
730  {
731  children[i].GUIComponent.AddToGUIUpdateList(ignoreChildren, order);
732  }
733  }
734 
736 
737 
738  private Point? animTargetPos;
739  public Point AnimTargetPos
740  {
741  get { return animTargetPos ?? AbsoluteOffset; }
742  }
743 
744  public void MoveOverTime(Point targetPos, float duration, Action onDoneMoving = null)
745  {
746  animTargetPos = targetPos;
747  CoroutineManager.StartCoroutine(DoMoveAnimation(targetPos, duration, onDoneMoving));
748  }
749  public void ScaleOverTime(Point targetSize, float duration)
750  {
751  CoroutineManager.StartCoroutine(DoScaleAnimation(targetSize, duration));
752  }
753 
754  private IEnumerable<CoroutineStatus> DoMoveAnimation(Point targetPos, float duration, Action onDoneMoving = null)
755  {
756  Vector2 startPos = AbsoluteOffset.ToVector2();
757  float t = 0.0f;
758  while (t < duration && duration > 0.0f)
759  {
760  t += CoroutineManager.DeltaTime;
761  AbsoluteOffset = Vector2.SmoothStep(startPos, targetPos.ToVector2(), t / duration).ToPoint();
762  yield return CoroutineStatus.Running;
763  }
764  AbsoluteOffset = targetPos;
765  animTargetPos = null;
766  onDoneMoving?.Invoke();
767  yield return CoroutineStatus.Success;
768  }
769  private IEnumerable<CoroutineStatus> DoScaleAnimation(Point targetSize, float duration)
770  {
771  Vector2 startSize = NonScaledSize.ToVector2();
772  float t = 0.0f;
773  while (t < duration && duration > 0.0f)
774  {
775  t += CoroutineManager.DeltaTime;
776  NonScaledSize = Vector2.SmoothStep(startSize, targetSize.ToVector2(), t / duration).ToPoint();
777  yield return CoroutineStatus.Running;
778  }
779  NonScaledSize = targetSize;
780  yield return CoroutineStatus.Success;
781  }
782 
788  {
789  MinSize = new Point(MinSize.X, children.Sum(c => c.MinSize.Y));
790  }
791 
797  {
798  MinSize = new Point(MinSize.X, children.Sum(c => c.Rect.Height));
799  }
800  #endregion
801 
802  #region Static methods
803  public static Pivot MatchPivotToAnchor(Anchor anchor)
804  {
805  return (Pivot)anchor;
806  }
807  public static Anchor MatchAnchorToPivot(Pivot pivot)
808  {
809  return (Anchor)pivot;
810  }
811 
815  public static Anchor MoveAnchorLeft(Anchor anchor)
816  {
817  switch (anchor)
818  {
819  case Anchor.TopCenter:
820  case Anchor.TopRight:
821  return Anchor.TopLeft;
822  case Anchor.Center:
823  case Anchor.CenterRight:
824  return Anchor.CenterLeft;
825  case Anchor.BottomCenter:
826  case Anchor.BottomRight:
827  return Anchor.BottomLeft;
828  default:
829  return anchor;
830  }
831  }
832 
836  public static Anchor MoveAnchorRight(Anchor anchor)
837  {
838  switch (anchor)
839  {
840  case Anchor.TopCenter:
841  case Anchor.TopLeft:
842  return Anchor.TopRight;
843  case Anchor.Center:
844  case Anchor.CenterLeft:
845  return Anchor.CenterRight;
846  case Anchor.BottomCenter:
847  case Anchor.BottomLeft:
848  return Anchor.BottomRight;
849  default:
850  return anchor;
851  }
852  }
853 
857  public static Anchor MoveAnchorTop(Anchor anchor)
858  {
859  switch (anchor)
860  {
861  case Anchor.CenterLeft:
862  case Anchor.BottomLeft:
863  return Anchor.TopLeft;
864  case Anchor.Center:
865  case Anchor.BottomCenter:
866  return Anchor.TopCenter;
867  case Anchor.CenterRight:
868  case Anchor.BottomRight:
869  return Anchor.TopRight;
870  default:
871  return anchor;
872  }
873  }
874 
878  public static Anchor MoveAnchorBottom(Anchor anchor)
879  {
880  switch (anchor)
881  {
882  case Anchor.CenterLeft:
883  case Anchor.TopLeft:
884  return Anchor.BottomLeft;
885  case Anchor.Center:
886  case Anchor.TopCenter:
887  return Anchor.BottomCenter;
888  case Anchor.CenterRight:
889  case Anchor.TopRight:
890  return Anchor.BottomRight;
891  default:
892  return anchor;
893  }
894  }
895 
899  public static Point ConvertOffsetRelativeToAnchor(Point offset, Anchor anchor)
900  {
901  switch (anchor)
902  {
903  case Anchor.BottomRight:
904  return offset.Inverse();
905  case Anchor.BottomLeft:
906  case Anchor.BottomCenter:
907  return new Point(offset.X, -offset.Y);
908  case Anchor.TopRight:
909  case Anchor.CenterRight:
910  return new Point(-offset.X, offset.Y);
911  default:
912  return offset;
913  }
914  }
915 
916  public static Point CalculatePivotOffset(Pivot anchor, Point size)
917  {
918  int width = size.X;
919  int height = size.Y;
920  switch (anchor)
921  {
922  case Pivot.TopLeft:
923  return Point.Zero;
924  case Pivot.TopCenter:
925  return new Point(-width / 2, 0);
926  case Pivot.TopRight:
927  return new Point(-width, 0);
928  case Pivot.CenterLeft:
929  return new Point(0, -height / 2);
930  case Pivot.Center:
931  return size.Divide(2).Inverse();
932  case Pivot.CenterRight:
933  return new Point(-width, -height / 2);
934  case Pivot.BottomLeft:
935  return new Point(0, -height);
936  case Pivot.BottomCenter:
937  return new Point(-width / 2, -height);
938  case Pivot.BottomRight:
939  return new Point(-width, -height);
940  default:
941  throw new NotImplementedException(anchor.ToString());
942  }
943  }
944 
945  public static Point CalculateAnchorPoint(Anchor anchor, Rectangle parent)
946  {
947  switch (anchor)
948  {
949  case Anchor.TopLeft:
950  return parent.Location;
951  case Anchor.TopCenter:
952  return new Point(parent.Center.X, parent.Top);
953  case Anchor.TopRight:
954  return new Point(parent.Right, parent.Top);
955  case Anchor.CenterLeft:
956  return new Point(parent.Left, parent.Center.Y);
957  case Anchor.Center:
958  return parent.Center;
959  case Anchor.CenterRight:
960  return new Point(parent.Right, parent.Center.Y);
961  case Anchor.BottomLeft:
962  return new Point(parent.Left, parent.Bottom);
963  case Anchor.BottomCenter:
964  return new Point(parent.Center.X, parent.Bottom);
965  case Anchor.BottomRight:
966  return new Point(parent.Right, parent.Bottom);
967  default:
968  throw new NotImplementedException(anchor.ToString());
969  }
970  }
971 
981  public static void ResetGlobalScale()
982  {
983  globalScale = Vector2.One;
984  }
985  #endregion
986  }
987 }
static CoroutineStatus Running
static int GraphicsHeight
Definition: GameMain.cs:168
bool IsParentOf(RectTransform rectT, bool recursive=true)
Point ScreenSpaceOffset
Screen space offset. From top left corner. In pixels.
static Anchor MoveAnchorTop(Anchor anchor)
Moves the anchor to the top, keeping the horizontal position unchanged (e.g. BottomCenter -> TopCente...
void SetPosition(Anchor anchor, Pivot? pivot=null)
Point AnchorPoint
Screen space point in pixels.
IEnumerable< RectTransform > GetAllChildren()
Returns all child elements in the hierarchy.
static RectTransform Load(XElement element, RectTransform parent, Anchor defaultAnchor=Anchor.TopLeft)
void RecalculateChildren(bool resize, bool scale=true)
void InheritTotalChildrenHeight()
Sets the minimum height of the transfrom to equal to the sum of the heights of the children (i....
IEnumerable< RectTransform > GetParents()
Returns all parent elements in the hierarchy.
Point AbsoluteOffset
Absolute in pixels but relative to the anchor point. Calculated away from the anchor point,...
Vector2 RelativeSize
Relative to the parent rect.
readonly List< RectTransform > children
void Resize(Point absoluteSize, bool resizeChildren=true)
void InheritTotalChildrenMinHeight()
Sets the minimum height of the transfrom to equal to the sum of the minimum heights of the children (...
Point ScaledSize
Size after scale multiplications.
RectTransform GetChild(int index)
static Anchor MatchAnchorToPivot(Pivot pivot)
IEnumerable< RectTransform > Children
static Anchor MoveAnchorRight(Anchor anchor)
Moves the anchor to the right, keeping the vertical position unchanged (e.g. CenterLeft -> CenterRigh...
RectTransform?? Parent
bool RepositionChildInHierarchy(int index)
Point PivotOffset
Calculated from the selected pivot. In pixels.
void RecalculateScale(bool withChildren)
Currently this needs to be manually called only when the global scale changes. If the local scale cha...
void SortChildren(Comparison< RectTransform > comparison)
Action< RectTransform > ChildrenChanged
The element provided as the argument is the changed child. It may be new in the hierarchy or just rep...
int GetChildIndex(RectTransform rectT)
void MoveOverTime(Point targetPos, float duration, Action onDoneMoving=null)
static Vector2 globalScale
Applied to all RectTransforms. The elements are not automatically resized, if the global scale change...
void Resize(Vector2 relativeSize, bool resizeChildren=true)
void RecalculateAll(bool resize, bool scale=true, bool withChildren=true)
RectTransform(Point absoluteSize, RectTransform parent=null, Anchor anchor=Anchor.TopLeft, Pivot? pivot=null, ScaleBasis scaleBasis=ScaleBasis.Normal, bool isFixedSize=false)
By default, elements defined with an absolute size (in pixels) will scale with the parent....
void Translate(Point translation)
Manipulates ScreenSpaceOffset. If you want to manipulate some other offset, access the property sette...
static void ResetGlobalScale()
The elements are not automatically resized, if the global scale changes. You have to manually call Re...
virtual Rectangle NonScaledUIRect
static Anchor MoveAnchorBottom(Anchor anchor)
Moves the anchor to the bottom, keeping the horizontal position unchanged (e.g. TopCenter -> BottomCe...
void ChangeScale(Vector2 newScale)
RectTransform(Vector2 relativeSize, RectTransform parent, Anchor anchor=Anchor.TopLeft, Pivot? pivot=null, Point? minSize=null, Point? maxSize=null, ScaleBasis scaleBasis=ScaleBasis.Normal)
static Pivot MatchPivotToAnchor(Anchor anchor)
Point?? MinSize
Min size in pixels. Does not affect scaling.
static Point CalculatePivotOffset(Pivot anchor, Point size)
Vector2 RelativeOffset
Defined as portions of the parent size. Also the direction of the offset is relative,...
void AddChildrenToGUIUpdateList(bool ignoreChildren=false, int order=0)
bool IsChildOf(RectTransform rectT, bool recursive=true)
static Point ConvertOffsetRelativeToAnchor(Point offset, Anchor anchor)
Converts the offset so that the direction is always away from the anchor point.
Action< RectTransform > ParentChanged
static Anchor MoveAnchorLeft(Anchor anchor)
Moves the anchor to the left, keeping the vertical position unchanged (e.g. CenterRight -> CenterLeft...
Point NonScaledSize
Size before scale multiplications.
static readonly Point MaxPoint
void ScaleOverTime(Point targetSize, float duration)
Point?? MaxSize
Max size in pixels. Does not affect scaling.
bool IsFixedSize
If false, the element will resize if the parent is resized (with the children). If true,...
static Point CalculateAnchorPoint(Anchor anchor, Rectangle parent)