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); })); } }
/// <summary> /// Converts a board point collection into a stroke. /// </summary> /// <param name="bpc">The BPC.</param> /// <returns>A stroke created from the given board point collection.</returns> private System.Windows.Ink.Stroke GetStroke(BoardPointCollection bpc) { System.Windows.Input.StylusPointCollection spc = new System.Windows.Input.StylusPointCollection(); bpc.Points.ForEach(point => { spc.Add(new System.Windows.Input.StylusPoint(point.X, point.Y, point.PressureFactor)); }); var stroke = new System.Windows.Ink.Stroke(spc, new System.Windows.Ink.DrawingAttributes() { Color = (Color)ColorConverter.ConvertFromString(bpc.Color) }); stroke.AddPropertyData(bpc.ID, bpc.User); stroke.DrawingAttributes.Height = bpc.BrushHeight; stroke.DrawingAttributes.Width = bpc.BrushWidth; return(stroke); }
/// <summary> /// Constructor /// </summary> /// <param name="sketch">SketchPanel to add a label to</param> /// <param name="inkStrokes">InkOverlay strokes</param> /// <param name="inkStrokes">A StrokeCollection strokes</param> /// <param name="label">Label to apply</param> /// <param name="domainInfo">DomainInfo for our Labeler</param> public EndPointMoveCmd(InkToSketchWPF.InkCanvasSketch inkSketch, Sketch.EndPoint oldLoc, Point newLoc, Stroke attachedStroke, Sketch.Shape shapeAtNewLoc) { isUndoable = true; this.inkSketch = inkSketch; oldLocation = oldLoc; newLocation = newLoc; this.attachedStroke = attachedStroke; this.shapeAtNewLoc = shapeAtNewLoc; this.changedShape = inkSketch.GetSketchSubstrokeByInk(attachedStroke).ParentShape; oldInternalConnection = changedShape.ConnectedShapes.Contains(changedShape); newIsWire = Domain.LogicDomain.IsWire(shapeAtNewLoc.Type); substrokesInNewShape = shapeAtNewLoc.SubstrokesL; // Make a new stroke comprising 100 points along the straight line between oldLocation and newLocation System.Windows.Input.StylusPointCollection line = new System.Windows.Input.StylusPointCollection(); for (double m = 0; m <= 1; m += 0.01) { double midX = oldLocation.X + m * (newLocation.X - oldLocation.X); double midY = oldLocation.Y + m * (newLocation.Y - oldLocation.Y); line.Add(new System.Windows.Input.StylusPoint(midX, midY)); } this.newStroke = new Stroke(line); }
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); } }