//<Snippet2> private void WriteDescriptionInfo(StylusPointCollection points) { StylusPointDescription pointsDescription = points.Description; ReadOnlyCollection <StylusPointPropertyInfo> properties = pointsDescription.GetStylusPointProperties(); StringWriter descriptionStringWriter = new StringWriter(); descriptionStringWriter.Write("Property Count:{0}", pointsDescription.PropertyCount.ToString()); foreach (StylusPointPropertyInfo property in properties) { // GetStylusPointPropertyName is defined below and returns the // name of the property. descriptionStringWriter.Write("name = {0}", GetStylusPointPropertyName(property).ToString()); descriptionStringWriter.WriteLine(" Guid = {0}", property.Id.ToString()); descriptionStringWriter.Write(" IsButton = {0}", property.IsButton.ToString()); descriptionStringWriter.Write(" Min = {0}", property.Minimum.ToString()); descriptionStringWriter.Write(" Max = {0}", property.Maximum.ToString()); descriptionStringWriter.Write(" Unit = {0}", property.Unit.ToString()); descriptionStringWriter.WriteLine(" Res {0}", property.Resolution.ToString()); } descriptionOutput.Text = descriptionStringWriter.ToString(); }
static public void WriteDescriptionInfo(StylusPointCollection points) { StylusPointDescription pointsDescription = points.Description; ReadOnlyCollection <StylusPointPropertyInfo> properties = pointsDescription.GetStylusPointProperties(); Debug.WriteLine("Property Count:" + pointsDescription.PropertyCount.ToString()); foreach (StylusPointPropertyInfo property in properties) { // GetStylusPointPropertyName is defined below and returns the // name of the property. Debug.WriteLine(" name = " + GetStylusPointPropertyName(property)); //Debug.WriteLine += " Guid = " + property.Id + "\r\n"; //Debug.WriteLine += " IsButton = " + property.IsButton; //Debug.WriteLine += " Min = " + property.Minimum; //Debug.WriteLine += " Max = " + property.Maximum; //Debug.WriteLine += " Unit = " + property.Unit; //Debug.WriteLine += " Res = " + property.Resolution + "\r\n"; } }
//</Snippet2> //<Snippet3> private void WriteStylusPointValues(StylusPointCollection points) { StylusPointDescription pointsDescription = points.Description; ReadOnlyCollection <StylusPointPropertyInfo> properties = pointsDescription.GetStylusPointProperties(); // Write the name and and value of each property in // every stylus point. StringWriter packetWriter = new StringWriter(); packetWriter.WriteLine("{0} stylus points", points.Count.ToString()); foreach (StylusPoint stylusPoint in points) { packetWriter.WriteLine("Stylus Point info"); packetWriter.WriteLine("X: {0}", stylusPoint.X.ToString()); packetWriter.WriteLine("Y: {0}", stylusPoint.Y.ToString()); packetWriter.WriteLine("Pressure: {0}", stylusPoint.PressureFactor.ToString()); // Get the property name and value for each StylusPoint. // Note that this loop reports the X, Y, and pressure values differantly than // getting their values above. for (int i = 0; i < pointsDescription.PropertyCount; ++i) { StylusPointProperty currentProperty = properties[i]; // GetStylusPointPropertyName is defined below and returns the // name of the property. packetWriter.Write("{0}: ", GetStylusPointPropertyName(currentProperty)); packetWriter.WriteLine(stylusPoint.GetPropertyValue(currentProperty).ToString()); } packetWriter.WriteLine(); } packetOutput.Text = packetWriter.ToString(); }
/// <summary> /// Builds the Stroke Descriptor for this stroke based on Packet Layout and Extended Properties /// For details on how this is strored please refer to the spec. /// </summary> internal static void BuildStrokeDescriptor( Stroke stroke, GuidList guidList, StrokeCollectionSerializer.StrokeLookupEntry strokeLookupEntry, out StrokeDescriptor strokeDescriptor, out MetricBlock metricBlock) { // Initialize the metric block for this stroke metricBlock = new MetricBlock(); // Clear any existing template strokeDescriptor = new StrokeDescriptor(); // Uninitialized variable passed in AddMetricEntry MetricEntryType metricEntryType; StylusPointDescription stylusPointDescription = stroke.StylusPoints.Description; KnownTagCache.KnownTagIndex tag = guidList.FindTag(KnownIds.X, true); metricEntryType = metricBlock.AddMetricEntry(stylusPointDescription.GetPropertyInfo(StylusPointProperties.X), tag); tag = guidList.FindTag(KnownIds.Y, true); metricEntryType = metricBlock.AddMetricEntry(stylusPointDescription.GetPropertyInfo(StylusPointProperties.Y), tag); ReadOnlyCollection <StylusPointPropertyInfo> propertyInfos = stylusPointDescription.GetStylusPointProperties(); int i = 0; //i is defined out of the for loop so we can use it later for buttons for (i = 2 /*past x,y*/; i < propertyInfos.Count; i++) { if (i == /*StylusPointDescription.RequiredPressureIndex //修复构建的代码 */ 2 && !strokeLookupEntry.StorePressure) { // // don't store pressure information // continue; } StylusPointPropertyInfo propertyInfo = propertyInfos[i]; if (propertyInfo.IsButton) { //we don't serialize buttons break; } tag = guidList.FindTag(propertyInfo.Id, true); strokeDescriptor.Template.Add(tag); strokeDescriptor.Size += SerializationHelper.VarSize((uint)tag); // Create the MetricEntry for this property if necessary metricEntryType = metricBlock.AddMetricEntry(propertyInfo, tag); } /* * we drop button data on the floor. * int buttonCount = stylusPointDescription.ButtonCount; * // Now write the button tags in the Template * if (buttonCount > 0) * { * // First write the TAG_BUTTONS * strokeDescriptor.Template.Add(KnownTagCache.KnownTagIndex.Buttons); * strokeDescriptor.Size += SerializationHelper.VarSize((uint)KnownTagCache.KnownTagIndex.Buttons); * * // Next write the i of buttons * strokeDescriptor.Template.Add((KnownTagCache.KnownTagIndex)buttonCount); * strokeDescriptor.Size += SerializationHelper.VarSize((uint)buttonCount); * * //we broke above on i when it was a button, it still * //points to the first button * for (; i < propertyInfos.Count; i++) * { * StylusPointPropertyInfo propertyInfo = propertyInfos[i]; * tag = guidList.FindTag(propertyInfo.Id, false); * * strokeDescriptor.Template.Add(tag); * strokeDescriptor.Size += SerializationHelper.VarSize((uint)tag); * } * } */ // Now write the extended properties in the template if (stroke.ExtendedProperties.Count > 0) { strokeDescriptor.Template.Add(KnownTagCache.KnownTagIndex.StrokePropertyList); strokeDescriptor.Size += SerializationHelper.VarSize((uint)KnownTagCache.KnownTagIndex.StrokePropertyList); // Now write the tags corresponding to each extended properties of the stroke for (int x = 0; x < stroke.ExtendedProperties.Count; x++) { tag = guidList.FindTag(stroke.ExtendedProperties[(int)x].Id, false); strokeDescriptor.Template.Add(tag); strokeDescriptor.Size += SerializationHelper.VarSize((uint)tag); } } }
public override void Perform() { if (InkCanvas.Strokes.Count == 0) { for (int i = 0; i < StylusPointCollection.Count; i++) { if (StylusPointCollection[i].HasProperty(StylusPointPropertyInfo)) { if (!StylusPointPropertyInfo.IsButton) { StylusPoint stylusPoint = StylusPointCollection[i]; int value = stylusPoint.GetPropertyValue(StylusPointPropertyInfo); value++; stylusPoint.SetPropertyValue(StylusPointPropertyInfo, value); StylusPointCollection[i] = stylusPoint; } } } //add the stroke and manipulate the points Stroke addStroke = new Stroke(StylusPointCollection); InkCanvas.Strokes.Add(addStroke); } else //randomly grab a stroke and tweak the data. { Stroke stroke = InkCanvas.Strokes[StrokeIndex % InkCanvas.Strokes.Count]; StylusPointDescription StylusPointDescription = stroke.StylusPoints.Description; ReadOnlyCollection <StylusPointPropertyInfo> StylusPointPropertyInfo = StylusPointDescription.GetStylusPointProperties(); for (int i = 0; i < stroke.StylusPoints.Count; i++) { StylusPoint StylusPoint = stroke.StylusPoints[i]; for (int j = 0; j < StylusPointPropertyInfo.Count; j++) { if (stroke.StylusPoints[i].HasProperty(StylusPointPropertyInfo[j])) { if (!StylusPointPropertyInfo[j].IsButton) { if (StylusPointProperties.X.Id == StylusPointPropertyInfo[j].Id) { StylusPoint.X = StylusPoint.X * XFact; } else if (StylusPointProperties.Y.Id == StylusPointPropertyInfo[j].Id) { StylusPoint.Y = StylusPoint.Y * YFact; } else { int value = StylusPoint.GetPropertyValue(StylusPointPropertyInfo[j]); //pick a random number and set the value value = Math.Min(StylusPointPropertyInfo[j].Minimum + GetValue % StylusPointPropertyInfo[j].Maximum, StylusPointPropertyInfo[j].Maximum); StylusPoint.SetPropertyValue(StylusPointPropertyInfo[j], value); } } } } stroke.StylusPoints[i] = StylusPoint; int hash = StylusPoint.GetHashCode(); } } }