/InputSystem/Tests/GestureTests.cs
C# | 289 lines | 243 code | 21 blank | 25 comment | 28 complexity | 1e36695dc517c5f6975ad731f91f9fa9 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
- {
- internal class GestureTests
- {
- #region GestuerDrag (LongRunning)
- /// <summary>
- /// TestDrag
- /// </summary>
- [Test, Category("Visual")]
- public static void GestuerDrag()
- {
- Application.Start(delegate
- {
- // Change the background color for a better presentation.
- Application.BackgroundColor = Color.Black;
- Font.Default.Draw("Drag To Draw",
- Rectangle.FromCenter(new Point(0.5f, 0.15f), Size.Half));
- Font.Default.Draw(
- "Note: if the line disappears it means you are dragging too fast " +
- "which turns it into a flick",
- Rectangle.FromCenter(new Point(0.5f, 0.175f), Size.Half));
-
- if (Input.Gestures.IsDrag)
- {
- Line.Draw(Input.Mouse.DragStartPosition,
- Input.Mouse.Position, Color.White);
- }
- });
- }
- #endregion
-
- #region GestureFlick (LongRunning)
- /// <summary>
- /// TestFlick
- /// </summary>
- [Test, Category("Visual")]
- public static void GestureFlick()
- {
- Application.Start(delegate
- {
- // Change the background color for a better presentation.
- Application.BackgroundColor = Color.Black;
- Font.Default.Draw("Flick to change color",
- Rectangle.FromCenter(new Point(0.5f, 0.15f), Size.Half));
-
- if (Input.Gestures.IsFlick)
- {
- Application.BackgroundColor = Color.Random;
- }
- });
- }
- #endregion
-
- #region AllGestures (LongRunning)
- /// <summary>
- /// general test to test all out gestures at the same time
- /// </summary>
- [Test, Category("Visual")]
- public static void AllGestures()
- {
- // We need a time stamp to allow viewing the green color a gesture happen
-
- #region Flags and Counters
- int tapStamp = -1;
- int doubleTapSt = -1;
- int rotateSt = -1;
- int pinchSt = -1;
- int flickSt = -1;
- bool tap = false;
- bool doubleTap = false;
- bool pinch = false;
- bool flick = false;
- bool rotate = false;
- #endregion
-
- // Start our application here.
- Application.Start(delegate
- {
- Application.BackgroundColor = Color.Black;
- Font.Default.Draw("Tap",
- Rectangle.FromCenter(new Point(0.45f, 0.45f), Size.Half));
- Font.Default.Draw("DoubleTap",
- Rectangle.FromCenter(new Point(0.45f, 0.475f), Size.Half));
- Font.Default.Draw("Hold",
- Rectangle.FromCenter(new Point(0.45f, 0.5f), Size.Half));
- Font.Default.Draw("Drag",
- Rectangle.FromCenter(new Point(0.45f, 0.525f), Size.Half));
- Font.Default.Draw("RightDrag(Deacticated)",
- Rectangle.FromCenter(new Point(0.45f, 0.55f), Size.Half));
- Font.Default.Draw("DualDrag",
- Rectangle.FromCenter(new Point(0.45f, 0.575f), Size.Half));
- Font.Default.Draw("HorizontalDrag",
- Rectangle.FromCenter(new Point(0.45f, 0.6f), Size.Half));
- Font.Default.Draw("VertiacalDrag",
- Rectangle.FromCenter(new Point(0.45f, 0.625f), Size.Half));
- Font.Default.Draw("Rotate",
- Rectangle.FromCenter(new Point(0.45f, 0.65f), Size.Half));
- Font.Default.Draw("Pinch",
- Rectangle.FromCenter(new Point(0.45f, 0.675f), Size.Half));
- Font.Default.Draw("Flick",
- Rectangle.FromCenter(new Point(0.45f, 0.7f), Size.Half));
-
- #region Set Green Light
- var gesture = Input.Gestures;
- if (gesture.IsDoubleTap)
- {
- doubleTap = true;
- doubleTapSt = Time.Seconds;
- }
- if (gesture.IsTap)
- {
- tap = true;
- tapStamp = Time.Seconds;
- }
- if (gesture.IsRotate)
- {
- rotate = true;
- rotateSt = Time.Seconds;
- }
- if (gesture.IsPinch)
- {
- pinch = true;
- pinchSt = Time.Seconds;
- }
- if (gesture.IsFlick)
- {
- flick = true;
- flickSt = Time.Seconds;
- }
- #endregion
-
-
- #region Tap
- // Indicator Lights
- if (tap && (Time.Seconds - tapStamp < 1))
- {
- Circle.DrawFilled(new Point(0.65f, 0.45f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.45f), 0.01f, Color.Red);
- if (tapStamp > 0)
- {
- tapStamp = 0;
- }
- }
- #endregion
-
- #region DoubleTap
- if (doubleTap && (Time.Seconds - doubleTapSt < 1))
- {
- Circle.DrawFilled(new Point(0.65f, 0.475f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.475f), 0.01f, Color.Red);
- if (doubleTapSt > 0)
- {
- doubleTapSt = 0;
- }
- }
- #endregion
-
- #region Hold
- if (gesture.IsHold)
- {
- Circle.DrawFilled(new Point(0.65f, 0.5f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.5f), 0.01f, Color.Red);
- }
- #endregion
-
- #region Drag
- // Just a test to see that the buttons are updated as well for the
- // Commands
-
- //if (gesture.IsDrag)
- if (Input.GetState(InputButton.GestureDrag) == InputState.Released)
- {
- Circle.DrawFilled(new Point(0.65f, 0.525f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.525f), 0.01f, Color.Red);
- }
- #endregion
-
- #region IsRightDrag(Deactivated)
- //if (Input.Mouse.IsRightDrag)
- //{
- // Circle.DrawFilled(new Point(0.65f, 0.55f), 0.01f, Color.Green);
- //}
- //else
- //{
- // Circle.DrawFilled(new Point(0.65f, 0.55f), 0.01f, Color.Red);
- //}
- Circle.DrawFilled(new Point(0.65f, 0.55f), 0.01f, Color.Red);
- #endregion
-
- #region IsDaulDrag
- if (gesture.IsDaulDrag)
- {
- Circle.DrawFilled(new Point(0.65f, 0.575f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.575f), 0.01f, Color.Red);
- }
- #endregion
-
- #region IsHorizontalDrag
- if (gesture.IsHorizontalDrag)
- {
- Circle.DrawFilled(new Point(0.65f, 0.6f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.6f), 0.01f, Color.Red);
- }
- #endregion
-
- #region IsVerticalDrag
- if (gesture.IsVerticalDrag)
- {
- Circle.DrawFilled(new Point(0.65f, 0.625f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.625f), 0.01f, Color.Red);
- }
- #endregion
-
- #region Rotate
- if (rotate && (Time.Seconds - rotateSt < 1))
- {
- Circle.DrawFilled(new Point(0.65f, 0.65f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.65f), 0.01f, Color.Red);
- if (rotateSt > 0)
- {
- rotateSt = 0;
- }
- }
- #endregion
-
- #region Pinch
- if (pinch && (Time.Seconds - pinchSt < 1))
- {
- Circle.DrawFilled(new Point(0.65f, 0.675f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.675f), 0.01f, Color.Red);
- if (pinchSt > 0)
- {
- pinchSt = 0;
- }
- }
- #endregion
-
- #region Flick
- if (flick && (Time.Seconds - flickSt < 1))
- {
- Circle.DrawFilled(new Point(0.65f, 0.7f), 0.01f, Color.Green);
- }
- else
- {
- Circle.DrawFilled(new Point(0.65f, 0.7f), 0.01f, Color.Red);
- if (flickSt > 0)
- {
- flickSt = 0;
- }
- }
- #endregion
- });
- }
- #endregion
- }
- }