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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
#define MONO_CAIRO_DEBUG_DISPOSE
using System;
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using System.Diagnostics;
using Crow;
using System.Threading;
using System.Collections.Generic;
using System.IO;
namespace test
{
class GOLIBTest_4 : OpenTKGameWindow, IValueChange
{
#region IValueChange implementation
public event EventHandler<ValueChangeEventArgs> ValueChanged;
#endregion
public GOLIBTest_4 ()
: base(1024, 800,"test4")
{}
#region FPS
int _fps = 0;
public int fps {
get { return _fps; }
set {
if (_fps == value)
return;
_fps = value;
if (_fps > fpsMax) {
fpsMax = _fps;
ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMax", fpsMax));
} else if (_fps < fpsMin) {
fpsMin = _fps;
ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMin", fpsMin));
}
ValueChanged.Raise(this, new ValueChangeEventArgs ("fps", _fps));
// ValueChanged.Raise (this, new ValueChangeEventArgs ("update",
// this.updateTime.ElapsedMilliseconds.ToString () + " ms"));
}
}
public int fpsMin = int.MaxValue;
public int fpsMax = 0;
void resetFps ()
{
fpsMin = int.MaxValue;
fpsMax = 0;
_fps = 0;
}
public string update = "";
#endregion
GraphicObject c;
ProgressBar pb, pb2;
Label labMousePos, labPb, labF, labA, labH, labFps, labFpsMin, labFpsMax, labV,
labUpdate;
Slider slTest;
Group colors;
public List<ClsItem> TestList = new List<ClsItem>(new ClsItem[]
{
new ClsItem("string 1"),
new ClsItem("string 2")
});
int i = 0;
Color[] colorsArray;
volatile List<GraphicObject> loadedCols = new List<GraphicObject>();
volatile bool allColsLoaded = false;
private static readonly object mutex = new object();
protected override void OnLoad (EventArgs e)
{
base.OnLoad (e);
c = LoadInterface("Interfaces/test4.goml");
//LoadInterface("golibtests/test4.xml", out c2);
//c2.HorizontalAlignment = HorizontalAlignment.Left;
//c2.VerticalAlignment = VerticalAlignment.Top;
//((Color)c.Background).AdjustAlpha (0.5);
// labMousePos = c.FindByName ("labMouse") as Label;
// //pb = c.FindByName("pbBar") as ProgressBar;
// pb2 = c.FindByName("pbBar2") as ProgressBar;
// labPb = c.FindByName ("labPb") as Label;
labF = c.FindByName ("labFocus") as Label;
labA = c.FindByName ("labActive") as Label;
labH = c.FindByName ("labHover") as Label;
// labFps = c.FindByName ("labFps") as Label;
// labFpsMin = c.FindByName ("labFpsMin") as Label;
// labFpsMax = c.FindByName ("labFpsMax") as Label;
// labV = c.FindByName ("labValue") as Label;
// labUpdate = c.FindByName ("labUpdate") as Label;
// slTest = c.FindByName ("slider") as Slider;
colors = c.FindByName ("colors") as Group;
c.MouseMove += pFps_mousemove;
// slTest.ValueChanged += (object sender, ValueChangeEventArgs vce) => {
// labV.Text = vce.NewValue.ToString ("00.00");
// };
colorsArray = Color.ColorDic.ToArray ();
Thread t = new Thread (loadingThread);
t.Start ();
// ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList));
}
void loadingThread()
{
foreach (Color col in colorsArray) {
HorizontalStack s = new HorizontalStack () { Fit = true};
s.HorizontalAlignment = HorizontalAlignment.Left;
Border b = new Border () {
Bounds = new Size (32, 20),
CornerRadius = 5,
Background = col,
BorderWidth = 2,
Foreground = Color.Transparent,
Focusable = true
};
b.MouseEnter += delegate(object sender, MouseMoveEventArgs ee) {
(sender as Border).Foreground = Color.White;
};
b.MouseLeave += delegate(object sender, MouseMoveEventArgs ee) {
(sender as Border).Foreground = Color.Transparent;
};
s.AddChild (b);
s.AddChild (
new Label (col.ToString ()){
Bounds=new Rectangle(0,0,-1,-1),
}
);
i++;
while(true){
lock (mutex) {
loadedCols.Add (s);
break;
}
}
Thread.Sleep (10);
}
allColsLoaded = true;
}
void pFps_mousemove(object sender, MouseMoveEventArgs e)
{
if (!e.Mouse.IsButtonDown (MouseButton.Left)||sender!=c)
return;
clipping.AddRectangle (c.ScreenCoordinates(c.Slot));
c.Left += e.XDelta;
c.Top += e.YDelta;
c.registerForGraphicUpdate ();
}
void onButClick(object send, MouseButtonEventArgs e)
{
Color col = Color.ColorDic.ToArray () [i];
HorizontalStack s = colors.AddChild (new HorizontalStack () { Fit = true});
s.HorizontalAlignment = HorizontalAlignment.Left;
Border b = new Border () {
Bounds = new Size (32, 20),
CornerRadius = 5,
Background = col,
BorderWidth = 2,
Foreground = Color.Transparent,
Focusable = true
};
b.MouseEnter += delegate(object sender, MouseMoveEventArgs ee) {
(sender as Border).Foreground = Color.White;
};
b.MouseLeave += delegate(object sender, MouseMoveEventArgs ee) {
(sender as Border).Foreground = Color.Transparent;
};
s.AddChild (b);
s.AddChild (
new Label (col.ToString ()){
Bounds=new Rectangle(0,0,-1,-1),
}
);
i++;
}
private int frameCpt = 0;
protected override void OnUpdateFrame (FrameEventArgs e)
{
base.OnUpdateFrame (e);
fps = (int)RenderFrequency;
lock (mutex) {
if (loadedCols.Count > 50 || allColsLoaded) {
while (loadedCols.Count > 0) {
colors.AddChild (loadedCols[0]);
loadedCols.RemoveAt (0);
}
}
}
if (frameCpt > 200) {
resetFps ();
frameCpt = 0;
}
frameCpt++;
// if (FocusedWidget==null)
// labF.Text = "- none -";
// else
// labF.Text = FocusedWidget.Name;
//
// if (activeWidget==null)
// labA.Text = "- none -";
// else
// labA.Text = activeWidget.Name;
//
// if (hoverWidget==null)
// labH.Text = "- none -";
// else
// labH.Text = hoverWidget.Name;
}
//public Point MousePosition;
protected override void OnMouseMove (MouseMoveEventArgs e)
{
base.OnMouseMove (e);
//MousePosition = e.Position;
ValueChanged.Raise(this, new ValueChangeEventArgs ("MousePosition", e.Position.ToString()));
}
[STAThread]
static void Main ()
{
Console.WriteLine ("starting example");
using (GOLIBTest_4 win = new GOLIBTest_4( )) {
win.Run (60.0);
}
}
}
}
|