PageRenderTime 123ms CodeModel.GetById 60ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 20ms

/InputSystem/Tests/MouseTests.cs

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