PageRenderTime 211ms CodeModel.GetById 100ms app.highlight 13ms RepoModel.GetById 68ms app.codeStats 0ms

/InputSystem/Tests/GestureTests.cs

#
C# | 289 lines | 243 code | 21 blank | 25 comment | 28 complexity | 1e36695dc517c5f6975ad731f91f9fa9 MD5 | raw file
  1using Delta.Engine;
  2using Delta.Rendering.Basics.Drawing;
  3using Delta.Rendering.Basics.Fonts;
  4using Delta.Utilities.Datatypes;
  5using NUnit.Framework;
  6
  7namespace Delta.InputSystem.Tests
  8{
  9	internal class GestureTests
 10	{
 11		#region GestuerDrag (LongRunning)
 12		/// <summary>
 13		/// TestDrag
 14		/// </summary>
 15		[Test, Category("Visual")]
 16		public static void GestuerDrag()
 17		{
 18			Application.Start(delegate
 19			{
 20				// Change the background color for a better presentation. 
 21				Application.BackgroundColor = Color.Black;
 22				Font.Default.Draw("Drag To Draw",
 23					Rectangle.FromCenter(new Point(0.5f, 0.15f), Size.Half));
 24				Font.Default.Draw(
 25					"Note: if the line disappears it means you are dragging too fast " +
 26					"which turns it into a flick",
 27					Rectangle.FromCenter(new Point(0.5f, 0.175f), Size.Half));
 28
 29				if (Input.Gestures.IsDrag)
 30				{
 31					Line.Draw(Input.Mouse.DragStartPosition,
 32						Input.Mouse.Position, Color.White);
 33				}
 34			});
 35		}
 36		#endregion
 37
 38		#region GestureFlick (LongRunning)
 39		/// <summary>
 40		/// TestFlick
 41		/// </summary>
 42		[Test, Category("Visual")]
 43		public static void GestureFlick()
 44		{
 45			Application.Start(delegate
 46			{
 47				// Change the background color for a better presentation. 
 48				Application.BackgroundColor = Color.Black;
 49				Font.Default.Draw("Flick to change color",
 50					Rectangle.FromCenter(new Point(0.5f, 0.15f), Size.Half));
 51
 52				if (Input.Gestures.IsFlick)
 53				{
 54					Application.BackgroundColor = Color.Random;
 55				}
 56			});
 57		}
 58		#endregion
 59
 60		#region AllGestures (LongRunning)
 61		/// <summary>
 62		/// general test to test all out gestures at the same time
 63		/// </summary>
 64		[Test, Category("Visual")]
 65		public static void AllGestures()
 66		{
 67			// We need a time stamp to allow viewing the green color a gesture happen
 68
 69			#region Flags and Counters
 70			int tapStamp = -1;
 71			int doubleTapSt = -1;
 72			int rotateSt = -1;
 73			int pinchSt = -1;
 74			int flickSt = -1;
 75			bool tap = false;
 76			bool doubleTap = false;
 77			bool pinch = false;
 78			bool flick = false;
 79			bool rotate = false;
 80			#endregion
 81
 82			// Start our application here. 
 83			Application.Start(delegate
 84			{
 85				Application.BackgroundColor = Color.Black;
 86				Font.Default.Draw("Tap",
 87					Rectangle.FromCenter(new Point(0.45f, 0.45f), Size.Half));
 88				Font.Default.Draw("DoubleTap",
 89					Rectangle.FromCenter(new Point(0.45f, 0.475f), Size.Half));
 90				Font.Default.Draw("Hold",
 91					Rectangle.FromCenter(new Point(0.45f, 0.5f), Size.Half));
 92				Font.Default.Draw("Drag",
 93					Rectangle.FromCenter(new Point(0.45f, 0.525f), Size.Half));
 94				Font.Default.Draw("RightDrag(Deacticated)",
 95					Rectangle.FromCenter(new Point(0.45f, 0.55f), Size.Half));
 96				Font.Default.Draw("DualDrag",
 97					Rectangle.FromCenter(new Point(0.45f, 0.575f), Size.Half));
 98				Font.Default.Draw("HorizontalDrag",
 99					Rectangle.FromCenter(new Point(0.45f, 0.6f), Size.Half));
100				Font.Default.Draw("VertiacalDrag",
101					Rectangle.FromCenter(new Point(0.45f, 0.625f), Size.Half));
102				Font.Default.Draw("Rotate",
103					Rectangle.FromCenter(new Point(0.45f, 0.65f), Size.Half));
104				Font.Default.Draw("Pinch",
105					Rectangle.FromCenter(new Point(0.45f, 0.675f), Size.Half));
106				Font.Default.Draw("Flick",
107					Rectangle.FromCenter(new Point(0.45f, 0.7f), Size.Half));
108
109				#region Set Green Light
110				var gesture = Input.Gestures;
111				if (gesture.IsDoubleTap)
112				{
113					doubleTap = true;
114					doubleTapSt = Time.Seconds;
115				}
116				if (gesture.IsTap)
117				{
118					tap = true;
119					tapStamp = Time.Seconds;
120				}
121				if (gesture.IsRotate)
122				{
123					rotate = true;
124					rotateSt = Time.Seconds;
125				}
126				if (gesture.IsPinch)
127				{
128					pinch = true;
129					pinchSt = Time.Seconds;
130				}
131				if (gesture.IsFlick)
132				{
133					flick = true;
134					flickSt = Time.Seconds;
135				}
136				#endregion
137
138
139				#region Tap
140				// Indicator Lights
141				if (tap && (Time.Seconds - tapStamp < 1))
142				{
143					Circle.DrawFilled(new Point(0.65f, 0.45f), 0.01f, Color.Green);
144				}
145				else
146				{
147					Circle.DrawFilled(new Point(0.65f, 0.45f), 0.01f, Color.Red);
148					if (tapStamp > 0)
149					{
150						tapStamp = 0;
151					}
152				}
153				#endregion
154
155				#region DoubleTap
156				if (doubleTap && (Time.Seconds - doubleTapSt < 1))
157				{
158					Circle.DrawFilled(new Point(0.65f, 0.475f), 0.01f, Color.Green);
159				}
160				else
161				{
162					Circle.DrawFilled(new Point(0.65f, 0.475f), 0.01f, Color.Red);
163					if (doubleTapSt > 0)
164					{
165						doubleTapSt = 0;
166					}
167				}
168				#endregion
169
170				#region Hold
171				if (gesture.IsHold)
172				{
173					Circle.DrawFilled(new Point(0.65f, 0.5f), 0.01f, Color.Green);
174				}
175				else
176				{
177					Circle.DrawFilled(new Point(0.65f, 0.5f), 0.01f, Color.Red);
178				}
179				#endregion
180
181				#region Drag
182				// Just a test to see that the buttons are updated as well for the 
183				// Commands
184
185				//if (gesture.IsDrag)
186				if (Input.GetState(InputButton.GestureDrag) == InputState.Released)
187				{
188					Circle.DrawFilled(new Point(0.65f, 0.525f), 0.01f, Color.Green);
189				}
190				else
191				{
192					Circle.DrawFilled(new Point(0.65f, 0.525f), 0.01f, Color.Red);
193				}
194				#endregion
195
196				#region IsRightDrag(Deactivated)
197				//if (Input.Mouse.IsRightDrag)
198				//{
199				//  Circle.DrawFilled(new Point(0.65f, 0.55f), 0.01f, Color.Green);
200				//}
201				//else
202				//{
203				//  Circle.DrawFilled(new Point(0.65f, 0.55f), 0.01f, Color.Red);
204				//}
205				Circle.DrawFilled(new Point(0.65f, 0.55f), 0.01f, Color.Red);
206				#endregion
207
208				#region IsDaulDrag
209				if (gesture.IsDaulDrag)
210				{
211					Circle.DrawFilled(new Point(0.65f, 0.575f), 0.01f, Color.Green);
212				}
213				else
214				{
215					Circle.DrawFilled(new Point(0.65f, 0.575f), 0.01f, Color.Red);
216				}
217				#endregion
218
219				#region IsHorizontalDrag
220				if (gesture.IsHorizontalDrag)
221				{
222					Circle.DrawFilled(new Point(0.65f, 0.6f), 0.01f, Color.Green);
223				}
224				else
225				{
226					Circle.DrawFilled(new Point(0.65f, 0.6f), 0.01f, Color.Red);
227				}
228				#endregion
229
230				#region IsVerticalDrag
231				if (gesture.IsVerticalDrag)
232				{
233					Circle.DrawFilled(new Point(0.65f, 0.625f), 0.01f, Color.Green);
234				}
235				else
236				{
237					Circle.DrawFilled(new Point(0.65f, 0.625f), 0.01f, Color.Red);
238				}
239				#endregion
240
241				#region Rotate
242				if (rotate && (Time.Seconds - rotateSt < 1))
243				{
244					Circle.DrawFilled(new Point(0.65f, 0.65f), 0.01f, Color.Green);
245				}
246				else
247				{
248					Circle.DrawFilled(new Point(0.65f, 0.65f), 0.01f, Color.Red);
249					if (rotateSt > 0)
250					{
251						rotateSt = 0;
252					}
253				}
254				#endregion
255
256				#region Pinch
257				if (pinch && (Time.Seconds - pinchSt < 1))
258				{
259					Circle.DrawFilled(new Point(0.65f, 0.675f), 0.01f, Color.Green);
260				}
261				else
262				{
263					Circle.DrawFilled(new Point(0.65f, 0.675f), 0.01f, Color.Red);
264					if (pinchSt > 0)
265					{
266						pinchSt = 0;
267					}
268				}
269				#endregion
270
271				#region Flick
272				if (flick && (Time.Seconds - flickSt < 1))
273				{
274					Circle.DrawFilled(new Point(0.65f, 0.7f), 0.01f, Color.Green);
275				}
276				else
277				{
278					Circle.DrawFilled(new Point(0.65f, 0.7f), 0.01f, Color.Red);
279					if (flickSt > 0)
280					{
281						flickSt = 0;
282					}
283				}
284				#endregion
285			});
286		}
287		#endregion
288	}
289}