Пример #1
0
        /// <summary>
        /// Helper that transforms and scales in one go
        /// </summary>
        internal StylusPointCollection Reformat(StylusPointDescription subsetToReformatTo, GeneralTransform transform)
        {
            if (!subsetToReformatTo.IsSubsetOf(this.Description))
            {
                throw new ArgumentException(SR.Get(SRID.InvalidStylusPointDescriptionSubset), "subsetToReformatTo");
            }

            StylusPointDescription subsetToReformatToWithCurrentMetrics =
                StylusPointDescription.GetCommonDescription(subsetToReformatTo,
                                                            this.Description); //preserve metrics from this spd

            if (StylusPointDescription.AreCompatible(this.Description, subsetToReformatToWithCurrentMetrics) &&
                (transform is Transform) && ((Transform)transform).IsIdentity)
            {
                //subsetToReformatTo might have different x, y, p metrics
                return(this.Clone(transform, subsetToReformatToWithCurrentMetrics));
            }

            //
            // we really need to reformat this...
            //
            StylusPointCollection newCollection = new StylusPointCollection(subsetToReformatToWithCurrentMetrics, this.Count);
            int additionalDataCount             = subsetToReformatToWithCurrentMetrics.GetExpectedAdditionalDataCount();

            ReadOnlyCollection <StylusPointPropertyInfo> properties
                = subsetToReformatToWithCurrentMetrics.GetStylusPointProperties();
            bool isIdentity = (transform is Transform) ? ((Transform)transform).IsIdentity : false;

            for (int i = 0; i < this.Count; i++)
            {
                StylusPoint stylusPoint = this[i];

                double xCoord   = stylusPoint.X;
                double yCoord   = stylusPoint.Y;
                float  pressure = stylusPoint.GetUntruncatedPressureFactor();

                if (!isIdentity)
                {
                    Point p = new Point(xCoord, yCoord);
                    transform.TryTransform(p, out p);
                    xCoord = p.X;
                    yCoord = p.Y;
                }

                int[] newData = null;
                if (additionalDataCount > 0)
                {
                    //don't init, we'll do that below
                    newData = new int[additionalDataCount];
                }

                StylusPoint newStylusPoint =
                    new StylusPoint(xCoord, yCoord, pressure, subsetToReformatToWithCurrentMetrics, newData, false, false);

                //start at 3, skipping x, y, pressure
                for (int x = StylusPointDescription.RequiredCountOfProperties /*3*/; x < properties.Count; x++)
                {
                    int value = stylusPoint.GetPropertyValue(properties[x]);
                    newStylusPoint.SetPropertyValue(properties[x], value, false /*copy on write*/);
                }
                //bypass validation
                ((List <StylusPoint>)newCollection.Items).Add(newStylusPoint);
            }
            return(newCollection);
        }
Пример #2
0
        /// <summary>
        /// internal ctor
        /// </summary>
        internal StylusPoint(
            double x,
            double y,
            float pressureFactor,
            StylusPointDescription stylusPointDescription,
            int[] additionalValues,
            bool validateAdditionalData,
            bool validatePressureFactor)
        {
            if (Double.IsNaN(x))
            {
                throw new ArgumentOutOfRangeException("x", SR.Get(SRID.InvalidStylusPointXYNaN));
            }
            if (Double.IsNaN(y))
            {
                throw new ArgumentOutOfRangeException("y", SR.Get(SRID.InvalidStylusPointXYNaN));
            }


            //we don't validate pressure when called by StylusPointDescription.Reformat
            if (validatePressureFactor &&
                (pressureFactor == Single.NaN || pressureFactor < 0.0f || pressureFactor > 1.0f))
            {
                throw new ArgumentOutOfRangeException("pressureFactor", SR.Get(SRID.InvalidPressureValue));
            }
            //
            // only accept values between MaxXY and MinXY
            // we don't throw when passed a value outside of that range, we just silently trunctate
            //
            _x = GetClampedXYValue(x);
            _y = GetClampedXYValue(y);
            _stylusPointDescription = stylusPointDescription;
            _additionalValues       = additionalValues;
            _pressureFactor         = pressureFactor;

            if (validateAdditionalData)
            {
                //
                // called from the public verbose ctor
                //
                if (null == stylusPointDescription)
                {
                    throw new ArgumentNullException("stylusPointDescription");
                }

                //
                // additionalValues can be null if PropertyCount == 3 (X, Y, P)
                //
                if (stylusPointDescription.PropertyCount > StylusPointDescription.RequiredCountOfProperties &&
                    null == additionalValues)
                {
                    throw new ArgumentNullException("additionalValues");
                }


                if (additionalValues != null)
                {
                    ReadOnlyCollection <StylusPointPropertyInfo> properties
                        = stylusPointDescription.GetStylusPointProperties();

                    int expectedAdditionalValues = properties.Count - StylusPointDescription.RequiredCountOfProperties; //for x, y, pressure
                    if (additionalValues.Length != expectedAdditionalValues)
                    {
                        throw new ArgumentException(SR.Get(SRID.InvalidAdditionalDataForStylusPoint), "additionalValues");
                    }

                    //
                    // any buttons passed in must each be in their own int.  We need to
                    // pack them all into one int here
                    //
                    int[] newAdditionalValues =
                        new int[stylusPointDescription.GetExpectedAdditionalDataCount()];

                    _additionalValues = newAdditionalValues;
                    for (int i = StylusPointDescription.RequiredCountOfProperties, j = 0; i < properties.Count; i++, j++)
                    {
                        //
                        // use SetPropertyValue, it validates buttons, but does not copy the
                        // int[] on writes (since we pass the bool flag)
                        //
                        SetPropertyValue(properties[i], additionalValues[j], false /*copy on write*/);
                    }
                }
            }
        }