-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUIView.cs
240 lines (192 loc) · 5.53 KB
/
GUIView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rigel.GUI
{
public class GUIViewBufferInfo
{
}
public class GUIView
{
public GUILayer Layer { get; internal set; }
internal GUIView Parent { get; set; } = null;
public GUIViewBufferInfo BufferInfo = null;
public List<GUIView> m_childrens = null;
public Vector4 Rect;
public Vector4 ContentRect;
public GUIContent Content { get; protected set; } = null;
public int Order = 0;
public bool IsFocused
{
get
{
if (Layer == null) return false;
return Layer.m_focusedView == this;
}
}
public bool HasChild
{
get { return m_childrens != null && m_childrens.Count != 0; }
}
public void RemoveFocused()
{
}
public virtual void SetContent(GUIContent content)
{
Content = content;
Content.View = this;
}
private bool m_debug = false;
private string m_debugName = "";
private Vector4 m_color = RigelColor.Random();
public GUIView(string debugName = null)
{
if (!string.IsNullOrEmpty(debugName))
{
m_debug = true;
m_debugName = debugName;
}
}
public void SetDebugName(string debugName)
{
m_debugName = debugName;
m_debug = true;
}
public void SetOrderFocused()
{
if(Parent != null)
{
Order = 10000;
Parent.SetOrderFocused();
}
}
public int SyncOrder(int baseOrder)
{
if (HasChild)
{
Order = baseOrder + 1;
m_childrens.Sort((a, b) => { return a.Order.CompareTo(b.Order); });
int orderMax = Order;
for(var i=0;i< m_childrens.Count; i++)
{
orderMax = m_childrens[i].SyncOrder(orderMax)+1;
}
return orderMax;
}
else
{
Order = baseOrder + 1;
return Order;
}
}
public bool CheckFocused(RigelGUIEvent e)
{
if (Layer == null) throw new Exception();
if (HasChild)
{
for(var i= m_childrens.Count-1; i>=0; i--)
{
//fix layer
if (m_childrens[i].Layer == null) m_childrens[i].Layer = Layer;
if (m_childrens[i].CheckFocused(e))
{
return true;
}
}
if (GUIUtility.RectContainsCheck(Rect, e.Pointer))
{
Layer.m_focusedView = this;
return true;
}
}
else
{
if (GUIUtility.RectContainsCheck(Rect, e.Pointer))
{
Layer.m_focusedView = this;
return true;
}
}
return false;
}
public virtual void Update(RigelGUIEvent e)
{
if(Content == null)
{
if (m_debug)
{
m_color = RigelColor.Random();
GUI.RectAbsolute(Rect, m_color);
}
}
else
{
Content.OnGUI(e);
}
}
public virtual void OnViewStart()
{
ContentRect = Rect.Padding(1);
GUI.BeginArea(ContentRect);
}
public virtual void OnViewEnd()
{
GUI.EndArea();
}
public virtual void OnDynamicDraw(RigelGUIEvent e)
{
}
internal void InternalUpdate(RigelGUIEvent e,GUIView exclude = null,bool onlyself = false)
{
if (exclude != this)
{
GUI.StartGUIView(this);
Update(e);
GUI.EndGUIView(this);
}
if (onlyself) return;
if(m_childrens != null)
{
for(var i = 0; i < m_childrens.Count; i++)
{
var cview = m_childrens[i];
if(cview.Layer == null)
{
cview.Layer = Layer;
}
cview.InternalUpdate(e, exclude);
}
}
}
public bool AddSubView(GUIView view)
{
if (m_childrens == null) m_childrens = new List<GUIView>();
if (m_childrens.Contains(view))
{
return true;
}
if(view.Parent != null)
{
view.Parent.RemoveSubView(view);
}
m_childrens.Add(view);
view.Parent = this;
if(Layer != null)view.Layer = Layer;
return true;
}
public bool RemoveSubView(GUIView view)
{
if (m_childrens == null) return false;
if (!m_childrens.Contains(view))
{
return false;
}
m_childrens.Remove(view);
view.Layer = null;
view.Parent = null;
return true;
}
}
}