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