/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
- using Delta.Engine;
- using Delta.Rendering.Basics.Drawing;
- using Delta.Rendering.Basics.Fonts;
- using Delta.Utilities.Datatypes;
- using NUnit.Framework;
-
- namespace Delta.InputSystem.Tests
- {
- /// <summary>
- /// Mouse tests
- /// </summary>
- internal class MouseTests
- {
- #region MouseStates
- /// <summary>
- /// Check mouse states
- /// </summary>
- [Test, Category("Visual")]
- public static void MouseStates()
- {
- Font infoFont = Font.Default;
- Application.Start(delegate
- {
- infoFont.Draw("Mouse IsConnected " + Input.Mouse.IsConnected,
- Rectangle.FromCenter(new Point(0.5f, 0.4f), Size.Half));
- infoFont.Draw(
- "Left " + Input.Mouse.GetState(InputButton.MouseLeft),
- Rectangle.FromCenter(new Point(0.5f, 0.45f), Size.Half));
- infoFont.Draw(
- "Right " + Input.Mouse.GetState(InputButton.MouseRight),
- Rectangle.FromCenter(new Point(0.5f, 0.5f), Size.Half));
- infoFont.Draw("Position " + Input.Mouse.Position,
- Rectangle.FromCenter(new Point(0.5f, 0.55f), Size.Half));
-
- // Also test set mouse position with right mouse button
- if (Input.Mouse.RightButtonReleased)
- {
- Input.Mouse.Position = ScreenSpace.DrawArea.TopLeft;
- }
- // Show mouse position (useful for MultiMouse tweaking)
- Circle.DrawFilled(Input.Mouse.Position, 0.01f, Color.Red);
- });
- }
- #endregion
-
- #region HighFpsMouseUpdating
- /// <summary>
- /// Test high fps mouse updating. Optimized in a way so we should see and
- /// check the performance of the native mouse implementation class. When I
- /// say high fps, this is in the range of 2 million (with XnaMouse) up to
- /// 10 million (with WindowsMouse) frames per second, really really good!
- /// </summary>
- [Test, Category("Visual")]
- public static void HighFpsMouseUpdating()
- {
- Application.Start(delegate
- {
- if (Input.Mouse.LeftButtonReleased)
- {
- //too slow, will get us down to 10 000 fps, which is still nice, but
- // not as useful for testing the input performance:
- //Graphic.InfoFont.Write(new Point(0.5f, 0.5f), "click");
- Application.BackgroundColor = Color.Random;
- }
- });
- }
- #endregion
-
- #region VeryLowFrameRateMouse
- /// <summary>
- /// Check mouse states
- /// </summary>
- [Test, Category("Visual")]
- public static void VeryLowFrameRateMouse()
- {
- // Limit the framerate to 2 fps
- Settings.Extra.LimitFramerateNumber = 2;
-
- Font infoFont = Font.Default;
- Application.Start(delegate
- {
- infoFont.Draw("Mouse IsConnected " + Input.Mouse.IsConnected,
- Rectangle.FromCenter(new Point(0.5f, 0.4f), Size.Half));
- infoFont.Draw("Left " + Input.Mouse.GetState(InputButton.MouseLeft),
- Rectangle.FromCenter(new Point(0.5f, 0.45f), Size.Half));
- infoFont.Draw("Right " + Input.Mouse.GetState(InputButton.MouseRight),
- Rectangle.FromCenter(new Point(0.5f, 0.5f), Size.Half));
- infoFont.Draw("Position " + Input.Mouse.Position,
- Rectangle.FromCenter(new Point(0.5f, 0.55f), Size.Half));
- infoFont.Draw(
- "MouseMiddle " + Input.Mouse.GetState(InputButton.MouseMiddle),
- Rectangle.FromCenter(new Point(0.5f, 0.6f), Size.Half));
- infoFont.Draw(
- "MouseScrollWheel " +
- Input.Mouse.GetState(InputButton.MouseScrollWheel),
- Rectangle.FromCenter(new Point(0.5f, 0.65f), Size.Half));
- });
- }
- #endregion
-
- #region ShowAndHideMouseCursor
- /// <summary>
- /// Test show and hide mouse cursor
- /// </summary>
- [Test, Category("Visual")]
- public static void ShowAndHideMouseCursor()
- {
- Application.Start(delegate
- {
- Font.Default.Draw(
- "Left click to show mouse cursor, right click to hide!",
- Rectangle.FromCenter(new Point(0.5f, 0.5f), Size.Half));
-
- if (Input.Mouse.LeftButtonReleased)
- {
- Application.Window.ShowCursor();
- } // if
- else if (Input.Mouse.RightButtonReleased)
- {
- Application.Window.HideCursor();
- } // else if
-
- // Always show the position of the mouse however!
- Circle.DrawOutline(Input.Mouse.Position, 0.05f, Color.Yellow);
- });
- }
- #endregion
-
- }
- }
-