CrabUI
Loading...
Searching...
No Matches
CUIComponent.State.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Diagnostics;
6using System.Runtime.CompilerServices;
7using System.IO;
8
9using Barotrauma;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Input;
12using Microsoft.Xna.Framework.Graphics;
13
14using System.Xml;
15using System.Xml.Linq;
16using HarmonyLib;
17
18namespace CrabUI
19{
20 public partial class CUIComponent : IDisposable
21 {
22 /// <summary>
23 /// Global ID, unique for component
24 /// </summary>
25 public int ID { get; set; }
26
27 internal bool DebugHighlight { get; set; }
28
29 private CUIMainComponent mainComponent;
30 /// <summary>
31 /// Link to CUIMainComponent, passed to children
32 /// </summary>
34 {
35 get => mainComponent;
36 set
37 {
38 mainComponent = value;
39 foreach (var child in Children) { child.MainComponent = value; }
40 }
41 }
42
43 internal int positionalZIndex;
44 internal int addedZIndex;
45
46 [Calculated] public bool Focused { get; set; }
47
48 /// <summary>
49 /// True when parent has HideChildrenOutsideFrame and child wanders beyond parents border
50 /// </summary>
51 [Calculated] internal bool CulledOut { get; set; }
52
53 /// <summary>
54 /// BackgroundColor != Color.Transparent
55 /// </summary>
56 protected bool BackgroundVisible { get; set; }
57
58 protected bool OutlineVisible { get; set; }
59
60 // This is for state clones, to protect them from style changes
61 private bool unreal;
62 internal bool Unreal
63 {
64 get => unreal;
65 set
66 {
67 unreal = value;
68 foreach (var child in Children) { child.Unreal = value; }
69 }
70 }
71
72 public bool MouseOver { get; set; }
73 public bool MousePressed { get; set; }
74
75 /// <summary>
76 /// This is used by text to prevent resizing beyond that
77 /// and works as AbsoluteMin
78 /// </summary>
79 [Calculated]
81 {
82 get => forsedSize;
83 set => SetForcedMinSize(value);
84 }
85 protected CUINullVector2 forsedSize; internal void SetForcedMinSize(CUINullVector2 value, [CallerMemberName] string memberName = "")
86 {
87 forsedSize = value;
88 CUIDebug.Capture(null, this, "SetForcedMinSize", memberName, "ForcedMinSize", ForcedMinSize.ToString());
89 OnPropChanged();//TODO this is the reason why lists with a lot of children lag
90 //OnSelfAndParentChanged();
91 OnAbsolutePropChanged();
92 }
93
94 /// <summary>
95 /// This is set by ChildrenOffset when zooming, and iirc consumed by text to adjust text scale
96 /// </summary>
97 [Calculated]
98 public float Scale
99 {
100 get => scale;
101 set => SetScale(value);
102 }
103 protected float scale = 1f; internal void SetScale(float value, [CallerMemberName] string memberName = "")
104 {
105 scale = value;
106 foreach (var child in Children) { child.Scale = value; }
107 // OnDecorPropChanged();
108 }
109
110 /// <summary>
111 /// Calculated Prop, Real + BorderThickness
112 /// </summary>
113 protected CUIRect BorderBox { get; set; }
114 protected CUIRect OutlineBox { get; set; }
115 internal Rectangle? ScissorRect { get; set; }
116 /// <summary>
117 /// Buffer for texture data, for IgnoreTransparent checks
118 /// </summary>
119 protected Color[] TextureData;
120 /// <summary>
121 /// Calculated prop, position on real screen in pixels
122 /// Should be fully calculated after CUIMainComponent.Update
123 /// </summary>
124 [Calculated]
126 {
127 get => real;
128 set => SetReal(value);
129 }
130
131
132
133 private CUIRect real; internal void SetReal(CUIRect value, [CallerMemberName] string memberName = "")
134 {
135 //HACK idk if i need it
136 real = new CUIRect(
137 (float)Math.Round(value.Left),
138 (float)Math.Round(value.Top),
139 (float)Math.Round(value.Width),
140 (float)Math.Round(value.Height)
141 );
142 // real = value;
143 CUIDebug.Capture(null, this, "SetReal", memberName, "real", real.ToString());
144
145
146 BorderBox = real;
147 // BorderBox = new CUIRect(
148 // real.Left - BorderThickness,
149 // real.Top - BorderThickness,
150 // real.Width + 2 * BorderThickness,
151 // real.Height + 2 * BorderThickness
152 // );
153
154 OutlineBox = new CUIRect(
155 real.Left - OutlineThickness,
156 real.Top - OutlineThickness,
157 real.Width + 2 * OutlineThickness,
158 real.Height + 2 * OutlineThickness
159 );
160
162 {
163 Rectangle SRect = real.Box;
164
165 // //HACK Remove these + 1
166 // Rectangle SRect = new Rectangle(
167 // (int)real.Left + 1,
168 // (int)real.Top + 1,
169 // (int)real.Width - 2,
170 // (int)real.Height - 2
171 // );
172
173 if (Parent?.ScissorRect != null)
174 {
175 ScissorRect = Rectangle.Intersect(Parent.ScissorRect.Value, SRect);
176 }
177 else
178 {
179 ScissorRect = SRect;
180 }
181 }
182 else ScissorRect = Parent?.ScissorRect;
183 }
184 }
185}
Color[] TextureData
Buffer for texture data, for IgnoreTransparent checks.
CUINullVector2 ForcedMinSize
This is used by text to prevent resizing beyond that and works as AbsoluteMin.
CUIRect BorderBox
Calculated Prop, Real + BorderThickness.
CUIMainComponent MainComponent
Link to CUIMainComponent, passed to children.
bool BackgroundVisible
BackgroundColor != Color.Transparent.
bool HideChildrenOutsideFrame
Should children be cut off by scissor rect, this is just visual, it's not the same as culling.
CUIRect Real
Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent....
int ID
Global ID, unique for component.
float Scale
This is set by ChildrenOffset when zooming, and iirc consumed by text to adjust text scale.
Orchestrating drawing and updating of it's children Also a CUIComponent, but it's draw and update m...
Vector2, but with float?
Rectangle with float.
Definition CUIRect.cs:17