/// <summary> /// Returns whether or not the stroke is within the drawing radius /// If it is not in the drawing radius, we start a new overlap collection /// </summary> /// <param name="stroke"></param> /// <returns></returns> private bool outsideDrawRadius(System.Windows.Ink.Stroke stroke) { Point strokeCenter = new Point(stroke.GetBounds().X + stroke.GetBounds().Width / 2, stroke.GetBounds().Y + stroke.GetBounds().Height / 2); Point strokeCollCenter = new Point(overlapStrokes.GetBounds().X + overlapStrokes.GetBounds().Width / 2, overlapStrokes.GetBounds().Y + overlapStrokes.GetBounds().Height / 2); double distance = Math.Sqrt(Math.Pow(strokeCenter.X - strokeCollCenter.X, 2) + Math.Pow(strokeCenter.Y - strokeCollCenter.Y, 2)); return(distance > DRAW_RADIUS); }
public Graph(IDelegate _del, Stroke b) { del = _del; box = b; bounds = box.GetBounds(); box.StylusPoints = InkUtils.xkcd(InkUtils.box(bounds)); box.DrawingAttributes.Color = Colors.Blue; analyzer = new InkAnalyzer(); analyzer.ContextNodeCreated += ContextNodeCreated; }
public void Stroke_Default_Bounds () { Stroke s = new Stroke (); Rect bounds = s.GetBounds (); Assert.AreEqual (-1.5, bounds.Top, "Top"); Assert.AreEqual (-1.5, bounds.Left, "Left"); Assert.AreEqual (3, bounds.Height, "Height"); Assert.AreEqual (3, bounds.Width, "Width"); }
private bool CheckRemoveGate(Stroke stroke) { Rect strokeBound = stroke.GetBounds(); bool removeGate = false; List<Gate> removedGates = new List<Gate>(); for(int i = 0; i < circuitInkCanvas.Children.Count; i++) { UIElement gate = circuitInkCanvas.Children[i]; if (gate is Gate) { Gate g = gate as Gate; Rect grect = new Rect(g.Margin.Left + 40, g.Margin.Top + 40, g.Width - 40, g.Height - 40); if (strokeBound.Contains(grect)) { //this.RemoveGate(g); removedGates.Add(g); removeGate = true; } }else if(gate is ConnectedWire) { ConnectedWire wire = gate as ConnectedWire; //Debug.WriteLine("Stroke Rect Bound: " + strokeBound.ToString()); //Debug.WriteLine("Wire Origin is " + wire.Origin.ToString()); //Debug.WriteLine("Wire Destination is " + wire.Destination.ToString()); //Debug.WriteLine("Wire Outer Margin is " + wire.Outer.Margin.ToString()); HitTestResult result = null; int count = 0; foreach(StylusPoint pt in stroke.StylusPoints) { result = VisualTreeHelper.HitTest(wire, pt.ToPoint()); if(result != null) { count++; } } //Debug.WriteLine("Count is " + count.ToString()); if(count >= 3) { //trigger remove wire //From connectedWire to get terminal Gates.Terminal t = new Gates.Terminal(wire.DestTerminalID.ID, wire.DestinationGate); c.Disconnect1(t); circuitInkCanvas.Children.Remove(wire); /* for (int j = 0; j < wire.DestinationGate.NumberOfInputs; j++) { Gates.Terminal t = new Gates.Terminal(j, wire.DestinationGate); //Gates.Terminal t = new Gates.Terminal(j, wire.OriginGate); if (t != null) { c.Disconnect1(t); circuitInkCanvas.Children.Remove(wire); } } */ removeGate = true; } } } if(removeGate) { foreach (Gate g in removedGates) { this.RemoveGate(g); } return true; } return false; }
/// <summary> /// StrokeInfo /// </summary> internal StrokeInfo(Stroke stroke) { System.Diagnostics.Debug.Assert(stroke != null); _stroke = stroke; _bounds = stroke.GetBounds(); // Start listening to the stroke events _stroke.DrawingAttributesChanged += new PropertyDataChangedEventHandler(OnStrokeDrawingAttributesChanged); _stroke.StylusPointsReplaced += new StylusPointsReplacedEventHandler(OnStylusPointsReplaced); _stroke.StylusPoints.Changed += new EventHandler(OnStylusPointsChanged); _stroke.DrawingAttributesReplaced += new DrawingAttributesReplacedEventHandler(OnDrawingAttributesReplaced); }
/// <summary> /// Custom Pen Drawing /// </summary> private static Drawing CreatePenDrawing(DrawingAttributes drawingAttributes, bool isHollow, bool isRightToLeft) { // Create a single point stroke. StylusPointCollection stylusPoints = new StylusPointCollection(); stylusPoints.Add(new StylusPoint(0f, 0f)); DrawingAttributes da = new DrawingAttributes(); da.Color = drawingAttributes.Color; da.Width = drawingAttributes.Width; da.Height = drawingAttributes.Height; da.StylusTipTransform = drawingAttributes.StylusTipTransform; da.IsHighlighter = drawingAttributes.IsHighlighter; da.StylusTip = drawingAttributes.StylusTip; Stroke singleStroke = new Stroke(stylusPoints, da); // NTRAID#WINDOWS-1326403-2005/10/03-waynezen, // We should draw our cursor in the device unit since it's device dependent object. singleStroke.DrawingAttributes.Width = ConvertToPixel(singleStroke.DrawingAttributes.Width); singleStroke.DrawingAttributes.Height = ConvertToPixel(singleStroke.DrawingAttributes.Height); double maxLength = Math.Min(SystemParameters.PrimaryScreenWidth / 2, SystemParameters.PrimaryScreenHeight / 2); // // NOTE: there are two ways to set the width / height of a stroke // 1) using .Width and .Height // 2) using StylusTipTransform and specifying a scale // these two can multiply and we need to prevent the size from ever going // over maxLength or under 1.0. The simplest way to check if we're too big // is by checking the bounds of the stroke, which takes both into account // Rect strokeBounds = singleStroke.GetBounds(); bool outOfBounds = false; // Make sure that the cursor won't exceed the minimum or the maximum boundary. if ( DoubleUtil.LessThan(strokeBounds.Width, 1.0) ) { singleStroke.DrawingAttributes.Width = 1.0; outOfBounds = true; } else if ( DoubleUtil.GreaterThan(strokeBounds.Width, maxLength) ) { singleStroke.DrawingAttributes.Width = maxLength; outOfBounds = true; } if ( DoubleUtil.LessThan(strokeBounds.Height, 1.0) ) { singleStroke.DrawingAttributes.Height = 1.0; outOfBounds = true; } else if ( DoubleUtil.GreaterThan(strokeBounds.Height, maxLength) ) { singleStroke.DrawingAttributes.Height = maxLength; outOfBounds = true; } //drop the StylusTipTransform if we're out of bounds. we might //consider trying to preserve any transform but this is such a rare //case (scaling over or under with a STT) that we don't care. if (outOfBounds) { singleStroke.DrawingAttributes.StylusTipTransform = Matrix.Identity; } if (isRightToLeft) { //reverse left to right to right to left Matrix xf = singleStroke.DrawingAttributes.StylusTipTransform; xf.Scale(-1, 1); //only set the xf if it has an inverse or the STT will throw if (xf.HasInverse) { singleStroke.DrawingAttributes.StylusTipTransform = xf; } } DrawingGroup penDrawing = new DrawingGroup(); DrawingContext dc = null; try { dc = penDrawing.Open(); // Call the internal drawing method on Stroke to draw as hollow if isHollow == true if ( isHollow ) { singleStroke.DrawInternal(dc, singleStroke.DrawingAttributes, isHollow); } else { // Invoke the public Draw method which will handle the Highlighter correctly. singleStroke.Draw(dc, singleStroke.DrawingAttributes); } } finally { if ( dc != null ) { dc.Close(); } } return penDrawing; }
private void doMyStrokeRemovedExceptHistory(Stroke stroke) { var sum = stroke.sum().checksum.ToString(); var bounds = stroke.GetBounds(); Commands.SendDirtyStroke.Execute(new MeTLLib.DataTypes.TargettedDirtyElement(Globals.location.currentSlide,Globals.me,target,stroke.tag().privacy,sum)); }
private bool isStrokeContainedByPolygon(Stroke stroke, Rect currentShapeBounds) { bool isContained = false; bool strokeContainedinBounds = false; var sBounds = stroke.GetBounds(); foreach (Point p in new[]{ new Point(sBounds.Left,sBounds.Top), new Point(sBounds.Right,sBounds.Top), new Point(sBounds.Left,sBounds.Bottom), new Point(sBounds.Right,sBounds.Bottom)}) if (!strokeContainedinBounds && currentShapeBounds.Contains(p)) { strokeContainedinBounds = true; } if (strokeContainedinBounds) { var hitPointCount = 0; int speedFactor = 1; int tempIndex = 0; var hitPointThreshold = (stroke.StylusPoints.Count() / speedFactor) * .75; foreach (StylusPoint sp in stroke.StylusPoints) { tempIndex++; if (tempIndex == speedFactor) { tempIndex = 0; var spPoint = new Point(sp.X, sp.Y); if (polyHitTest(currentSelectionShape.Points.ToArray(), spPoint)) { hitPointCount++; } } } if (hitPointCount > hitPointThreshold) { isContained = true; } } return isContained; }
public void Stroke_StylusPointCollection_Bounds () { StylusPointCollection spc = new StylusPointCollection (); spc.Add (new StylusPoint (1, 2)); Stroke s = new Stroke (spc); Rect bounds = s.GetBounds (); Assert.AreEqual (-0.5, bounds.Left, "Left"); Assert.AreEqual (0.5, bounds.Top, "Top"); Assert.AreEqual (3, bounds.Height, "Height"); Assert.AreEqual (3, bounds.Width, "Width"); }