/// <summary> /// Magnifies the sketch by a preset amount. /// </summary> public void ZoomIn() { inkPic.Renderer.Scale(SketchPanelConstants.ZoomInFactor, SketchPanelConstants.ZoomInFactor, true); ZoomEventHandler zoomEvent = ZoomEvent; if (zoomEvent != null) { zoomEvent(SketchPanelConstants.ZoomInFactor); } this.resizeInkPicture(); inkPic.Refresh(); }
/// <summary> /// Fragment the loaded Stroke at the intersections created by the drawn /// Microsoft.Ink.Stroke. /// </summary> /// <param name="sender">Reference to the object that raised the event</param> /// <param name="e">Passes an object specific to the event that is being handled</param> private void sketchInk_Stroke(object sender, InkCollectorStrokeEventArgs e) { // Find the float intersection points float[] intersections = e.Stroke.FindIntersections(sketchInk.Ink.Strokes); System.Drawing.Point[] pointInter = new System.Drawing.Point[intersections.Length]; // Find the actual points of intersection for (int i = 0; i < pointInter.Length; ++i) { pointInter[i] = LocatePoint(e.Stroke, intersections[i]); } // Remove our drawing stroke from the Ink this.sketchInk.Ink.DeleteStroke(e.Stroke); // Threshold for how far away we can draw from the actual stroke const double DISTTHRESHOLD = 40.0; // Hashtable mapping new points to FeatureStrokes Dictionary <Sketch.Stroke, List <int> > ptsToAdd = new Dictionary <Sketch.Stroke, List <int> >(); // For each point in our intersections we'll find the closest point in // the corresponding FeatureStroke points foreach (System.Drawing.Point currPt in pointInter) { int bestPointIndex = 0; double bestDist = Double.PositiveInfinity; Sketch.Stroke bestStroke = null; // Check all of the FeatureStrokes to see if the Point is close enough foreach (Sketch.Stroke stroke in this.strokes) { Sketch.Point[] pts = stroke.Points; // Find the closest point for this FeatureStroke for (int i = 0; i < pts.Length; i++) { double currDist = Euclidean(currPt.X, currPt.Y, pts[i].X, pts[i].Y); if (currDist < bestDist) { bestDist = currDist; bestPointIndex = i; bestStroke = stroke; } } } // If it's close enough, add it to our temporary Hashtable to keep track of // which point corresponds to which FeatureStroke if (bestDist < DISTTHRESHOLD) { bool alreadyExists = false; if (this.strokeToCorners.ContainsKey(bestStroke)) { List <int> existingPts = this.strokeToCorners[bestStroke]; if (existingPts.Contains(bestPointIndex)) { alreadyExists = true; } } if (!alreadyExists) { if (!ptsToAdd.ContainsKey(bestStroke)) { List <int> newPts = new List <int>(); newPts.Add(bestPointIndex); ptsToAdd.Add(bestStroke, newPts); } else { List <int> existingPts = ptsToAdd[bestStroke]; if (!existingPts.Contains(bestPointIndex)) { existingPts.Add(bestPointIndex); } } } } } if (ptsToAdd.Count > 0) { // Hand-fragment the stroke CM.ExecuteCommand(new CommandList.HandFragmentCornersCmd(ptsToAdd, this.strokeToCorners, this.overlayInk, this.fragmentPtAttributes)); } sketchInk.Refresh(); }