public PointerData ConvertStylusPoint(Phase phase, long timestamp, StylusPoint sp) { float x = (float)sp.X; float y = (float)sp.Y; PointerData pointerData = null; if (mScaleTiltX == 0) { pointerData = new PointerData(x, y, phase, timestamp) { Force = sp.PressureFactor }; } else { int tiltX = sp.GetPropertyValue(StylusPointProperties.XTiltOrientation); int tiltY = sp.GetPropertyValue(StylusPointProperties.YTiltOrientation); float tx = mTargetMinTiltX + (tiltX - mInputMinTiltX) * mScaleTiltX; float ty = mTargetMinTiltY + (tiltY - mInputMinTiltY) * mScaleTiltY; PointerData.CalculateAltitudeAndAzimuth(tx, ty, out float altitude, out float azimuth); pointerData = new PointerData(x, y, phase, timestamp) { Force = sp.PressureFactor, AltitudeAngle = altitude, AzimuthAngle = azimuth }; } return(pointerData); }
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(); } } }
protected override double GetStylusPointWidthOrHeight(StylusPoint stylusPoint, bool isWidth) { double pixelsPerInch = DpiUtil.DefaultPixelsPerInch; // If we have an active source and root visual use the DPI from there if (ActiveSource?.RootVisual != null) { pixelsPerInch = VisualTreeHelper.GetDpi(ActiveSource.RootVisual).PixelsPerInchX; } StylusPointProperty property = (isWidth ? StylusPointProperties.Width : StylusPointProperties.Height); double value = 0d; if (stylusPoint.HasProperty(property)) { // Get the property value in the corresponding units value = (double)stylusPoint.GetPropertyValue(property); StylusPointPropertyInfo propertyInfo = stylusPoint.Description.GetPropertyInfo(property); if (!DoubleUtil.AreClose(propertyInfo.Resolution, 0d)) { value /= propertyInfo.Resolution; } else { value = 0; } // Convert the value to Inches if (propertyInfo.Unit == StylusPointPropertyUnit.Centimeters) { value /= CentimetersPerInch; } // Convert the value to pixels value *= pixelsPerInch; } return(value); }
//</Snippet4> void StylusPointConstructor() { //<snippet5> StylusPointDescription newDescription = new StylusPointDescription(new StylusPointPropertyInfo[] { new StylusPointPropertyInfo(StylusPointProperties.X), new StylusPointPropertyInfo(StylusPointProperties.Y), new StylusPointPropertyInfo(StylusPointProperties.NormalPressure), new StylusPointPropertyInfo(StylusPointProperties.XTiltOrientation), new StylusPointPropertyInfo(StylusPointProperties.YTiltOrientation), new StylusPointPropertyInfo(StylusPointProperties.BarrelButton) }); int[] propertyValues = { 1800, 1000, 1 }; StylusPoint newStylusPoint = new StylusPoint(100, 100, .5f, newDescription, propertyValues); //</snippet5> //<Snippet16> StylusPointPropertyInfo XTiltPropertyInfo = new StylusPointPropertyInfo(StylusPointProperties.XTiltOrientation, 0, 3600, StylusPointPropertyUnit.Degrees, 10f); //</Snippet16> StylusPoint point = new StylusPoint(); //<Snippet11> if (point.HasProperty(StylusPointProperties.PitchRotation)) { int pitchRotation = point.GetPropertyValue(StylusPointProperties.PitchRotation); } //</Snippet11> //<Snippet12> if (point.HasProperty(StylusPointProperties.PitchRotation)) { point.SetPropertyValue(StylusPointProperties.PitchRotation, 1000); } //</Snippet12> }
/// <summary> /// Get the width or height of the stylus point's bounding box. /// </summary> /// <param name="stylusPoint">The point for which the width or height is being calculated</param> /// <param name="isWidth">True if this should calculate width, false for height</param> /// <returns>The width or height of the stylus poing</returns> /// <remarks> /// Note that this is not DPI aware. This implementation has never been aware of DPI changes and /// changing that now could cause issues with people who depended on this to be based on 96 DPI. /// </remarks> protected override double GetStylusPointWidthOrHeight(StylusPoint stylusPoint, bool isWidth) { double pixelsPerInch = DpiUtil.DefaultPixelsPerInch; StylusPointProperty property = (isWidth ? StylusPointProperties.Width : StylusPointProperties.Height); double value = 0d; if (stylusPoint.HasProperty(property)) { // Get the property value in the corresponding units value = (double)stylusPoint.GetPropertyValue(property); StylusPointPropertyInfo propertyInfo = stylusPoint.Description.GetPropertyInfo(property); if (!DoubleUtil.AreClose(propertyInfo.Resolution, 0d)) { value /= propertyInfo.Resolution; } else { value = 0; } // Convert the value to Inches if (propertyInfo.Unit == StylusPointPropertyUnit.Centimeters) { value /= CentimetersPerInch; } // Convert the value to pixels value *= pixelsPerInch; } return(value); }
public static Size GetSizeFromStylusPoint(StylusPoint stylusPoint) { return(new Size( stylusPoint.GetPropertyValue(StylusPointProperties.Width), stylusPoint.GetPropertyValue(StylusPointProperties.Height))); }