Ejemplo n.º 1
0
        //</Snippet19>

        void StylusPropertySnippets()
        {
            StylusPointPropertyInfo newProperty = new StylusPointPropertyInfo(StylusPointProperties.TwistOrientation);

            //<Snippet25>
            Guid guid = new Guid("12345678-1234-1234-1234-123456789012");
            StylusPointProperty newlyDefinedProperty = new StylusPointProperty(guid, false);
            //</Snippet25>
        }
        /// <summary>
        /// Create a StylusPointPropertyInfo.
        /// </summary>
        /// <param name="random"></param>
        /// <returns></returns>
        public override StylusPointPropertyInfo Create(DeterministicRandom random)
        {
            StylusPointProperty stylusPointProperty = random.NextStaticField <StylusPointProperty>(typeof(StylusPointProperties));
            int minimum = random.Next(10000);
            int maximum = random.Next(10000) + minimum;
            StylusPointPropertyUnit unit = random.NextEnum <StylusPointPropertyUnit>();
            float resolution             = random.Next(100) / 10f;

            StylusPointPropertyInfo stylusPointPropertyInfo = new StylusPointPropertyInfo(stylusPointProperty, minimum, maximum, unit, resolution);

            return(stylusPointPropertyInfo);
        }
        /// <summary>
        /// Creates WPF property infos from WM_POINTER device properties.  This appropriately maps and converts HID spec
        /// properties found in WM_POINTER to their WPF equivalents.  This is based on code from the WISP implementation
        /// that feeds the legacy WISP based stack.
        /// </summary>
        /// <param name="prop">The pointer property to convert</param>
        /// <returns>The equivalent WPF property info</returns>
        internal static StylusPointPropertyInfo CreatePropertyInfo(UnsafeNativeMethods.POINTER_DEVICE_PROPERTY prop)
        {
            StylusPointPropertyInfo result = null;

            // Get the mapped GUID for the HID usages
            Guid propGuid =
                StylusPointPropertyIds.GetKnownGuid(
                    (StylusPointPropertyIds.HidUsagePage)prop.usagePageId,
                    (StylusPointPropertyIds.HidUsage)prop.usageId);

            if (propGuid != Guid.Empty)
            {
                StylusPointProperty stylusProp = new StylusPointProperty(propGuid, StylusPointPropertyIds.IsKnownButton(propGuid));

                // Set Units
                StylusPointPropertyUnit?unit = StylusPointPropertyUnitHelper.FromPointerUnit(prop.unit);

                // If the parsed unit is invalid, set the default
                if (!unit.HasValue)
                {
                    unit = StylusPointPropertyInfoDefaults.GetStylusPointPropertyInfoDefault(stylusProp).Unit;
                }

                // Set to default resolution
                float resolution = StylusPointPropertyInfoDefaults.GetStylusPointPropertyInfoDefault(stylusProp).Resolution;

                short mappedExponent = 0;

                if (_hidExponentMap.TryGetValue((byte)(prop.unitExponent & HidExponentMask), out mappedExponent))
                {
                    float exponent = (float)Math.Pow(10, mappedExponent);

                    // Guard against divide by zero or negative resolution
                    if (prop.physicalMax - prop.physicalMin > 0)
                    {
                        // Calculated resolution is a scaling factor from logical units into the physical space
                        // at the given exponentiation.
                        resolution =
                            (prop.logicalMax - prop.logicalMin) / ((prop.physicalMax - prop.physicalMin) * exponent);
                    }
                }

                result = new StylusPointPropertyInfo(
                    stylusProp,
                    prop.logicalMin,
                    prop.logicalMax,
                    unit.Value,
                    resolution);
            }

            return(result);
        }
Ejemplo n.º 4
0
        // Use reflection to get the name of currentProperty.
        private static string GetStylusPointPropertyName(StylusPointProperty currentProperty)
        {
            Guid guid = currentProperty.Id;

            // Iterate through the StylusPointProperties to find the StylusPointProperty
            // that matches currentProperty, then return the name.
            foreach (FieldInfo theFieldInfo
                     in typeof(StylusPointProperties).GetFields())
            {
                StylusPointProperty property = (StylusPointProperty)theFieldInfo.GetValue(currentProperty);
                if (property.Id == guid)
                {
                    return(theFieldInfo.Name);
                }
            }
            return("Not found");
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        //</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();
        }
Ejemplo n.º 7
0
        /// <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);
        }