Exemplo n.º 1
0
 public GestureData(int[] moves, System.Windows.Input.StylusPoint[] points, System.Windows.Input.StylusPoint lastPoint, Rectangle rect)
 {
     this.moves     = moves;
     this.points    = points;
     this.lastPoint = lastPoint;
     this.rect      = rect;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create a stroke from an InkStroke. Used when adding the stroke.
        /// </summary>
        /// <param name="stroke"></param>
        /// <param name="dtGuid"></param>
        /// <param name="SAMPLE_RATE"></param>
        public Stroke(System.Windows.Ink.Stroke stroke, Guid dtGuid, float SAMPLE_RATE)
            : this()
        {
            // Get the timestamp for the function using a const Guid
            ulong theTime;

            if (stroke.ContainsPropertyData(dtGuid))
            {
                // MIT file format
                ulong fileTime = (ulong)stroke.GetPropertyData(dtGuid);
                theTime = (fileTime - 116444736000000000) / 10000;
            }
            else
            {
                theTime = ((ulong)DateTime.Now.ToFileTime() - 116444736000000000) / 10000;
            }

            // Set time data for each point and add it to the list of substroke's points
            List <Point> pointsToAdd = new List <Point>();

            System.Windows.Input.StylusPointCollection stylusPoints = stroke.StylusPoints;
            int numPoints = stylusPoints.Count;

            for (int i = 0; i < numPoints; i++)
            {
                // We believe this to be the standard sample rate.  The multiplication by 1,000 is to convert from
                // seconds to milliseconds.
                //
                // Our time is in the form of milliseconds since Jan 1, 1970
                //
                // NOTE: The timestamp for the stroke is made WHEN THE PEN IS LIFTED
                System.Windows.Input.StylusPoint styPoint = stylusPoints[i];
                ulong adjustedTime = theTime - (ulong)((1 / SAMPLE_RATE * 1000) * (numPoints - i));
                Point toAdd        = new Point((float)styPoint.X, (float)styPoint.Y, (float)styPoint.PressureFactor, Convert.ToUInt64(adjustedTime), "point");
                // HACK: Add back in if debugging: if (!pointsToAdd.Contains(toAdd))
                pointsToAdd.Add(toAdd);
            }

            // Create the new substroke using its drawing attributes
            System.Windows.Ink.DrawingAttributes drawingAttributes = stroke.DrawingAttributes;
            Substroke substroke = new Substroke(pointsToAdd);

            substroke.Name      = "substroke";
            substroke.Color     = drawingAttributes.Color.GetHashCode();
            substroke.PenTip    = drawingAttributes.StylusTip.ToString();
            substroke.PenWidth  = (float)drawingAttributes.Width;
            substroke.PenHeight = (float)drawingAttributes.Height;
            substroke.Source    = "InkSketch.canvasStrokeToSketchStroke";
            substroke.Start     = pointsToAdd[0].Id;
            substroke.End       = pointsToAdd[pointsToAdd.Count - 1].Id;
            this.AddSubstroke(substroke);

            // Update the stroke's attributes
            this._xmlAttributes.Name   = "stroke";
            this._xmlAttributes.Time   = (ulong)theTime;
            this._xmlAttributes.Type   = "stroke";
            this._xmlAttributes.Source = "Converter";
        }
Exemplo n.º 3
0
        /// <summary>
        /// 开始手势捕获
        /// </summary>
        /// <param name="mx">鼠标相对于绘图区的X坐标</param>
        /// <param name="my">鼠标相对于绘图区的Y坐标</param>
        public void StartCapture(int mx, int my)
        {
            moves  = new ArrayList();
            points = new ArrayList();

            rect = new GenericRect(int.MaxValue, int.MinValue, int.MaxValue, int.MinValue);

            lastPoint = new System.Windows.Input.StylusPoint(mx, my);
        }
        private void Service_StrokeUpdated(object sender, StrokeUpdatedEventArgs e)
        {
            var pathPart = e.PathPart;
            var data     = pathPart.Data.GetEnumerator();

            //Data is stored XYW
            float x = -1;
            float y = -1;
            float w = -1;

            if (data.MoveNext())
            {
                x = data.Current;
            }

            if (data.MoveNext())
            {
                y = data.Current;
            }

            if (data.MoveNext())
            {
                //Clamp to 0.0 -> 1.0
                w = Math.Max(0.0f, Math.Min(1.0f, (data.Current - 1.0f) * pFactor));
            }

            var point = new System.Windows.Input.StylusPoint(x * m_scale, y * m_scale, w);

            if (m_addNewStrokeToModel)
            {
                m_addNewStrokeToModel = false;
                var points = new System.Windows.Input.StylusPointCollection();
                points.Add(point);

                var stroke = new Stroke(points);
                stroke.DrawingAttributes = m_DrawingAttributes;

                Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                {
                    _strokes.Add(stroke);
                }));
            }
            else
            {
                Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                {
                    _strokes[_strokes.Count - 1].StylusPoints.Add(point);
                }));
            }
        }
        private void Service_StrokeEnded(object sender, StrokeEndedEventArgs e)
        {
            Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
            {
                var pathPart = e.PathPart;
                var data     = pathPart.Data.GetEnumerator();


                //Data is stored XYW
                float x = -1;
                float y = -1;
                float w = -1;

                if (data.MoveNext())
                {
                    x = data.Current;
                }

                if (data.MoveNext())
                {
                    y = data.Current;
                }

                if (data.MoveNext())
                {
                    //Clamp to 0.0 -> 1.0
                    w = Math.Max(0.0f, Math.Min(1.0f, (data.Current - 1.0f) * pFactor));
                }

                var point = new System.Windows.Input.StylusPoint(x * m_scale, y * m_scale, w);
                Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                {
                    _strokes[_strokes.Count - 1].StylusPoints.Add(point);
                    NotifyPropertyChanged("Strokes");
                }));

                m_addNewStrokeToModel = true;
            }));
        }
Exemplo n.º 6
0
        private void MatchGesture()
        {
            int bestCost = 1000000;
            int cost     = 0;

            int[] gest;
            int[] imoves = new int[moves.Count];
            for (int i = 0; i < moves.Count; i++)
            {
                //Console.WriteLine((int)moves[i]);
                if (i > 0 && i + 1 < imoves.Length)
                {
                    if (((int)moves[i] == 7 && (int)moves[i + 1] != 6 && (int)moves[i + 1] != 0 && (int)moves[i + 1] != 7) || ((int)moves[i + 1] == 7 && (int)moves[i] != 6 && (int)moves[i] != 0 && (int)moves[i] != 7))
                    {
                        polyPoints.Add((System.Windows.Input.StylusPoint)points[i]);
                        polyPoints.Add((System.Windows.Input.StylusPoint)points[i + 1]);
                    }
                    else if ((int)moves[i] != 7 && (int)moves[i + 1] != 7 && Math.Abs(((int)moves[i + 1] + 1) % 8 - ((int)moves[i] + 1) % 8) > 1)
                    {
                        polyPoints.Add((System.Windows.Input.StylusPoint)points[i]);
                        polyPoints.Add((System.Windows.Input.StylusPoint)points[i + 1]);
                    }
                }
            }
            for (int i = 0; i < imoves.Length; i++)
            {
                imoves[i] = (int)moves[i];
            }
            System.Windows.Input.StylusPoint[] ppoints = new System.Windows.Input.StylusPoint[points.Count];
            for (int i = 0; i < ppoints.Length; i++)
            {
                ppoints[i] = (System.Windows.Input.StylusPoint)points[i];
            }
            string    bestGesture = string.Empty;
            Rectangle irect       = new Rectangle();

            irect.HorizontalAlignment = HorizontalAlignment.Left;
            irect.VerticalAlignment   = VerticalAlignment.Top;
            irect.Margin = new Thickness(rect.MinX, rect.MinY, 0, 0);
            irect.Width  = rect.MaxX - rect.MinX;
            irect.Height = rect.MaxY - rect.MinY;
            GestureInfos infos = new GestureInfos(new GestureData(imoves, ppoints, lastPoint, irect));

            for (int i = 0; i < gestures.Count; i++)
            {
                gest          = (gestures[i] as GestureProperties).Moves;
                infos.Present = (gestures[i] as GestureProperties).Present;
                cost          = CostLeven(gest, imoves);
                if (cost <= DEFAULT_FIABILITY)
                {
                    if ((gestures[i] as GestureProperties).match != null)
                    {
                        infos.Cost = cost;
                        cost       = (gestures[i] as GestureProperties).match(infos);
                    }
                    if (cost < bestCost)
                    {
                        bestCost    = cost;
                        bestGesture = (gestures[i] as GestureProperties).Present;
                    }
                }
            }
            MouseGestureEventArgs args = new MouseGestureEventArgs();

            args.Present   = bestGesture;
            args.Fiability = cost;
            if (GestureMatchEvent != null)
            {
                GestureMatchEvent(args);
            }
        }
 public static bool Equals(System.Windows.Input.StylusPoint stylusPoint1, System.Windows.Input.StylusPoint stylusPoint2)
 {
     return(default(bool));
 }
 public bool Equals(System.Windows.Input.StylusPoint value)
 {
     return(default(bool));
 }