-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathControl.cs
225 lines (192 loc) · 6.78 KB
/
Control.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
using System;
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
namespace OpenTKGUI
{
/// <summary>
/// The basic unit of TKGUI. Describes a gui component that can be drawn and receive events.
/// </summary>
public abstract class Control : IDisposable
{
/// <summary>
/// A convenience function for wrapping the control in a BorderContainer with a uniformly-sized black border.
/// </summary>
public BorderContainer WithBorder(double Size)
{
return this.WithBorder(Size, Size, Size, Size);
}
/// <summary>
/// A convenience function for wrapping the control in a BorderContainer and applying a black border.
/// </summary>
public BorderContainer WithBorder(double Left, double Top, double Right, double Bottom)
{
return this.WithBorder(Color.RGB(0.0, 0.0, 0.0), Left, Top, Right, Bottom);
}
/// <summary>
/// A convenience function for wrapping the control in a BorderContainer and applying a border.
/// </summary>
public BorderContainer WithBorder(Color Color, double Left, double Top, double Right, double Bottom)
{
BorderContainer bc = new BorderContainer(this);
bc.Color = Color;
bc.Set(Left, Top, Right, Bottom);
return bc;
}
/// <summary>
/// A convenience function for wrapping the control in a MarginContainer, applying a uniform margin to the control.
/// </summary>
public MarginContainer WithMargin(double Margin)
{
return new MarginContainer(this, Margin);
}
/// <summary>
/// A convenience function for wrapping the control in an AlignContainer, giving it a target size and aligning it in
/// its container.
/// </summary>
public AlignContainer WithAlign(Point TargetSize, Align HorizontalAlign, Align VerticalAlign)
{
return new AlignContainer(this, TargetSize, HorizontalAlign, VerticalAlign);
}
/// <summary>
/// A convenience function for wrapping the control in an AlignContainer, giving it a target size and aligning it in the center of
/// its container.
/// </summary>
public AlignContainer WithCenterAlign(Point TargetSize)
{
return new AlignContainer(this, TargetSize, Align.Center, Align.Center);
}
/// <summary>
/// Gets the size (in pixels) of this panel when rendered.
/// </summary>
public Point Size
{
get
{
return this._Size;
}
}
/// <summary>
/// Renders the control with the given context.
/// </summary>
/// <remarks>Rendering, when the given context is current, should be done from (0.0, 0.0) to (Size.X, Size.Y).</remarks>
public virtual void Render(GUIRenderContext Context)
{
}
/// <summary>
/// Updates the state of the control after the specified amount of time elapses.
/// </summary>
public virtual void Update(GUIControlContext Context, double Time)
{
}
/// <summary>
/// Updates the state of the control as a root control.
/// </summary>
public void Update(GUIContext Context, double Time)
{
this.Update(Context.CreateRootControlContext(this, new Point(0.0, 0.0)), Time);
}
/// <summary>
/// Resizes this control in a not very nice way that may cause problems. Do not use the function unless
/// you know what you are doing.
/// </summary>
public void ForceResize(Point Size)
{
this._Size = Size;
this.OnResize(Size);
}
/// <summary>
/// Resizes a child control.
/// </summary>
protected void ResizeChild(Control Child, Point Size)
{
Child._Size = Size;
Child.OnResize(Size);
}
/// <summary>
/// Called when the size of the control is forcibly changed.
/// </summary>
protected virtual void OnResize(Point Size)
{
}
/// <summary>
/// Called when the control is cleaning up it's used resources. The control will not be used
/// after this.
/// </summary>
protected virtual void OnDispose()
{
}
/// <summary>
/// Disposes of all resources this control is using along with all its current child controls.
/// </summary>
public void Dispose()
{
this.OnDispose();
}
internal Point _Size;
}
/// <summary>
/// A control that displays a 3D scene.
/// </summary>
public abstract class Render3DControl : Control
{
/// <summary>
/// Sets up the projection matrix for the 3D scene.
/// </summary>
public abstract void SetupProjection(Point Viewsize);
/// <summary>
/// Renders the scene for the control. This may use calls outside of a GUI render context, as long as it
/// resets the GL state to how it was before the render.
/// </summary>
public abstract void RenderScene();
/// <summary>
/// Performs 2D rendering over the scene, for HUDs or overlays.
/// </summary>
public virtual void OverRender(GUIRenderContext Context)
{
}
public sealed override void Render(GUIRenderContext Context)
{
Context.Draw3D(this.SetupProjection, this.RenderScene, this.Size);
this.OverRender(Context);
}
}
/// <summary>
/// A container of a single control that produces some effect or modification on it.
/// </summary>
public class SingleContainer : Control
{
public SingleContainer(Control Client)
{
this._Client = Client;
}
/// <summary>
/// Gets the control that is affected or modified by this container.
/// </summary>
public Control Client
{
get
{
return this._Client;
}
}
public override void Render(GUIRenderContext Context)
{
this._Client.Render(Context);
}
public override void Update(GUIControlContext Context, double Time)
{
this._Client.Update(Context.CreateChildContext(this._Client, new Point(0.0, 0.0)), Time);
}
protected override void OnResize(Point Size)
{
this.ResizeChild(this._Client, Size);
}
protected override void OnDispose()
{
this._Client.Dispose();
}
private Control _Client;
}
}