/// <summary> /// Adds MouseMoveSegment to the current gesture. /// </summary> /// <param name="sender"></param> /// <param name="e">Mouse event data</param> /// <remarks> /// Function is called on the MouseMoveSegment of MouseMessageFilter /// The segment is added only when segment length is greater then /// mouseMoveSegmentLength /// </remarks> public void AddToGesture(object sender, EventArgs e) { if (working) { if (GetDistance(lastPoint, Cursor.Position) >= mouseMoveSegmentLength) { MouseMoveSegment segment = new MouseMoveSegment(lastPoint, Cursor.Position); mouseMoveSegments.Add(segment); lastPoint = Cursor.Position; } } }
public void Add(MouseMoveSegment segment) { mouseMoveSegments.Add(segment); }
/// <summary> /// Counts segments with the same direction in mouseMoveSegments. /// Counting started at the index of mouseMoveSegments array and /// the direction of segments is passed to the segmentDirection /// </summary> /// <param name="index"> /// Index to start at. Index to start next search is passed to /// this var. /// </param> /// <param name="segmentDirection"> /// The direction of the segments is passed /// to this var. /// </param> /// <returns>Returns the number of segments with the same direction in the row.</returns> private int CountMouseMoveSegments(ref int index, out MouseMoveSegment.SegmentDirection segmentDirection) { int count = 0; segmentDirection = MouseMoveSegment.SegmentDirection.Unknown; if ( index < mouseMoveSegments.Count ) { segmentDirection = mouseMoveSegments[index].Direction; } else return 0; while ( index < mouseMoveSegments.Count && mouseMoveSegments[index].Direction == segmentDirection) { index++; count++; } return count; }
/// <summary> /// Counts segments in row with SegmentDirection. /// Counting started at the index of mouseMoveSegments array. /// </summary> /// <param name="index"> /// Index to start at. Index to start next search is passed to /// this var. /// </param> /// <param name="segmentDirection">The direction of segments to count.</param> /// <returns>Returns the number of segments with direction in the row.</returns> private int CountMouseMoveSegments(ref int index, MouseMoveSegment.SegmentDirection segmentDirection) { int count = 0; while (index < mouseMoveSegments.Count && mouseMoveSegments[index].Direction == segmentDirection) { index++; count++; } return count; }
/// <summary> /// Tries to recognize simple mouse gesture /// </summary> /// <param name="unknownBefore">The number of segments with SegmentDirection.Unknown before the gesture</param> /// <param name="length">The number of segments of the gesture.</param> /// <param name="unknownAfter">The number of segments with SegmentDirection.Unknown after the gesture</param> /// <param name="direction">The direction of the gesture.</param> /// <returns>Returns the simple gesture or MouseGesture.Unknown if no gesture is recognized.</returns> protected MouseGesture RecognizeSimpleGesture(int unknownBefore, int length, int unknownAfter, MouseMoveSegment.SegmentDirection direction) { // max length of unknown segments before and after gesture double lengthTolerance = length * maxUnknownSkipRatio; // check unknown segments if ( (unknownBefore < lengthTolerance) && (unknownAfter < lengthTolerance) ) { //according to the direction of the segment choose simple MouseGesture switch ( direction ) { case MouseMoveSegment.SegmentDirection.Up: return MouseGesture.Up; case MouseMoveSegment.SegmentDirection.Right: return MouseGesture.Right; case MouseMoveSegment.SegmentDirection.Down: return MouseGesture.Down; case MouseMoveSegment.SegmentDirection.Left: return MouseGesture.Left; } } return MouseGesture.Unknown; }
/// <summary> /// Adds MouseMoveSegment to the current gesture. /// </summary> /// <param name="sender"></param> /// <param name="e">Mouse event data</param> /// <remarks> /// Function is called on the MouseMoveSegment of MouseMessageFilter /// The segment is added only when segment length is greater then /// mouseMoveSegmentLength /// </remarks> public void AddToGesture(object sender, EventArgs e) { if ( working ) { if ( GetDistance(lastPoint, Cursor.Position) >= mouseMoveSegmentLength ) { MouseMoveSegment segment = new MouseMoveSegment(lastPoint, Cursor.Position); mouseMoveSegments.Add(segment); lastPoint = Cursor.Position; } } }