Ejemplo n.º 1
0
        private double GetStylusPointWidthOrHeight(StylusPoint stylusPoint, bool isWidth)
        {
            const double CentimeterPerInch = 2.54d;
            const double PixelPerInch      = 96d;

            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 /= CentimeterPerInch;
                }

                // Convert the value to pixels
                value *= PixelPerInch;
            }
            return(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// StylusPointProperty
        /// </summary>
        /// <param name="stylusPointProperty"></param>
        /// <param name="minimum">minimum</param>
        /// <param name="maximum">maximum</param>
        /// <param name="unit">unit</param>
        /// <param name="resolution">resolution</param>
        public StylusPointPropertyInfo(StylusPointProperty stylusPointProperty, int minimum, int maximum, StylusPointPropertyUnit unit, float resolution)
            : base(stylusPointProperty) //base checks for null
        {
            // validate unit
            if (!StylusPointPropertyUnitHelper.IsDefined(unit))
            {
                throw new InvalidEnumArgumentException("unit", (int)unit, typeof(StylusPointPropertyUnit));
            }

            // validate min/max
            if (maximum < minimum)
            {
                throw new ArgumentException(SR.Get(SRID.Stylus_InvalidMax), "maximum");
            }

            // validate resolution
            if (resolution < 0.0f)
            {
                throw new ArgumentException(SR.Get(SRID.InvalidStylusPointPropertyInfoResolution), "resolution");
            }

            _min = minimum;
            _max = maximum;
            _resolution = resolution;
            _unit = unit;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// StylusPointProperty
        /// </summary>
        /// <param name="stylusPointProperty"></param>
        /// <param name="minimum">minimum</param>
        /// <param name="maximum">maximum</param>
        /// <param name="unit">unit</param>
        /// <param name="resolution">resolution</param>
        public StylusPointPropertyInfo(StylusPointProperty stylusPointProperty, int minimum, int maximum, StylusPointPropertyUnit unit, float resolution)
            : base(stylusPointProperty) //base checks for null
        {
            // validate unit
            if (!StylusPointPropertyUnitHelper.IsDefined(unit))
            {
                throw new InvalidEnumArgumentException("unit", (int)unit, typeof(StylusPointPropertyUnit));
            }

            // validate min/max
            if (maximum < minimum)
            {
                throw new ArgumentException(SR.Get(SRID.Stylus_InvalidMax), "maximum");
            }

            // validate resolution
            if (resolution < 0.0f)
            {
                throw new ArgumentException(SR.Get(SRID.InvalidStylusPointPropertyInfoResolution), "resolution");
            }

            _min        = minimum;
            _max        = maximum;
            _resolution = resolution;
            _unit       = unit;
        }
 /// <summary>
 /// StylusPointProperty
 /// </summary>
 /// <param name="stylusPointProperty"></param>
 /// <remarks>Protected - used by the StylusPointPropertyInfo ctor</remarks>
 protected StylusPointProperty(StylusPointProperty stylusPointProperty)
 {
     if (null == stylusPointProperty)
     {
         throw new ArgumentNullException("stylusPointProperty");
     }
     Initialize(stylusPointProperty.Id, stylusPointProperty.IsButton);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// StylusPointProperty
 /// </summary>
 /// <param name="stylusPointProperty"></param>
 /// <remarks>Protected - used by the StylusPointPropertyInfo ctor</remarks>
 protected StylusPointProperty(StylusPointProperty stylusPointProperty)
 {
     if (null == stylusPointProperty)
     {
         throw new ArgumentNullException("stylusPointProperty");
     }
     Initialize(stylusPointProperty.Id, stylusPointProperty.IsButton);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// GetProperty
 /// </summary>
 /// <param name="stylusPointProperty">stylusPointProperty</param>
 public StylusPointPropertyInfo GetPropertyInfo(StylusPointProperty stylusPointProperty)
 {
     if (null == stylusPointProperty)
     {
         throw new ArgumentNullException("stylusPointProperty");
     }
     return(GetPropertyInfo(stylusPointProperty.Id));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// For a given StylusPointProperty, instantiates a StylusPointPropertyInfo with default values
        /// </summary>
        /// <param name="stylusPointProperty"></param>
        public StylusPointPropertyInfo(StylusPointProperty stylusPointProperty)
            : base(stylusPointProperty)  //base checks for null
        {
            StylusPointPropertyInfo info =
                StylusPointPropertyInfoDefaults.GetStylusPointPropertyInfoDefault(stylusPointProperty);

            _min        = info.Minimum;
            _max        = info.Maximum;
            _resolution = info.Resolution;
            _unit       = info.Unit;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// For a given StylusPointProperty, instantiates a StylusPointPropertyInfo with default values
 /// </summary>
 /// <param name="stylusPointProperty"></param>
 public StylusPointPropertyInfo(StylusPointProperty stylusPointProperty) 
     : base (stylusPointProperty) //base checks for null
 {
     StylusPointPropertyInfo info =
         StylusPointPropertyInfoDefaults.GetStylusPointPropertyInfoDefault(stylusPointProperty);
     _min = info.Minimum;
     _max = info.Maximum;
     _resolution = info.Resolution;
     _unit = info.Unit;
     
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Provides read access to all stylus properties
        /// </summary>
        /// <param name="stylusPointProperty">The StylusPointPropertyIds of the property to retrieve</param>
        public int GetPropertyValue(StylusPointProperty stylusPointProperty)
        {
            if (null == stylusPointProperty)
            {
                throw new ArgumentNullException("stylusPointProperty");
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.X)
            {
                return((int)_x);
            }
            else if (stylusPointProperty.Id == StylusPointPropertyIds.Y)
            {
                return((int)_y);
            }
            else if (stylusPointProperty.Id == StylusPointPropertyIds.NormalPressure)
            {
                StylusPointPropertyInfo info =
                    this.Description.GetPropertyInfo(StylusPointProperties.NormalPressure);

                int max = info.Maximum;
                return((int)(_pressureFactor * (float)max));
            }
            else
            {
                int propertyIndex = this.Description.GetPropertyIndex(stylusPointProperty.Id);
                if (-1 == propertyIndex)
                {
                    throw new ArgumentException(SR.Get(SRID.InvalidStylusPointProperty), "stylusPointProperty");
                }
                if (stylusPointProperty.IsButton)
                {
                    //
                    // 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 ((buttonData & bit) != 0)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(_additionalValues[propertyIndex - 3]);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// HasProperty
        /// </summary>
        /// <param name="stylusPointProperty">stylusPointProperty</param>
        public bool HasProperty(StylusPointProperty stylusPointProperty)
        {
            if (null == stylusPointProperty)
            {
                throw new ArgumentNullException("stylusPointProperty");
            }

            int index = IndexOf(stylusPointProperty.Id);

            if (-1 == index)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Internal helper for determining what bit position the button is at
        /// </summary>
        internal int GetButtonBitPosition(StylusPointProperty buttonProperty)
        {
            if (!buttonProperty.IsButton)
            {
                throw new InvalidOperationException();
            }
            int buttonIndex = 0;

            for (int x = _stylusPointPropertyInfos.Length - _buttonCount; //start of the buttons
                 x < _stylusPointPropertyInfos.Length; x++)
            {
                if (_stylusPointPropertyInfos[x].Id == buttonProperty.Id)
                {
                    return(buttonIndex);
                }
                if (_stylusPointPropertyInfos[x].IsButton)
                {
                    // we're in the buttons, but this isn't the right one,
                    // bump the button index and keep looking
                    buttonIndex++;
                }
            }
            return(-1);
        }
Ejemplo n.º 12
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 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);
            }

        }
Ejemplo n.º 13
0
 /// <summary>
 /// Allows supported properties to be set
 /// </summary>
 /// <param name="stylusPointProperty">The property to set, it must exist on this StylusPoint</param>
 /// <param name="value">value</param>
 public void SetPropertyValue(StylusPointProperty stylusPointProperty, int value)
 {
     SetPropertyValue(stylusPointProperty, value, true);
 }
Ejemplo n.º 14
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;
                }
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Returns true if this StylusPoint supports the specified property
 /// </summary>
 /// <param name="stylusPointProperty">The StylusPointProperty to see if this StylusPoint supports</param>
 public bool HasProperty(StylusPointProperty stylusPointProperty)
 {
     return(this.Description.HasProperty(stylusPointProperty));
 }
 public int GetPropertyValue(StylusPointProperty stylusPointProperty)
 {
     return(default(int));
 }
 public bool HasProperty(StylusPointProperty stylusPointProperty)
 {
   return default(bool);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// GetProperty
 /// </summary>
 /// <param name="stylusPointProperty">stylusPointProperty</param>
 public StylusPointPropertyInfo GetPropertyInfo(StylusPointProperty stylusPointProperty)
 {
     if (null == stylusPointProperty)
     {
         throw new ArgumentNullException("stylusPointProperty");
     }
     return GetPropertyInfo(stylusPointProperty.Id);
 }
 public StylusPointPropertyInfo(StylusPointProperty stylusPointProperty) : base (default(StylusPointProperty))
 {
 }
        /// <summary>
        /// For a given StylusPointProperty, return the default property info
        /// </summary>
        /// <param name="stylusPointProperty">stylusPointProperty</param>
        /// <returns></returns>
        internal static StylusPointPropertyInfo GetStylusPointPropertyInfoDefault(StylusPointProperty stylusPointProperty)
        {
            if (stylusPointProperty.Id == StylusPointPropertyIds.X)
            {
                return StylusPointPropertyInfoDefaults.X;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.Y)
            {
                return StylusPointPropertyInfoDefaults.Y;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.Z)
            {
                return StylusPointPropertyInfoDefaults.Z;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.Width)
            {
                return StylusPointPropertyInfoDefaults.Width;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.Height)
            {
                return StylusPointPropertyInfoDefaults.Height;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.SystemTouch)
            {
                return StylusPointPropertyInfoDefaults.SystemTouch;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.PacketStatus)
            {
                return StylusPointPropertyInfoDefaults.PacketStatus;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.SerialNumber)
            {
                return StylusPointPropertyInfoDefaults.SerialNumber;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.NormalPressure)
            {
                return StylusPointPropertyInfoDefaults.NormalPressure;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.TangentPressure)
            {
                return StylusPointPropertyInfoDefaults.TangentPressure;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.ButtonPressure)
            {
                return StylusPointPropertyInfoDefaults.ButtonPressure;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.XTiltOrientation)
            {
                return StylusPointPropertyInfoDefaults.XTiltOrientation;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.YTiltOrientation)
            {
                return StylusPointPropertyInfoDefaults.YTiltOrientation;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.AzimuthOrientation)
            {
                return StylusPointPropertyInfoDefaults.AzimuthOrientation;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.AltitudeOrientation)
            {
                return StylusPointPropertyInfoDefaults.AltitudeOrientation;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.TwistOrientation)
            {
                return StylusPointPropertyInfoDefaults.TwistOrientation;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.PitchRotation)
            {
                return StylusPointPropertyInfoDefaults.PitchRotation;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.RollRotation)
            {
                return StylusPointPropertyInfoDefaults.RollRotation;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.YawRotation)
            {
                return StylusPointPropertyInfoDefaults.YawRotation;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.TipButton)
            {
                return StylusPointPropertyInfoDefaults.TipButton;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.BarrelButton)
            {
                return StylusPointPropertyInfoDefaults.BarrelButton;
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.SecondaryTipButton)
            {
                return StylusPointPropertyInfoDefaults.SecondaryTipButton;
            }

            //
            // return a default
            //
            if (stylusPointProperty.IsButton)
            {
                return StylusPointPropertyInfoDefaults.DefaultButton;
            }
            return StylusPointPropertyInfoDefaults.DefaultValue;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// For a given StylusPointProperty, return the default property info
        /// </summary>
        /// <param name="stylusPointProperty">stylusPointProperty</param>
        /// <returns></returns>
        internal static StylusPointPropertyInfo GetStylusPointPropertyInfoDefault(StylusPointProperty stylusPointProperty)
        {
            if (stylusPointProperty.Id == StylusPointPropertyIds.X)
            {
                return(StylusPointPropertyInfoDefaults.X);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.Y)
            {
                return(StylusPointPropertyInfoDefaults.Y);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.Z)
            {
                return(StylusPointPropertyInfoDefaults.Z);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.Width)
            {
                return(StylusPointPropertyInfoDefaults.Width);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.Height)
            {
                return(StylusPointPropertyInfoDefaults.Height);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.SystemTouch)
            {
                return(StylusPointPropertyInfoDefaults.SystemTouch);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.PacketStatus)
            {
                return(StylusPointPropertyInfoDefaults.PacketStatus);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.SerialNumber)
            {
                return(StylusPointPropertyInfoDefaults.SerialNumber);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.NormalPressure)
            {
                return(StylusPointPropertyInfoDefaults.NormalPressure);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.TangentPressure)
            {
                return(StylusPointPropertyInfoDefaults.TangentPressure);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.ButtonPressure)
            {
                return(StylusPointPropertyInfoDefaults.ButtonPressure);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.XTiltOrientation)
            {
                return(StylusPointPropertyInfoDefaults.XTiltOrientation);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.YTiltOrientation)
            {
                return(StylusPointPropertyInfoDefaults.YTiltOrientation);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.AzimuthOrientation)
            {
                return(StylusPointPropertyInfoDefaults.AzimuthOrientation);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.AltitudeOrientation)
            {
                return(StylusPointPropertyInfoDefaults.AltitudeOrientation);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.TwistOrientation)
            {
                return(StylusPointPropertyInfoDefaults.TwistOrientation);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.PitchRotation)
            {
                return(StylusPointPropertyInfoDefaults.PitchRotation);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.RollRotation)
            {
                return(StylusPointPropertyInfoDefaults.RollRotation);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.YawRotation)
            {
                return(StylusPointPropertyInfoDefaults.YawRotation);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.TipButton)
            {
                return(StylusPointPropertyInfoDefaults.TipButton);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.BarrelButton)
            {
                return(StylusPointPropertyInfoDefaults.BarrelButton);
            }
            if (stylusPointProperty.Id == StylusPointPropertyIds.SecondaryTipButton)
            {
                return(StylusPointPropertyInfoDefaults.SecondaryTipButton);
            }

            //
            // return a default
            //
            if (stylusPointProperty.IsButton)
            {
                return(StylusPointPropertyInfoDefaults.DefaultButton);
            }
            return(StylusPointPropertyInfoDefaults.DefaultValue);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// HasProperty
        /// </summary>
        /// <param name="stylusPointProperty">stylusPointProperty</param>
        public bool HasProperty(StylusPointProperty stylusPointProperty)
        {
            if (null == stylusPointProperty)
            {
                throw new ArgumentNullException("stylusPointProperty");
            }

            int index = IndexOf(stylusPointProperty.Id);
            if (-1 == index)
            {
                return false;
            }
            return true;
        }
Ejemplo n.º 23
0
        private static void InitializeSupportedStylusPointProperties(IPimcTablet pimcTablet, TabletDeviceInfo tabletInfo)
        {
            int cProps;
            int cButtons;
            int pressureIndex = -1;

            pimcTablet.GetPacketDescriptionInfo(out cProps, out cButtons); // Calls Unmanaged code - SecurityCritical with SUC.
            List<StylusPointProperty> properties = new List<StylusPointProperty>(cProps + cButtons + 3);
            for ( int i = 0; i < cProps; i++ )
            {
                Guid guid;
                int min, max;
                int units;
                float res;
                pimcTablet.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;
                }

                StylusPointProperty property = new StylusPointProperty(guid, false);
                properties.Add(property);
            }

            for ( int i = 0; i < cButtons; i++ )
            {
                Guid buttonGuid;
                pimcTablet.GetPacketButtonInfo(i, out buttonGuid); // Calls Unmanaged code - SecurityCritical with SUC.

                StylusPointProperty buttonProperty = new StylusPointProperty(buttonGuid, true);
                properties.Add(buttonProperty);
            }

            //validate we can never get X, Y at index != 0, 1
            Debug.Assert(properties[StylusPointDescription.RequiredXIndex /*0*/].Id == StylusPointPropertyIds.X, "X isn't where we expect it! Fix PenImc to ask for X at index 0");
            Debug.Assert(properties[StylusPointDescription.RequiredYIndex /*1*/].Id == StylusPointPropertyIds.Y, "Y isn't where we expect it! Fix PenImc to ask for Y at index 1");
            // NOTE: We can't force pressure since touch digitizers may not provide this info.  The following assert is bogus.
            //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
                properties.Insert(StylusPointDescription.RequiredPressureIndex /*2*/, System.Windows.Input.StylusPointProperties.NormalPressure);
            }
            else
            {
                //this device supports pressure
                tabletInfo.HardwareCapabilities |= TabletHardwareCapabilities.SupportsPressure;
            }

            tabletInfo.StylusPointProperties = new ReadOnlyCollection<StylusPointProperty>(properties);
            tabletInfo.PressureIndex = pressureIndex;
        }
Ejemplo n.º 24
0
 public StylusPointPropertyInfo(StylusPointProperty stylusPointProperty) : base(default(StylusPointProperty))
 {
 }
Ejemplo n.º 25
0
 public StylusPointPropertyInfo(StylusPointProperty stylusPointProperty, int minimum, int maximum, StylusPointPropertyUnit unit, float resolution) : base(default(StylusPointProperty))
 {
 }
 public void SetPropertyValue(StylusPointProperty stylusPointProperty, int value)
 {
 }
 public bool HasProperty(StylusPointProperty stylusPointProperty)
 {
     return(default(bool));
 }
 public StylusPointPropertyInfo(StylusPointProperty stylusPointProperty, int minimum, int maximum, StylusPointPropertyUnit unit, float resolution) : base (default(StylusPointProperty))
 {
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Internal helper for determining what bit position the button is at
 /// </summary>
 internal int GetButtonBitPosition(StylusPointProperty buttonProperty)
 {
     if (!buttonProperty.IsButton)
     {
         throw new InvalidOperationException();
     }
     int buttonIndex = 0;
     for (int x = _stylusPointPropertyInfos.Length - _buttonCount; //start of the buttons
          x < _stylusPointPropertyInfos.Length; x++)
     {
         if (_stylusPointPropertyInfos[x].Id == buttonProperty.Id)
         {
             return buttonIndex;
         }
         if (_stylusPointPropertyInfos[x].IsButton)
         {
             // we're in the buttons, but this isn't the right one,
             // bump the button index and keep looking
             buttonIndex++;
         }
     }
     return -1;
 }
Ejemplo n.º 30
0
        /// <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);
        }
 public StylusPointPropertyInfo GetPropertyInfo(StylusPointProperty stylusPointProperty)
 {
   return default(StylusPointPropertyInfo);
 }
Ejemplo n.º 32
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);
            }
        }
 public StylusPointPropertyInfo GetPropertyInfo(StylusPointProperty stylusPointProperty)
 {
     return(default(StylusPointPropertyInfo));
 }