public static string GetMendID(this Stroke stroke) { if (stroke.ContainsPropertyData(MendID)) { return(stroke.GetPropertyData(MendID) as string); } return(string.Empty); }
public static bool GetIsMend(this Stroke stroke) { if (stroke.ContainsPropertyData(IsMend)) { return((bool)stroke.GetPropertyData(IsMend)); } return(false); }
public static string GetID(this Stroke stroke) { if (stroke.ContainsPropertyData(ID)) { return(stroke.GetPropertyData(ID) as string); } else { string id = Guid.NewGuid().ToString(); stroke.SetID(id); return(id); } }
/// <summary> /// Get Custom GUID properties from stroke /// </summary> /// <param name="s"></param> private double GetGuidValue(Stroke s, Guid guid) { double tempVelocity = 0d; if (s.ContainsPropertyData(guid)) { object data = s.GetPropertyData(guid); if (data is double) { tempVelocity = (double)data; } } return(tempVelocity); }
/// <summary> /// calculates the velocity of the stroke in seconds for expert stroke since the expert stroke could not be used in collection /// </summary> public double GetExpertStrokeVelocity(Stroke s) { GuidAttribute IMyInterfaceAttribute = (GuidAttribute)Attribute.GetCustomAttribute(typeof(ExpertInkCanvas), typeof(GuidAttribute)); //Debug.WriteLine("IMyInterface Attribute: " + IMyInterfaceAttribute.Value); Guid ExpertVelocity = new Guid(IMyInterfaceAttribute.Value); double strokeVelocity = 0d; if (s.ContainsPropertyData(ExpertVelocity)) { object velocity = s.GetPropertyData(ExpertVelocity); if (velocity is double) { strokeVelocity = (double)velocity; } } else { SendDebugMessage("The StrokeCollection does not have Velocity."); } return(strokeVelocity); }
// When the stylus clips a stroke, // delete that stroke. // When the stylus erases a stoke, // replace the stroke with the strokes returned by // the Stroke.Erase method. void myIHT_StrokeIntersectionChanged(object sender, StrokeHitEventArgs e) { Stroke thisStroke = e.HitStroke; // <Snippet11> Rect myRect = thisStroke.GetBounds(); // </Snippet11> if (state == sMode.clip) { // ***Stroke.Clip*** // <Snippet4> // Get the intersections when the stroke is clipped. // e is a StrokeIntersectionChangedEventArgs object in the // StrokeIntersectionChanged event handler. StrokeCollection clipResult = e.GetPointEraseResults(); StrokeCollection strokesToReplace = new StrokeCollection(); strokesToReplace.Add(thisStroke); // Replace the old stroke with the new one. if (clipResult.Count > 0) { myInkPresenter.Strokes.Replace(strokesToReplace, clipResult); } else { myInkPresenter.Strokes.Remove(strokesToReplace); } // </Snippet4> if (!gotFirstStroke) { // <Snippet3> // Create a guid for the date/timestamp. Guid dtGuid = new Guid("03457307-3475-3450-3035-640435034540"); DateTime now = DateTime.Now; // Check whether the property is already saved if (thisStroke.ContainsPropertyData(dtGuid)) { // Check whether the existing property matches the current date/timestamp DateTime oldDT = (DateTime)thisStroke.GetPropertyData(dtGuid); if (oldDT != now) { // Update the current date and time thisStroke.AddPropertyData(dtGuid, now); } } // </Snippet3> // <Snippet30> // Create a guid for the date/timestamp. Guid dateTimeGuid = new Guid("03457307-3475-3450-3035-045430534046"); DateTime current = DateTime.Now; // Check whether the property is already saved if (thisStroke.ContainsPropertyData(dateTimeGuid)) { DateTime oldDateTime = (DateTime)thisStroke.GetPropertyData(dateTimeGuid); // Check whether the existing property matches the current date/timestamp if (!(oldDateTime == current)) { // Delete the custom property thisStroke.RemovePropertyData(dateTimeGuid); } } // </Snippet30> // <Snippet12> // Save the stroke as an array of Point objects //Point[] myPoints = thisStroke.GetRenderingPoints(); // </Snippet12> // Port to VB if I ever get this working! // See if we can figure out which stroke point(s) got hit //StrokeIntersection[] myStrokeIntersections = e.GetHitStrokeIntersections(); //Point[] myStrokeIntersectionPoints = new Point[myStrokeIntersections.Length]; //int p = 0; //for (int k = 0; k < myStrokeIntersections.Length; k++) //{ // StrokeIntersection s = myStrokeIntersections[k]; // if (s.HitBegin != StrokeIntersection.BeforeFirst && s.HitEnd != StrokeIntersection. AfterLast) // { // // Get stroke point that is closest to average between HitBegin and HitEnd: // double x = s.HitBegin; // double y = s.HitEnd; // double midPoint = (x + y) / 2; // int middlePoint = (int)midPoint; // // Now add that Point from the existing stroke points // myStrokeIntersectionPoints[p] = myPoints[middlePoint]; // p++; // } //} // Get DrawingContext for InkPresenter //VisualCollection myVisuals = VisualOperations.GetChildren(myInkPresenter); //DrawingVisual myVisual = new DrawingVisual(); //DrawingContext myContext = myVisual.RenderOpen(); //// Draw midpoints of stroke intersections a little green circles //for (int j = 0; j < myStrokeIntersectionPoints.Length; j++) //{ // // Draw green circles around each point // myContext.DrawGeometry(Brushes.Green, // new Pen(Brushes.Green, 1.0), // new EllipseGeometry(myStrokeIntersectionPoints[j], 4.0, 4.0)); //} //myContext.Close(); //myVisuals.Add(myVisual); // Do I have to do something here to display the revised InkPresenter? // Open the file to hold strokes // if the file already exists, overwrite it //myFile = new StreamWriter(File.Open(STROKE_FILE, FileMode.Create)); //Point myPoint; //int xVal, yVal; //for (int i = 0; i < myPoints.Length; i++) //{ // myPoint = myPoints[i]; // xVal = (int)myPoint.X; // yVal = (int)myPoint.Y; // // Save the point to a file // myFile.WriteLine(xVal.ToString() + " " + yVal.ToString()); //} //myFile.Flush(); //myFile.Close(); //gotFirstStroke = true; } } else { // ***erase** // <Snippet10> // Remove the stokee that is hit. myInkPresenter.Strokes.Remove(e.HitStroke); // </Snippet10> } }
public static bool ContainsFirstBatPointCount(this Stroke stroke) { return(stroke.ContainsPropertyData(FirstBatPointCount)); }
public static bool HasID(this Stroke stroke) { return(stroke.ContainsPropertyData(ID)); }