aboutsummaryrefslogtreecommitdiffstatsci
path: root/Tests/GOLIBTests.cs
blob: 53f36590b4828e6b00362fc562aa58efede47037 (plain)
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#define MONO_CAIRO_DEBUG_DISPOSE


using System;
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;

using System.Diagnostics;

//using GGL;
using Crow;
using System.Threading;
using System.Collections.Generic;
using System.Linq;


namespace test
{
	class GOLIBTests : OpenTKGameWindow, IValueChange
	{
		#region IValueChange implementation
		public event EventHandler<ValueChangeEventArgs> ValueChanged;
		public virtual void NotifyValueChanged(string MemberName, object _value)
		{
			ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value));			
		}
		#endregion

		public GOLIBTests ()
			: base(800, 600,"test: press spacebar to toogle test files")
		{
			//VSync = VSyncMode.Off;
			Interface.CurrentInterface = CrowInterface;
			GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]);
			obj.DataSource = this;

		}

		int frameCpt = 0;
		int idx = 0;
		string[] testFiles = {
			"testMsgBox.goml",
			"testCombobox.goml",
			"testExpandable.goml",
			"test_Listbox.goml",
			"6.crow",
			"testGroupBox.goml",
			"1.crow",
			"5.crow",
			"testCheckbox.goml",
			"testWindow.goml",
			"fps.goml",
			"testTabView.crow",
			"0.crow",
			"testImage.crow",
			"testOutOfClipUpdate.crow",
//			"test_Listbox.goml",
//			"testTreeView.crow",
			"1.crow",
			"clip4.crow",
			"clip3.crow",
			"clip2.crow",
			"clip0.crow",
			"clip1.crow",
			"testPopper.goml",
			"testTextBox.crow",
			"testColorList.crow",
//			"5.crow",
//			"testCombobox.goml",
//			"testPopper.goml",
			"testTextBox.crow",
//			"testColorList.crow",
			"4.crow",
			"testSpinner.goml",
			"testScrollbar.goml",
			"testGrid.goml",
			"testButton.crow",
			"testBorder.goml",
//			"testButton2.crow",
			"test2WayBinding.crow",
			"test4.goml",
			"2.crow",
			"test1.goml",
			"testWindow2.goml",

			"testWindow3.goml",
			"testLabel.goml",
			"testAll.goml",
//			"testSpinner.goml",
//			"testRadioButton2.goml",
			"testContainer.goml",
			"testRadioButton.goml",

//			"testMeter.goml",
		};

		#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));
				#if MEASURE_TIME
				ValueChanged.Raise (this, new ValueChangeEventArgs ("update",
					this.CrowInterface.updateTime.ElapsedTicks.ToString () + " ticks"));
				ValueChanged.Raise (this, new ValueChangeEventArgs ("layouting",
					this.CrowInterface.layoutTime.ElapsedTicks.ToString () + " ticks"));
				ValueChanged.Raise (this, new ValueChangeEventArgs ("drawing",
					this.CrowInterface.drawingTime.ElapsedTicks.ToString () + " ticks"));
				#endif
			}
		}

		public int fpsMin = int.MaxValue;
		public int fpsMax = 0;

		void resetFps ()
		{
			fpsMin = int.MaxValue;
			fpsMax = 0;
			_fps = 0;
		}
		public string update = "";
		public string drawing = "";
		public string layouting = "";
		public Alignment alignment = Alignment.Left;
		#endregion

		public int intValue = 25;

		public int IntValue {
			get {
				return intValue;
			}
			set {
				intValue = value;
				NotifyValueChanged ("IntValue", intValue);
			}
		}
		void onSpinnerValueChange(object sender, ValueChangeEventArgs e){
			if (e.MemberName != "Value")
				return;
			intValue = Convert.ToInt32(e.NewValue);
		}
		void change_alignment(object sender, EventArgs e){
			RadioButton rb = sender as RadioButton;
			if (rb == null)
				return;
			NotifyValueChanged ("alignment", Enum.Parse(typeof(Alignment), rb.Caption));
		}
		public IList<String> List2 = new List<string>(new string[]
			{
				"string1",
				"string2",
				"string3",
				"string4",
				"string5",
				"string6",
				"string7",
				"string8",
				"string8",
				"string8",
				"string8",
				"string8",
				"string8",
				"string9"
			}
		);
		IList<Color> testList = Color.ColorDic.ToList();
		public IList<Color> TestList {
			set{
				testList = value;
				NotifyValueChanged ("TestList", testList);
			}
			get { return testList; }
		}
		void OnClear (object sender, MouseButtonEventArgs e) => TestList = null;

		void OnLoadList (object sender, MouseButtonEventArgs e) {
			TestList = Color.ColorDic.ToList();
		}

		void GOLIBTests_KeyboardKeyDown1 (object sender, OpenTK.Input.KeyboardKeyEventArgs e)
		{
			if (e.Key == OpenTK.Input.Key.Escape) {
				Quit (null, null);
				return;
			} else if (e.Key == OpenTK.Input.Key.L) {
				TestList.Add ("new string");
				NotifyValueChanged ("TestList", TestList);
				return;
			} else if (e.Key == OpenTK.Input.Key.W) {
				GraphicObject w = CrowInterface.LoadInterface("Interfaces/testWindow.goml");
				w.DataSource = this;
				return;
			}
			CrowInterface.ClearInterface ();
			idx++;
			if (idx == testFiles.Length)
				idx = 0;
			this.Title = testFiles [idx];
			GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]);
			obj.DataSource = this;
		}

//		protected override void OnUpdateFrame (FrameEventArgs e)
//		{
//			//if (frameCpt % 8 == 0)
//				base.OnUpdateFrame (e);
//
//			fps = (int)RenderFrequency;
//
//
//			if (frameCpt > 50) {
//				resetFps ();
//				frameCpt = 0;
//				GC.Collect();
//				GC.WaitForPendingFinalizers();
//				NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString());
//			}
//			frameCpt++;
//		}
		void onButClick(object send, MouseButtonEventArgs e)
		{
			Console.WriteLine ("button clicked:" + send.ToString());
		}
		void onAddTabButClick(object sender, MouseButtonEventArgs e){
			
			TabView tv = CrowInterface.FindByName("tabview1") as TabView;
			if (tv == null)
				return;
			tv.AddChild (new TabItem () { Caption = "NewTab" });
		}
		[STAThread]
		static void Main ()
		{
			Console.WriteLine ("starting example");
			Gtk.Application.Init ();
			GOLIBTests win = new GOLIBTests ();
			win.KeyPressEvent += win.Win_KeyPressEvent;

			Gtk.Application.Run ();
		}
		void onMsgBoxOk(object sender, EventArgs e){
			Debug.WriteLine ("OK");
		}
		void onMsgBoxCancel(object sender, EventArgs e)
		{
			Debug.WriteLine ("cancel");
		}
		void Win_KeyPressEvent (object o, Gtk.KeyPressEventArgs args)
		{
			CrowInterface.ClearInterface ();
			idx++;
			if (idx == testFiles.Length)
				idx = 0;
			this.Title = testFiles [idx];
			GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]);
			obj.DataSource = this;			
		}
	}
}