Exemplo n.º 1
0
        //</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>
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }