PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/InputSystem/Tests/GestureTests.cs

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