PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/InputSystem/Tests/MultiMice.cs

#
C# | 141 lines | 112 code | 17 blank | 12 comment | 1 complexity | a3d7dda3d707a3c3b4b024b521345d23 MD5 | raw file
Possible License(s): Apache-2.0
  1. using Delta.Engine;
  2. using Delta.InputSystem.Devices;
  3. using Delta.Rendering.Basics.Drawing;
  4. using Delta.Rendering.Basics.Fonts;
  5. using Delta.Utilities;
  6. using Delta.Utilities.Datatypes;
  7. using NUnit.Framework;
  8. namespace Delta.InputSystem.Tests
  9. {
  10. /// <summary>
  11. /// This class deals with a multiple mouse input (Connecting more than one
  12. /// mouse at once and make all the input from these various devices usable.
  13. /// </summary>
  14. internal class MultiMice
  15. {
  16. #region TestMultipleMice (Static)
  17. /// <summary>
  18. /// Test multiple mice
  19. /// </summary>
  20. [Test, Category("Visual")]
  21. public static void TestMultipleMice()
  22. {
  23. Application.BackgroundColor = Color.Black;
  24. Font infoFont = Font.Default;
  25. Application.Start(delegate
  26. {
  27. infoFont.Draw("Mouse 1 IsConnected " + Input.Mouse.IsConnected,
  28. Rectangle.FromCenter(new Point(0.5f, 0.2f), Size.Half));
  29. infoFont.Draw(
  30. "Mouse 1 Left " + Input.Mouse.GetState(InputButton.MouseLeft),
  31. Rectangle.FromCenter(new Point(0.5f, 0.23f), Size.Half));
  32. infoFont.Draw(
  33. "Mouse 1 Right " + Input.Mouse.GetState(InputButton.MouseRight),
  34. Rectangle.FromCenter(new Point(0.5f, 0.26f), Size.Half));
  35. infoFont.Draw("Mouse 1 Position " + Input.Mouse.Position,
  36. Rectangle.FromCenter(new Point(0.5f, 0.29f), Size.Half));
  37. infoFont.Draw(
  38. "Mouse 1 MouseTap " + Input.Mouse.GetState(InputButton.GestureTap),
  39. Rectangle.FromCenter(new Point(0.5f, 0.32f), Size.Half));
  40. infoFont.Draw(
  41. "Mouse 2 IsConnected " + Input.Mice(1).IsConnected,
  42. Rectangle.FromCenter(new Point(0.5f, 0.37f), Size.Half));
  43. infoFont.Draw(
  44. "Mouse 2 Left " + Input.Mice(1).GetState(InputButton.MouseLeft),
  45. Rectangle.FromCenter(new Point(0.5f, 0.4f), Size.Half));
  46. infoFont.Draw(
  47. "Mouse 2 Right " + Input.Mice(1).GetState(InputButton.MouseRight),
  48. Rectangle.FromCenter(new Point(0.5f, 0.43f), Size.Half));
  49. infoFont.Draw("Mouse 2 Position " + Input.Mice(1).Position,
  50. Rectangle.FromCenter(new Point(0.5f, 0.46f), Size.Half));
  51. infoFont.Draw(
  52. "Mouse 2 MouseTap " + Input.Mice(1).GetState(InputButton.GestureTap),
  53. Rectangle.FromCenter(new Point(0.5f, 0.49f), Size.Half));
  54. infoFont.Draw(
  55. "Mouse 3 IsConnected " + Input.Mice(2).IsConnected,
  56. Rectangle.FromCenter(new Point(0.5f, 0.54f), Size.Half));
  57. infoFont.Draw(
  58. "Mouse 3 Left " + Input.Mice(2).GetState(InputButton.MouseLeft),
  59. Rectangle.FromCenter(new Point(0.5f, 0.57f), Size.Half));
  60. infoFont.Draw(
  61. "Mouse 3 Right " + Input.Mice(2).GetState(InputButton.MouseRight),
  62. Rectangle.FromCenter(new Point(0.5f, 0.6f), Size.Half));
  63. infoFont.Draw("Mouse 3 Position " + Input.Mice(2).Position,
  64. Rectangle.FromCenter(new Point(0.5f, 0.63f), Size.Half));
  65. });
  66. }
  67. #endregion
  68. #region TestSeveralMiceInput (Static)
  69. /// <summary>
  70. /// Test several mice input
  71. /// </summary>
  72. [Test, Category("Visual")]
  73. public static void TestSeveralMiceInput()
  74. {
  75. Color[] miceColors = new[]
  76. {
  77. Color.Red,
  78. Color.Yellow,
  79. Color.White,
  80. Color.Green,
  81. };
  82. string clickMessage = "no click yet";
  83. Application.BackgroundColor = Color.Black;
  84. Application.Start(delegate
  85. {
  86. // We need to init the mouse at the first time
  87. Assert.NotNull(Input.Mouse);
  88. Font font = Font.Default;
  89. float textLineGap = font.LineHeight * 1.1f;
  90. float yTextPos = 0.2f;
  91. for (int index = 0; index < Input.MaxNumberOfMice; index++)
  92. {
  93. BaseMouse mouse = Input.Mice(index);
  94. Assert.NotNull(mouse);
  95. string mouseName = "Mouse " + (index + 1);
  96. font.Draw(mouseName + " IsConnected " + mouse.IsConnected,
  97. Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
  98. yTextPos += textLineGap;
  99. font.Draw(mouseName + " Position " + mouse.Position,
  100. Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
  101. yTextPos += textLineGap;
  102. font.Draw(mouseName + " ScrollValue " + mouse.TotalScrollWheel,
  103. Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
  104. yTextPos += textLineGap;
  105. font.Draw(
  106. mouseName + " Left " + mouse.GetState(InputButton.MouseLeft),
  107. Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
  108. yTextPos += textLineGap;
  109. font.Draw(
  110. mouseName + " Right " + mouse.GetState(InputButton.MouseRight),
  111. Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
  112. yTextPos += textLineGap;
  113. yTextPos += textLineGap;
  114. // Also draw both mouse cursors as circles
  115. Circle.DrawOutline(mouse.Position, 0.025f, miceColors[index]);
  116. } // for
  117. font.Draw(clickMessage,
  118. Rectangle.FromCenter(new Point(0.5f,
  119. ScreenSpace.DrawArea.Bottom - textLineGap), Size.Half));
  120. });
  121. }
  122. #endregion
  123. }
  124. }