internal void UpdateSizeDeltas(StylusPointDescription description, WispLogic stylusLogic)
        {
            // Query default settings for mouse drag and double tap (with minimum of 1x1 size).
            Size mouseDragDefault = new Size(Math.Max(1, SafeSystemMetrics.DragDeltaX / 2),
                                             Math.Max(1, SafeSystemMetrics.DragDeltaY / 2));
            Size mouseDoubleTapDefault = new Size(Math.Max(1, SafeSystemMetrics.DoubleClickDeltaX / 2),
                                                  Math.Max(1, SafeSystemMetrics.DoubleClickDeltaY / 2));

            StylusPointPropertyInfo xProperty = description.GetPropertyInfo(StylusPointProperties.X);
            StylusPointPropertyInfo yProperty = description.GetPropertyInfo(StylusPointProperties.Y);

            uint dwXValue = GetPropertyValue(xProperty);
            uint dwYValue = GetPropertyValue(yProperty);

            if (dwXValue != 0 && dwYValue != 0)
            {
                _cancelSize = new Size((int)Math.Round((ScreenSize.Width * stylusLogic.CancelDelta) / dwXValue),
                                       (int)Math.Round((ScreenSize.Height * stylusLogic.CancelDelta) / dwYValue));

                // Make sure we return whole numbers (pixels are whole numbers) and take the maximum
                // value between mouse and stylus settings to be safe.
                _cancelSize.Width  = Math.Max(mouseDragDefault.Width, _cancelSize.Width);
                _cancelSize.Height = Math.Max(mouseDragDefault.Height, _cancelSize.Height);

                _doubleTapSize = new Size((int)Math.Round((ScreenSize.Width * stylusLogic.DoubleTapDelta) / dwXValue),
                                          (int)Math.Round((ScreenSize.Height * stylusLogic.DoubleTapDelta) / dwYValue));

                // Make sure we return whole numbers (pixels are whole numbers) and take the maximum
                // value between mouse and stylus settings to be safe.
                _doubleTapSize.Width  = Math.Max(mouseDoubleTapDefault.Width, _doubleTapSize.Width);
                _doubleTapSize.Height = Math.Max(mouseDoubleTapDefault.Height, _doubleTapSize.Height);
            }
            else
            {
                // If no info to do the calculation then use the mouse settings for the default.
                _doubleTapSize = mouseDoubleTapDefault;
                _cancelSize    = mouseDragDefault;
            }

            _forceUpdateSizeDeltas = false;
        }
Beispiel #2
0
        protected static uint GetPropertyValue(StylusPointPropertyInfo propertyInfo)
        {
            uint dw = DefaultPropertyValue;

            switch (propertyInfo.Unit)
            {
            case StylusPointPropertyUnit.Inches:
                if (propertyInfo.Resolution != 0)
                {
                    dw = (uint)(((propertyInfo.Maximum - propertyInfo.Minimum) * 254) / propertyInfo.Resolution);
                }
                break;

            case StylusPointPropertyUnit.Centimeters:
                if (propertyInfo.Resolution != 0)
                {
                    dw = (uint)(((propertyInfo.Maximum - propertyInfo.Minimum) * 100) / propertyInfo.Resolution);
                }
                break;
            }

            return(dw);
        }
        /// <summary>
        /// Returns true if the two StylusPointDescriptions have the same StylusPointProperties.  Metrics are ignored.
        /// </summary>
        /// <param name="stylusPointDescription1">stylusPointDescription1</param>
        /// <param name="stylusPointDescription2">stylusPointDescription2</param>
        public static bool AreCompatible(StylusPointDescription stylusPointDescription1, StylusPointDescription stylusPointDescription2)
        {
            if (stylusPointDescription1 == null || stylusPointDescription2 == null)
            {
                throw new ArgumentNullException("stylusPointDescription");
            }

            #pragma warning disable 6506 // if a StylusPointDescription is not null, then _stylusPointPropertyInfos is not null.
            //
            // ignore X, Y, Pressure - they are guaranteed to be the first3 members
            //
            Debug.Assert(stylusPointDescription1._stylusPointPropertyInfos.Length >= RequiredCountOfProperties &&
                         stylusPointDescription1._stylusPointPropertyInfos[0].Id == StylusPointPropertyIds.X &&
                         stylusPointDescription1._stylusPointPropertyInfos[1].Id == StylusPointPropertyIds.Y &&
                         stylusPointDescription1._stylusPointPropertyInfos[2].Id == StylusPointPropertyIds.NormalPressure);

            Debug.Assert(stylusPointDescription2._stylusPointPropertyInfos.Length >= RequiredCountOfProperties &&
                         stylusPointDescription2._stylusPointPropertyInfos[0].Id == StylusPointPropertyIds.X &&
                         stylusPointDescription2._stylusPointPropertyInfos[1].Id == StylusPointPropertyIds.Y &&
                         stylusPointDescription2._stylusPointPropertyInfos[2].Id == StylusPointPropertyIds.NormalPressure);

            if (stylusPointDescription1._stylusPointPropertyInfos.Length != stylusPointDescription2._stylusPointPropertyInfos.Length)
            {
                return(false);
            }
            for (int x = RequiredCountOfProperties; x < stylusPointDescription1._stylusPointPropertyInfos.Length; x++)
            {
                if (!StylusPointPropertyInfo.AreCompatible(stylusPointDescription1._stylusPointPropertyInfos[x], stylusPointDescription2._stylusPointPropertyInfos[x]))
                {
                    return(false);
                }
            }
            #pragma warning restore 6506

            return(true);
        }
Beispiel #4
0
 public MetricEntryList (KnownTagCache.KnownTagIndex tag, StylusPointPropertyInfo prop)
 {
     Tag = tag;
     PropertyMetrics = prop;
 }
Beispiel #5
0
        /// <summary>
        /// This function checks if this packet property results in a valid metric entry. This will be a valid entry if
        /// 1. it is a custom property, 2. Does not belong to the global list of gaMetricEntry_Never, 3. Belongs to the
        /// global list of gaMetricEntry_Must and 4. Belongs to global list of gaMetricEntry_Optional and at least one of
        /// its metric values is different from the corresponding default.
        /// </summary>
        /// <param name="propertyInfo"></param>
        /// <param name="tag"></param>
        /// <param name="metricEntryType"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        
        static bool IsValidMetricEntry(StylusPointPropertyInfo propertyInfo, KnownTagCache.KnownTagIndex tag, out MetricEntryType metricEntryType, out uint index)
        {
            index = 0;
            // If this is a custom property, check if all the Metric values are null or not. If they are then this is not a 
            // valid metric entry
            if (tag >= (KnownTagCache.KnownTagIndex)KnownIdCache.CustomGuidBaseIndex)
            {
                metricEntryType = MetricEntryType.Custom;
                if( Int32.MinValue == propertyInfo.Minimum &&
                    Int32.MaxValue == propertyInfo.Maximum &&
                    StylusPointPropertyUnit.None == propertyInfo.Unit &&
                    DoubleUtil.AreClose(1.0, propertyInfo.Resolution) )
                    return false;
                else
                    return true;
            }
            else
            {
                int ul;
                // First find the property in the gaMetricEntry_Never. If it belongs to this list,
                // we will never write the metric table for this prop. So return FALSE;
                for( ul = 0; ul < MetricEntry_Never.Length ; ul++ )
                {
                    if( MetricEntry_Never[ul] == tag )
                    {
                        metricEntryType = MetricEntryType.Never;
                        return false;
                    }
                }

                // Then search the property in the gaMetricEntry_Must list. If it belongs to this list,
                // we must always write the metric table for this prop. So return TRUE;
                for( ul = 0; ul<MetricEntry_Must.Length; ul++ )
                {
                    if( MetricEntry_Must[ul] == tag )
                    {
                        metricEntryType = MetricEntryType.Must;
                        if( propertyInfo.Minimum == DefaultPropertyMetrics.Minimum &&
                            propertyInfo.Maximum == DefaultPropertyMetrics.Maximum &&
                            propertyInfo.Unit == DefaultPropertyMetrics.Unit &&
                            DoubleUtil.AreClose(propertyInfo.Resolution, DefaultPropertyMetrics.Resolution ))
                            return false;
                        else
                            return true;
                    }
                }

                // Now seach it in the gaMetricEntry_Optional list. If it is there, check the metric values
                // agianst the default values and if there is any non default value, return TRUE;
                for( ul = 0; ul<MetricEntry_Optional.Length; ul++ )
                {
                    if( ((MetricEntryList)MetricEntry_Optional[ul]).Tag == tag )
                    {
                        metricEntryType = MetricEntryType.Optional;
                        if( propertyInfo.Minimum == MetricEntry_Optional[ul].PropertyMetrics.Minimum &&
                            propertyInfo.Maximum == MetricEntry_Optional[ul].PropertyMetrics.Maximum &&
                            propertyInfo.Unit == MetricEntry_Optional[ul].PropertyMetrics.Unit &&
                            DoubleUtil.AreClose(propertyInfo.Resolution, MetricEntry_Optional[ul].PropertyMetrics.Resolution) )
                            return false;
                        else
                        {
                            index = (uint)ul;
                            return true;
                        }
                    }
                }
                // it is not found in any of the list. Force to write all metric entries for the property.
                metricEntryType = MetricEntryType.Must;
                return true;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Creates a metric entry based on a PropertyInfo and Tag and returns the Metric Entry Type created
        /// </summary>
        /// <param name="propertyInfo"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        public MetricEntryType CreateMetricEntry(StylusPointPropertyInfo propertyInfo, KnownTagCache.KnownTagIndex tag)
        {
            // First create the default Metric entry based on the property and type of metric entry and then use that to initialize the
            // metric entry data.
            uint index = 0;
            Tag = tag;

            MetricEntryType type;
            if( IsValidMetricEntry(propertyInfo, Tag, out type, out index) )
            {
                switch(type)
                {
                    case MetricEntryType.Optional:
                    {
                        Initialize(propertyInfo, MetricEntry_Optional[index].PropertyMetrics);
                        break;
                    }
                    case MetricEntryType.Must :
                    case MetricEntryType.Custom:
                        Initialize(propertyInfo, DefaultPropertyMetrics);
                        break;
                    default:
                        throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("MetricEntryType was persisted with Never flag which should never happen"));
                }
            }
            return type;
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a MetricEntry based on StylusPointPropertyInfo and default StylusPointPropertyInfo for the property
 /// </summary>
 /// <param name="originalInfo"></param>
 /// <param name="defaultInfo"></param>
 /// <returns></returns>
 public void Initialize(StylusPointPropertyInfo originalInfo, StylusPointPropertyInfo defaultInfo)
 {
     _size = 0;
     using (MemoryStream strm = new MemoryStream(_data))
     {
         if (!DoubleUtil.AreClose(originalInfo.Resolution, defaultInfo.Resolution))
         {
             // First min value
             _size += SerializationHelper.SignEncode(strm, originalInfo.Minimum);
             // Max value
             _size += SerializationHelper.SignEncode(strm, originalInfo.Maximum);
             // Units
             _size += SerializationHelper.Encode(strm, (uint)originalInfo.Unit);
             // resolution
             using (BinaryWriter bw = new BinaryWriter(strm))
             {
                 bw.Write(originalInfo.Resolution);
                 _size += 4; // sizeof(float)
             }
         }
         else if (originalInfo.Unit != defaultInfo.Unit)
         {
             // First min value
             _size += SerializationHelper.SignEncode(strm, originalInfo.Minimum);
             // Max value
             _size += SerializationHelper.SignEncode(strm, originalInfo.Maximum);
             // Units
             _size += SerializationHelper.Encode(strm, (uint)originalInfo.Unit);
         }
         else if (originalInfo.Maximum != defaultInfo.Maximum)
         {
             // First min value
             _size += SerializationHelper.SignEncode(strm, originalInfo.Minimum);
             // Max value
             _size += SerializationHelper.SignEncode(strm, originalInfo.Maximum);
         }
         else if (originalInfo.Minimum != defaultInfo.Minimum)
         {
             _size += SerializationHelper.SignEncode(strm, originalInfo.Minimum);
         }
     }
 }
        /// <summary>
        /// Builds StylusPointDescription based on StrokeDescriptor and Metric Descriptor Block. Sometime Metric Descriptor block may contain
        /// metric information for properties which are not part of the stroke descriptor. They are simply ignored.
        /// </summary>
        /// <param name="strd"></param>
        /// <param name="block"></param>
        /// <param name="guidList"></param>
        /// <returns></returns>
        private StylusPointDescription BuildStylusPointDescription(StrokeDescriptor strd, MetricBlock block, GuidList guidList)
        {
            int cTags = 0;
            int packetPropertyCount = 0;
            uint buttonCount = 0;
            Guid[] buttonguids = null;
            System.Collections.Generic.List<KnownTagCache.KnownTagIndex> tags = null;

            // if strd is null, it means there is only default descriptor with X & Y
            if (null != strd)
            {
                tags = new System.Collections.Generic.List<KnownTagCache.KnownTagIndex>();
                while (cTags < strd.Template.Count)
                {
                    KnownTagCache.KnownTagIndex tag = (KnownTagCache.KnownTagIndex)strd.Template[cTags];

                    if (KnownTagCache.KnownTagIndex.Buttons == tag)
                    {
                        cTags++;

                        // The next item in the array is no of buttongs.
                        buttonCount = (uint)strd.Template[cTags];
                        cTags++;

                        // Currently we skip the the no of buttons as buttons is not implimented yet
                        buttonguids = new Guid[buttonCount];
                        for (uint u = 0; u < buttonCount; u++)
                        {
                            Guid guid = guidList.FindGuid(strd.Template[cTags]);
                            if (guid == Guid.Empty)
                            {
                                throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Button guid tag embedded in ISF stream does not match guid table"),"strd");
                            }

                            buttonguids[(int)u] = guid;
                            cTags++;
                        }
                    }
                    else if (KnownTagCache.KnownTagIndex.StrokePropertyList == tag)
                    {
                        break; // since no more Packet properties can be stored
                    }
                    else
                    {
                        if (KnownTagCache.KnownTagIndex.NoX == tag ||
                            KnownTagCache.KnownTagIndex.NoY == tag)
                        {
                            throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Invalid ISF with NoX or NoY specified"), "strd");
                        }

                        tags.Add(strd.Template[cTags]);
                        packetPropertyCount++;
                        cTags++;
                    }
                }
            }


            List<StylusPointPropertyInfo> stylusPointPropertyInfos = new List<StylusPointPropertyInfo>();
            stylusPointPropertyInfos.Add(GetStylusPointPropertyInfo(KnownIds.X, (KnownTagCache.KnownTagIndex)((uint)KnownIdCache.KnownGuidBaseIndex + (uint)KnownIdCache.OriginalISFIdIndex.X), block));
            stylusPointPropertyInfos.Add(GetStylusPointPropertyInfo(KnownIds.Y, (KnownTagCache.KnownTagIndex)((uint)KnownIdCache.KnownGuidBaseIndex + (uint)KnownIdCache.OriginalISFIdIndex.Y), block));
            stylusPointPropertyInfos.Add(GetStylusPointPropertyInfo(KnownIds.NormalPressure, (KnownTagCache.KnownTagIndex)((uint)KnownIdCache.KnownGuidBaseIndex + (uint)KnownIdCache.OriginalISFIdIndex.NormalPressure), block));

            int pressureIndex = -1;
            if (tags != null)
            {
                for (int i = 0; i < tags.Count; i++)
                {
                    Guid guid = guidList.FindGuid(tags[i]);
                    if (guid == Guid.Empty)
                    {
                        throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Packet Description Property tag embedded in ISF stream does not match guid table"), "strd");
                    }
                    if (pressureIndex == -1 && guid == StylusPointPropertyIds.NormalPressure)
                    {
                        pressureIndex = i + 2; //x,y have already been accounted for
                        continue; //we've already added pressure (above)
                    }

                    stylusPointPropertyInfos.Add(GetStylusPointPropertyInfo(guid, tags[i], block));
                }

                if (null != buttonguids)
                {
                    //
                    // add the buttons to the end of the description if they exist
                    //
                    for (int i = 0; i < buttonguids.Length; i++)
                    {
                        StylusPointProperty buttonProperty = new StylusPointProperty(buttonguids[i], true);
                        StylusPointPropertyInfo buttonInfo = new StylusPointPropertyInfo(buttonProperty);
                        stylusPointPropertyInfos.Add(buttonInfo);
                    }
                }
            }

            return new StylusPointDescription(stylusPointPropertyInfos, pressureIndex);
        }
        /// <summary>
        /// ToISFReadyArrays - Returns an array of arrays of packet values:
        ///
        /// int[]
        ///     - int[x,x,x,x,x,x]
        ///     - int[y,y,y,y,y,y]
        ///     - int[p,p,p,p,p,p]
        ///
        /// For ISF serialization
        ///
        /// Also returns if any non-default pressures were found or the metric for
        /// pressure was non-default
        ///
        /// </summary>
        internal void ToISFReadyArrays(out int[][] output, out bool shouldPersistPressure)
        {
            Debug.Assert(this.Count != 0, "Why are we serializing an empty StylusPointCollection???");
            //
            // X and Y are in Avalon units, we need to convert to HIMETRIC
            //

            //
            //


            int lengthPerPoint = this.Description.GetOutputArrayLengthPerPoint();

            if (this.Description.ButtonCount > 0)
            {
                //don't serialize button data. See Windows OS Bugs 1413460 for details
                lengthPerPoint--;
            }

            output = new int[lengthPerPoint][];
            for (int x = 0; x < lengthPerPoint; x++)
            {
                output[x] = new int[this.Count];
            }

            //
            // we serialize pressure if
            // 1) The StylusPointPropertyInfo for pressure is not the default
            // 2) There is at least one non-default pressure value in this SPC
            //
            StylusPointPropertyInfo pressureInfo =
                this.Description.GetPropertyInfo(StylusPointPropertyIds.NormalPressure);

            shouldPersistPressure =
                !StylusPointPropertyInfo.AreCompatible(pressureInfo, StylusPointPropertyInfoDefaults.NormalPressure);

            for (int b = 0; b < this.Count; b++)
            {
                StylusPoint stylusPoint = this[b];
                output[0][b] = (int)Math.Round(stylusPoint.X * StrokeCollectionSerializer.AvalonToHimetricMultiplier);
                output[1][b] = (int)Math.Round(stylusPoint.Y * StrokeCollectionSerializer.AvalonToHimetricMultiplier);
                output[2][b] = stylusPoint.GetPropertyValue(StylusPointProperties.NormalPressure);
                //
                // it's not necessary to check HasDefaultPressure if
                // allDefaultPressures is already set
                //
                if (!shouldPersistPressure && !stylusPoint.HasDefaultPressure)
                {
                    shouldPersistPressure = true;
                }
                if (lengthPerPoint > StylusPointDescription.RequiredCountOfProperties)
                {
                    int[] additionalData = stylusPoint.GetAdditionalData();
                    int   countToCopy    = lengthPerPoint - StylusPointDescription.RequiredCountOfProperties;/*3*/
                    Debug.Assert(this.Description.ButtonCount > 0 ?
                                 additionalData.Length - 1 == countToCopy :
                                 additionalData.Length == countToCopy);

                    for (int y = 0; y < countToCopy; y++)
                    {
                        output[y + 3][b] = additionalData[y];
                    }
                }
            }
        }
Beispiel #10
0
        private void GetPacketData
        (
            Stroke stroke,
            out MS.Win32.Recognizer.PACKET_DESCRIPTION packetDescription, 
            out int countOfBytes, 
            out IntPtr packets, 
            out NativeMethods.XFORM xForm
        )
        {
            int i;
            countOfBytes = 0;
            packets = IntPtr.Zero;
            packetDescription = new MS.Win32.Recognizer.PACKET_DESCRIPTION();
            Matrix matrix = Matrix.Identity;
            xForm = new NativeMethods.XFORM((float)(matrix.M11), (float)(matrix.M12), (float)(matrix.M21),
                                            (float)(matrix.M22), (float)(matrix.OffsetX), (float)(matrix.OffsetY));

            StylusPointCollection stylusPoints = stroke.StylusPoints;
            if (stylusPoints.Count == 0)
            {
                return; //we'll fail when the calling routine sees that packets is IntPtr.Zer
            }

            if (stylusPoints.Description.PropertyCount > StylusPointDescription.RequiredCountOfProperties)
            {
                //
                // reformat to X, Y, P
                //
                StylusPointDescription reformatDescription
                    = new StylusPointDescription(
                            new StylusPointPropertyInfo[]{
                                new StylusPointPropertyInfo(StylusPointProperties.X),
                                new StylusPointPropertyInfo(StylusPointProperties.Y),
                                stylusPoints.Description.GetPropertyInfo(StylusPointProperties.NormalPressure)});
                stylusPoints = stylusPoints.Reformat(reformatDescription);
            }

            //
            // now make sure we only take a finite amount of data for the stroke
            //
            if (stylusPoints.Count > MaxStylusPoints)
            {
                stylusPoints = stylusPoints.Clone(MaxStylusPoints);
            }

            Guid[] propertyGuids = new Guid[]{  StylusPointPropertyIds.X, //required index for SPD
                                                StylusPointPropertyIds.Y, //required index for SPD
                                                StylusPointPropertyIds.NormalPressure}; //required index for SPD

            Debug.Assert(stylusPoints != null);
            Debug.Assert(propertyGuids.Length == StylusPointDescription.RequiredCountOfProperties);

            // Get the packet description
            packetDescription.cbPacketSize = (uint)(propertyGuids.Length * Marshal.SizeOf(typeof(Int32)));
            packetDescription.cPacketProperties = (uint)propertyGuids.Length;

            //
            // use X, Y defaults for metrics, sometimes mouse metrics can be bogus
            // always use NormalPressure metrics, though.
            //
            StylusPointPropertyInfo[] infosToUse = new StylusPointPropertyInfo[StylusPointDescription.RequiredCountOfProperties];
            infosToUse[StylusPointDescription.RequiredXIndex] = StylusPointPropertyInfoDefaults.X;
            infosToUse[StylusPointDescription.RequiredYIndex] = StylusPointPropertyInfoDefaults.Y;
            infosToUse[StylusPointDescription.RequiredPressureIndex] =
                stylusPoints.Description.GetPropertyInfo(StylusPointProperties.NormalPressure);

            MS.Win32.Recognizer.PACKET_PROPERTY[] packetProperties = 
                new MS.Win32.Recognizer.PACKET_PROPERTY[packetDescription.cPacketProperties];
            
            StylusPointPropertyInfo propertyInfo;
            for ( i = 0; i < packetDescription.cPacketProperties; i++ )
            {
                packetProperties[i].guid = propertyGuids[i];
                propertyInfo = infosToUse[i];

                MS.Win32.Recognizer.PROPERTY_METRICS propertyMetrics = new MS.Win32.Recognizer.PROPERTY_METRICS( );
                propertyMetrics.nLogicalMin = propertyInfo.Minimum;
                propertyMetrics.nLogicalMax = propertyInfo.Maximum;
                propertyMetrics.Units = (int)(propertyInfo.Unit);
                propertyMetrics.fResolution = propertyInfo.Resolution;
                packetProperties[i].PropertyMetrics = propertyMetrics;
            }

            unsafe
            {
                int allocationSize = (int)(Marshal.SizeOf(typeof(MS.Win32.Recognizer.PACKET_PROPERTY)) * packetDescription.cPacketProperties);
                packetDescription.pPacketProperties = Marshal.AllocCoTaskMem(allocationSize);
                MS.Win32.Recognizer.PACKET_PROPERTY* pPacketProperty = 
                    (MS.Win32.Recognizer.PACKET_PROPERTY*)(packetDescription.pPacketProperties.ToPointer());
                MS.Win32.Recognizer.PACKET_PROPERTY* pElement = pPacketProperty;
                for ( i = 0 ; i < packetDescription.cPacketProperties ; i ++ )
                {
                    Marshal.StructureToPtr(packetProperties[i], new IntPtr(pElement), false);
                    pElement++;
                }
            }

            // Get packet data
            int[] rawPackets = stylusPoints.ToHiMetricArray();
            int packetCount = rawPackets.Length;
            if (packetCount != 0)
            {
                countOfBytes = packetCount * Marshal.SizeOf(typeof(Int32));
                packets = Marshal.AllocCoTaskMem(countOfBytes);
                Marshal.Copy(rawPackets, 0, packets, packetCount);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Optimization that lets the ctor call setvalue repeatly without causing a copy of the int[]
        /// </summary>
        /// <param name="stylusPointProperty">stylusPointProperty</param>
        /// <param name="value">value</param>
        /// <param name="copyBeforeWrite"></param>
        internal void SetPropertyValue(StylusPointProperty stylusPointProperty, int value, bool copyBeforeWrite)
        {
            if (null == stylusPointProperty)
            {
                throw new ArgumentNullException("stylusPointProperty");
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.X)
            {
                double dVal = (double)value;
                //
                // 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(dVal);
            }
            else if (stylusPointProperty.Id == StylusPointPropertyIds.Y)
            {
                double dVal = (double)value;
                //
                // only accept values between MaxXY and MinXY
                // we don't throw when passed a value outside of that range, we just silently trunctate
                //
                _y = GetClampedXYValue(dVal);
            }
            else if (stylusPointProperty.Id == StylusPointPropertyIds.NormalPressure)
            {
                StylusPointPropertyInfo info =
                    this.Description.GetPropertyInfo(StylusPointProperties.NormalPressure);

                int min = info.Minimum;
                int max = info.Maximum;
                if (max == 0)
                {
                    _pressureFactor = 0.0f;
                }
                else
                {
                    _pressureFactor = (float)(Convert.ToSingle(min + value) / Convert.ToSingle(max));
                }
            }
            else
            {
                int propertyIndex = this.Description.GetPropertyIndex(stylusPointProperty.Id);
                if (-1 == propertyIndex)
                {
                    throw new ArgumentException(SR.Get(SRID.InvalidStylusPointProperty), "propertyId");
                }
                if (stylusPointProperty.IsButton)
                {
                    if (value < 0 || value > 1)
                    {
                        throw new ArgumentOutOfRangeException("value", SR.Get(SRID.InvalidMinMaxForButton));
                    }

                    if (copyBeforeWrite)
                    {
                        CopyAdditionalData();
                    }

                    //
                    // we get button data from a single int in the array
                    //
                    int buttonData        = _additionalValues[_additionalValues.Length - 1];
                    int buttonBitPosition = this.Description.GetButtonBitPosition(stylusPointProperty);
                    int bit = 1 << buttonBitPosition;
                    if (value == 0)
                    {
                        //turn the bit off
                        buttonData &= ~bit;
                    }
                    else
                    {
                        //turn the bit on
                        buttonData |= bit;
                    }
                    _additionalValues[_additionalValues.Length - 1] = buttonData;
                }
                else
                {
                    if (copyBeforeWrite)
                    {
                        CopyAdditionalData();
                    }
                    _additionalValues[propertyIndex - 3] = value;
                }
            }
        }
        private static uint GetPropertyValue(StylusPointPropertyInfo propertyInfo)
        {
            uint   dw = 0;

            switch (propertyInfo.Unit)
            {
                case StylusPointPropertyUnit.Inches:
                    if (propertyInfo.Resolution != 0)
                        dw = (uint) (((propertyInfo.Maximum - propertyInfo.Minimum) * 254) / propertyInfo.Resolution);
                    break;

                case StylusPointPropertyUnit.Centimeters:
                    if (propertyInfo.Resolution != 0)
                        dw = (uint) (((propertyInfo.Maximum - propertyInfo.Minimum) * 100) / propertyInfo.Resolution);
                    break;

                default:
                    dw = 1000;
                    break;
            }
            return dw;
        }
        private void InitStylusPointDescription()
        {
            int cProps;
            int cButtons;
            int pressureIndex = -1;

            // Make sure we are never called on the application thread when we need to talk
            // to penimc or else we can cause reentrancy!
            Debug.Assert(!_contexts._inputSource.Value.CheckAccess());

            // We should always have a valid IPimcContext interface pointer.
            Debug.Assert(_pimcContext != null && _pimcContext.Value != null);
            
            _pimcContext.Value.GetPacketDescriptionInfo(out cProps, out cButtons); // Calls Unmanaged code - SecurityCritical with SUC.

            List<StylusPointPropertyInfo> propertyInfos = new List<StylusPointPropertyInfo>(cProps + cButtons + 3);
            for (int i = 0; i < cProps; i++)
            {
                Guid guid;
                int min, max;
                int units;
                float res;
                _pimcContext.Value.GetPacketPropertyInfo(i, out guid, out min, out max, out units, out res); // Calls Unmanaged code - SecurityCritical with SUC.

                if (pressureIndex == -1 && guid == StylusPointPropertyIds.NormalPressure)
                {
                    pressureIndex = i;
                }
                
                if (_statusPropertyIndex == -1 && guid == StylusPointPropertyIds.PacketStatus)
                {
                    _statusPropertyIndex = i;
                }

                StylusPointPropertyInfo propertyInfo = new StylusPointPropertyInfo(new StylusPointProperty(guid, false), min, max, (StylusPointPropertyUnit)units, res);
                
                propertyInfos.Add(propertyInfo);
            }

            Debug.Assert(_statusPropertyIndex != -1);  // We should always see this.
            
            // Make sure we actually created propertyInfos OK
            if (propertyInfos != null)
            {
                for (int i = 0; i < cButtons; i++)
                {
                    Guid buttonGuid;
                    _pimcContext.Value.GetPacketButtonInfo(i, out buttonGuid); // Calls Unmanaged code - SecurityCritical with SUC.

                    StylusPointProperty buttonProperty = new StylusPointProperty(buttonGuid, true);
                    StylusPointPropertyInfo buttonInfo = new StylusPointPropertyInfo(buttonProperty);
                    propertyInfos.Add(buttonInfo);
                }

                //validate we can never get X, Y at index != 0, 1
                Debug.Assert(propertyInfos[StylusPointDescription.RequiredXIndex /*0*/].Id == StylusPointPropertyIds.X, "X isn't where we expect it! Fix PenImc to ask for X at index 0");
                Debug.Assert(propertyInfos[StylusPointDescription.RequiredYIndex /*0*/].Id == StylusPointPropertyIds.Y, "Y isn't where we expect it! Fix PenImc to ask for Y at index 1");
                Debug.Assert(pressureIndex == -1 || pressureIndex == StylusPointDescription.RequiredPressureIndex /*2*/, 
                    "Fix PenImc to ask for NormalPressure at index 2!");
                if (pressureIndex == -1)
                {
                    //pressure wasn't found.  Add it
                    propertyInfos.Insert(StylusPointDescription.RequiredPressureIndex /*2*/, StylusPointPropertyInfoDefaults.NormalPressure);
                }
                _infoX = propertyInfos[0];
                _infoY = propertyInfos[1];
                
                _stylusPointDescription = new StylusPointDescription(propertyInfos, pressureIndex);
            }

        }
Beispiel #14
0
        /// <summary>
        /// Internal helper method for comparing compat for two StylusPointPropertyInfos
        /// </summary>
        internal static bool AreCompatible(StylusPointPropertyInfo stylusPointPropertyInfo1, StylusPointPropertyInfo stylusPointPropertyInfo2)
        {
            if (stylusPointPropertyInfo1 == null || stylusPointPropertyInfo2 == null)
            {
                throw new ArgumentNullException("stylusPointPropertyInfo");
            }

            Debug.Assert((stylusPointPropertyInfo1.Id != StylusPointPropertyIds.X &&
                          stylusPointPropertyInfo1.Id != StylusPointPropertyIds.Y &&
                          stylusPointPropertyInfo2.Id != StylusPointPropertyIds.X &&
                          stylusPointPropertyInfo2.Id != StylusPointPropertyIds.Y),
                         "Why are you checking X, Y for compatibility?  They're always compatible");
            //
            // we only take ID and IsButton into account, we don't take metrics into account
            //
            return(stylusPointPropertyInfo1.Id == stylusPointPropertyInfo2.Id &&
                   stylusPointPropertyInfo1.IsButton == stylusPointPropertyInfo2.IsButton);
        }
Beispiel #15
0
        /// <summary>
        /// Adds a new metric entry in the existing list of metric entries
        /// </summary>
        /// <param name="property"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        public MetricEntryType AddMetricEntry(StylusPointPropertyInfo property, KnownTagCache.KnownTagIndex tag)
        {
            // Create a new metric entry based on the packet information passed.
            MetricEntry entry = new MetricEntry();
            MetricEntryType type = entry.CreateMetricEntry(property, tag);

            // Don't add this entry to the global list if size is 0, means default metric values!
            if( 0 == entry.Size )
            {
                return type;
            }

            MetricEntry start = _Entry;
            if( null == start )
            {
                _Entry = entry;
            }
            else    // tack on data at the end, want to keep x,y at the beginning
            {
                while(start.Next != null)
                {
                    start = start.Next;
                }
                start.Next = entry;
            }
            _Count++;
            _size += entry.Size + SerializationHelper.VarSize(entry.Size) + SerializationHelper.VarSize((uint)_Entry.Tag);
            return type;
        }
Beispiel #16
0
        private void InitStylusPointDescription()
        {
            int cProps;
            int cButtons;
            int pressureIndex = -1;

            // Make sure we are never called on the application thread when we need to talk
            // to penimc or else we can cause reentrancy!
            Debug.Assert(!_contexts._inputSource.Value.CheckAccess());

            // We should always have a valid IPimcContext2 interface pointer.
            Debug.Assert(_pimcContext != null && _pimcContext.Value != null);

            _pimcContext.Value.GetPacketDescriptionInfo(out cProps, out cButtons); // Calls Unmanaged code - SecurityCritical with SUC.

            List <StylusPointPropertyInfo> propertyInfos = new List <StylusPointPropertyInfo>(cProps + cButtons + 3);

            for (int i = 0; i < cProps; i++)
            {
                Guid  guid;
                int   min, max;
                int   units;
                float res;
                _pimcContext.Value.GetPacketPropertyInfo(i, out guid, out min, out max, out units, out res); // Calls Unmanaged code - SecurityCritical with SUC.

                if (pressureIndex == -1 && guid == StylusPointPropertyIds.NormalPressure)
                {
                    pressureIndex = i;
                }

                if (_statusPropertyIndex == -1 && guid == StylusPointPropertyIds.PacketStatus)
                {
                    _statusPropertyIndex = i;
                }

                StylusPointPropertyInfo propertyInfo = new StylusPointPropertyInfo(new StylusPointProperty(guid, false), min, max, (StylusPointPropertyUnit)units, res);

                propertyInfos.Add(propertyInfo);
            }

            Debug.Assert(_statusPropertyIndex != -1);  // We should always see this.

            // Make sure we actually created propertyInfos OK
            if (propertyInfos != null)
            {
                for (int i = 0; i < cButtons; i++)
                {
                    Guid buttonGuid;
                    _pimcContext.Value.GetPacketButtonInfo(i, out buttonGuid); // Calls Unmanaged code - SecurityCritical with SUC.

                    StylusPointProperty     buttonProperty = new StylusPointProperty(buttonGuid, true);
                    StylusPointPropertyInfo buttonInfo     = new StylusPointPropertyInfo(buttonProperty);
                    propertyInfos.Add(buttonInfo);
                }

                //validate we can never get X, Y at index != 0, 1
                Debug.Assert(propertyInfos[StylusPointDescription.RequiredXIndex /*0*/].Id == StylusPointPropertyIds.X, "X isn't where we expect it! Fix PenImc to ask for X at index 0");
                Debug.Assert(propertyInfos[StylusPointDescription.RequiredYIndex /*0*/].Id == StylusPointPropertyIds.Y, "Y isn't where we expect it! Fix PenImc to ask for Y at index 1");
                Debug.Assert(pressureIndex == -1 || pressureIndex == StylusPointDescription.RequiredPressureIndex /*2*/,
                             "Fix PenImc to ask for NormalPressure at index 2!");
                if (pressureIndex == -1)
                {
                    //pressure wasn't found.  Add it
                    propertyInfos.Insert(StylusPointDescription.RequiredPressureIndex /*2*/, StylusPointPropertyInfoDefaults.NormalPressure);
                }
                _infoX = propertyInfos[0];
                _infoY = propertyInfos[1];

                _stylusPointDescription = new StylusPointDescription(propertyInfos, pressureIndex);
            }
        }
        /// <summary>
        /// Internal helper method for comparing compat for two StylusPointPropertyInfos
        /// </summary>
        internal static bool AreCompatible(StylusPointPropertyInfo stylusPointPropertyInfo1, StylusPointPropertyInfo stylusPointPropertyInfo2)
        {
            if (stylusPointPropertyInfo1 == null || stylusPointPropertyInfo2 == null)
            {
                throw new ArgumentNullException("stylusPointPropertyInfo");
            }

            Debug.Assert((  stylusPointPropertyInfo1.Id != StylusPointPropertyIds.X &&
                            stylusPointPropertyInfo1.Id != StylusPointPropertyIds.Y &&
                            stylusPointPropertyInfo2.Id != StylusPointPropertyIds.X &&
                            stylusPointPropertyInfo2.Id != StylusPointPropertyIds.Y),
                            "Why are you checking X, Y for compatibility?  They're always compatible");
            //
            // we only take ID and IsButton into account, we don't take metrics into account
            //
            return (stylusPointPropertyInfo1.Id == stylusPointPropertyInfo2.Id &&
                    stylusPointPropertyInfo1.IsButton == stylusPointPropertyInfo2.IsButton);
        }