/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
- using Delta.Engine;
- using Delta.InputSystem.Devices;
- using Delta.Rendering.Basics.Drawing;
- using Delta.Rendering.Basics.Fonts;
- using Delta.Utilities;
- using Delta.Utilities.Datatypes;
- using NUnit.Framework;
-
- namespace Delta.InputSystem.Tests
- {
- /// <summary>
- /// This class deals with a multiple mouse input (Connecting more than one
- /// mouse at once and make all the input from these various devices usable.
- /// </summary>
- internal class MultiMice
- {
- #region TestMultipleMice (Static)
- /// <summary>
- /// Test multiple mice
- /// </summary>
- [Test, Category("Visual")]
- public static void TestMultipleMice()
- {
- Application.BackgroundColor = Color.Black;
-
- Font infoFont = Font.Default;
- Application.Start(delegate
- {
- infoFont.Draw("Mouse 1 IsConnected " + Input.Mouse.IsConnected,
- Rectangle.FromCenter(new Point(0.5f, 0.2f), Size.Half));
- infoFont.Draw(
- "Mouse 1 Left " + Input.Mouse.GetState(InputButton.MouseLeft),
- Rectangle.FromCenter(new Point(0.5f, 0.23f), Size.Half));
- infoFont.Draw(
- "Mouse 1 Right " + Input.Mouse.GetState(InputButton.MouseRight),
- Rectangle.FromCenter(new Point(0.5f, 0.26f), Size.Half));
- infoFont.Draw("Mouse 1 Position " + Input.Mouse.Position,
- Rectangle.FromCenter(new Point(0.5f, 0.29f), Size.Half));
- infoFont.Draw(
- "Mouse 1 MouseTap " + Input.Mouse.GetState(InputButton.GestureTap),
- Rectangle.FromCenter(new Point(0.5f, 0.32f), Size.Half));
-
- infoFont.Draw(
- "Mouse 2 IsConnected " + Input.Mice(1).IsConnected,
- Rectangle.FromCenter(new Point(0.5f, 0.37f), Size.Half));
- infoFont.Draw(
- "Mouse 2 Left " + Input.Mice(1).GetState(InputButton.MouseLeft),
- Rectangle.FromCenter(new Point(0.5f, 0.4f), Size.Half));
- infoFont.Draw(
- "Mouse 2 Right " + Input.Mice(1).GetState(InputButton.MouseRight),
- Rectangle.FromCenter(new Point(0.5f, 0.43f), Size.Half));
- infoFont.Draw("Mouse 2 Position " + Input.Mice(1).Position,
- Rectangle.FromCenter(new Point(0.5f, 0.46f), Size.Half));
- infoFont.Draw(
- "Mouse 2 MouseTap " + Input.Mice(1).GetState(InputButton.GestureTap),
- Rectangle.FromCenter(new Point(0.5f, 0.49f), Size.Half));
-
- infoFont.Draw(
- "Mouse 3 IsConnected " + Input.Mice(2).IsConnected,
- Rectangle.FromCenter(new Point(0.5f, 0.54f), Size.Half));
- infoFont.Draw(
- "Mouse 3 Left " + Input.Mice(2).GetState(InputButton.MouseLeft),
- Rectangle.FromCenter(new Point(0.5f, 0.57f), Size.Half));
- infoFont.Draw(
- "Mouse 3 Right " + Input.Mice(2).GetState(InputButton.MouseRight),
- Rectangle.FromCenter(new Point(0.5f, 0.6f), Size.Half));
- infoFont.Draw("Mouse 3 Position " + Input.Mice(2).Position,
- Rectangle.FromCenter(new Point(0.5f, 0.63f), Size.Half));
- });
- }
- #endregion
-
- #region TestSeveralMiceInput (Static)
- /// <summary>
- /// Test several mice input
- /// </summary>
- [Test, Category("Visual")]
- public static void TestSeveralMiceInput()
- {
- Color[] miceColors = new[]
- {
- Color.Red,
- Color.Yellow,
- Color.White,
- Color.Green,
- };
-
- string clickMessage = "no click yet";
-
- Application.BackgroundColor = Color.Black;
-
- Application.Start(delegate
- {
- // We need to init the mouse at the first time
- Assert.NotNull(Input.Mouse);
-
- Font font = Font.Default;
- float textLineGap = font.LineHeight * 1.1f;
- float yTextPos = 0.2f;
-
- for (int index = 0; index < Input.MaxNumberOfMice; index++)
- {
- BaseMouse mouse = Input.Mice(index);
- Assert.NotNull(mouse);
- string mouseName = "Mouse " + (index + 1);
-
- font.Draw(mouseName + " IsConnected " + mouse.IsConnected,
- Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
- yTextPos += textLineGap;
-
- font.Draw(mouseName + " Position " + mouse.Position,
- Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
- yTextPos += textLineGap;
-
- font.Draw(mouseName + " ScrollValue " + mouse.TotalScrollWheel,
- Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
- yTextPos += textLineGap;
-
- font.Draw(
- mouseName + " Left " + mouse.GetState(InputButton.MouseLeft),
- Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
- yTextPos += textLineGap;
-
- font.Draw(
- mouseName + " Right " + mouse.GetState(InputButton.MouseRight),
- Rectangle.FromCenter(new Point(0.5f, yTextPos), Size.Half));
- yTextPos += textLineGap;
-
- yTextPos += textLineGap;
- // Also draw both mouse cursors as circles
- Circle.DrawOutline(mouse.Position, 0.025f, miceColors[index]);
- } // for
-
- font.Draw(clickMessage,
- Rectangle.FromCenter(new Point(0.5f,
- ScreenSpace.DrawArea.Bottom - textLineGap), Size.Half));
- });
- }
- #endregion
- }
- }