PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/InputSystem/Tests/MouseTests.cs

#
C# | 131 lines | 96 code | 10 blank | 25 comment | 5 complexity | dd9aa8b81a03a28798629ac8eb475abf 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. /// <summary>
  9. /// Mouse tests
  10. /// </summary>
  11. internal class MouseTests
  12. {
  13. #region MouseStates
  14. /// <summary>
  15. /// Check mouse states
  16. /// </summary>
  17. [Test, Category("Visual")]
  18. public static void MouseStates()
  19. {
  20. Font infoFont = Font.Default;
  21. Application.Start(delegate
  22. {
  23. infoFont.Draw("Mouse IsConnected " + Input.Mouse.IsConnected,
  24. Rectangle.FromCenter(new Point(0.5f, 0.4f), Size.Half));
  25. infoFont.Draw(
  26. "Left " + Input.Mouse.GetState(InputButton.MouseLeft),
  27. Rectangle.FromCenter(new Point(0.5f, 0.45f), Size.Half));
  28. infoFont.Draw(
  29. "Right " + Input.Mouse.GetState(InputButton.MouseRight),
  30. Rectangle.FromCenter(new Point(0.5f, 0.5f), Size.Half));
  31. infoFont.Draw("Position " + Input.Mouse.Position,
  32. Rectangle.FromCenter(new Point(0.5f, 0.55f), Size.Half));
  33. // Also test set mouse position with right mouse button
  34. if (Input.Mouse.RightButtonReleased)
  35. {
  36. Input.Mouse.Position = ScreenSpace.DrawArea.TopLeft;
  37. }
  38. // Show mouse position (useful for MultiMouse tweaking)
  39. Circle.DrawFilled(Input.Mouse.Position, 0.01f, Color.Red);
  40. });
  41. }
  42. #endregion
  43. #region HighFpsMouseUpdating
  44. /// <summary>
  45. /// Test high fps mouse updating. Optimized in a way so we should see and
  46. /// check the performance of the native mouse implementation class. When I
  47. /// say high fps, this is in the range of 2 million (with XnaMouse) up to
  48. /// 10 million (with WindowsMouse) frames per second, really really good!
  49. /// </summary>
  50. [Test, Category("Visual")]
  51. public static void HighFpsMouseUpdating()
  52. {
  53. Application.Start(delegate
  54. {
  55. if (Input.Mouse.LeftButtonReleased)
  56. {
  57. //too slow, will get us down to 10 000 fps, which is still nice, but
  58. // not as useful for testing the input performance:
  59. //Graphic.InfoFont.Write(new Point(0.5f, 0.5f), "click");
  60. Application.BackgroundColor = Color.Random;
  61. }
  62. });
  63. }
  64. #endregion
  65. #region VeryLowFrameRateMouse
  66. /// <summary>
  67. /// Check mouse states
  68. /// </summary>
  69. [Test, Category("Visual")]
  70. public static void VeryLowFrameRateMouse()
  71. {
  72. // Limit the framerate to 2 fps
  73. Settings.Extra.LimitFramerateNumber = 2;
  74. Font infoFont = Font.Default;
  75. Application.Start(delegate
  76. {
  77. infoFont.Draw("Mouse IsConnected " + Input.Mouse.IsConnected,
  78. Rectangle.FromCenter(new Point(0.5f, 0.4f), Size.Half));
  79. infoFont.Draw("Left " + Input.Mouse.GetState(InputButton.MouseLeft),
  80. Rectangle.FromCenter(new Point(0.5f, 0.45f), Size.Half));
  81. infoFont.Draw("Right " + Input.Mouse.GetState(InputButton.MouseRight),
  82. Rectangle.FromCenter(new Point(0.5f, 0.5f), Size.Half));
  83. infoFont.Draw("Position " + Input.Mouse.Position,
  84. Rectangle.FromCenter(new Point(0.5f, 0.55f), Size.Half));
  85. infoFont.Draw(
  86. "MouseMiddle " + Input.Mouse.GetState(InputButton.MouseMiddle),
  87. Rectangle.FromCenter(new Point(0.5f, 0.6f), Size.Half));
  88. infoFont.Draw(
  89. "MouseScrollWheel " +
  90. Input.Mouse.GetState(InputButton.MouseScrollWheel),
  91. Rectangle.FromCenter(new Point(0.5f, 0.65f), Size.Half));
  92. });
  93. }
  94. #endregion
  95. #region ShowAndHideMouseCursor
  96. /// <summary>
  97. /// Test show and hide mouse cursor
  98. /// </summary>
  99. [Test, Category("Visual")]
  100. public static void ShowAndHideMouseCursor()
  101. {
  102. Application.Start(delegate
  103. {
  104. Font.Default.Draw(
  105. "Left click to show mouse cursor, right click to hide!",
  106. Rectangle.FromCenter(new Point(0.5f, 0.5f), Size.Half));
  107. if (Input.Mouse.LeftButtonReleased)
  108. {
  109. Application.Window.ShowCursor();
  110. } // if
  111. else if (Input.Mouse.RightButtonReleased)
  112. {
  113. Application.Window.HideCursor();
  114. } // else if
  115. // Always show the position of the mouse however!
  116. Circle.DrawOutline(Input.Mouse.Position, 0.05f, Color.Yellow);
  117. });
  118. }
  119. #endregion
  120. }
  121. }