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

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

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

            if (dwXValue != 0 && dwYValue != 0)
            {
                _doubleTapSize = new Size((int)Math.Round((ScreenSize.Width * DoubleTapDelta) / dwXValue),
                                          (int)Math.Round((ScreenSize.Height * 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;
            }

            _forceUpdateSizeDeltas = false;
        }
        protected void GetStylusParams(StylusPointDescription sd)
        {
            if (sd.HasProperty(StylusPointProperties.XTiltOrientation) &&
                sd.HasProperty(StylusPointProperties.YTiltOrientation))
            {
                StylusPointPropertyInfo tiltXInfo = sd.GetPropertyInfo(StylusPointProperties.XTiltOrientation);
                StylusPointPropertyInfo tiltYInfo = sd.GetPropertyInfo(StylusPointProperties.YTiltOrientation);

                mInputMinTiltX = tiltXInfo.Minimum;
                mInputMaxTiltX = tiltXInfo.Maximum;

                mInputMinTiltY = tiltYInfo.Minimum;
                mInputMaxTiltY = tiltYInfo.Maximum;

                mScaleTiltX = (mTargetMaxTiltX - mTargetMinTiltX) / (mInputMaxTiltX - mInputMinTiltX);
                mScaleTiltY = (mTargetMaxTiltY - mTargetMinTiltY) / (mInputMaxTiltY - mInputMinTiltY);
            }
            else
            {
                mScaleTiltX = 0;
                mScaleTiltY = 0;
            }
        }
Example #3
0
        // <Snippet21>
        void inkCanvas1_StylusMove(object sender, StylusEventArgs e)
        {
            StylusPointCollection  points             = e.GetStylusPoints(inkCanvas1);
            StylusPointDescription description        = points.Description;
            StringWriter           normalPressureInfo = new StringWriter();

            if (description.HasProperty(StylusPointProperties.NormalPressure))
            {
                StylusPointPropertyInfo propertyInfo =
                    description.GetPropertyInfo(StylusPointProperties.NormalPressure);

                normalPressureInfo.WriteLine("  Guid = {0}", propertyInfo.Id.ToString());
                normalPressureInfo.Write("  Min = {0}", propertyInfo.Minimum.ToString());
                normalPressureInfo.Write("  Max = {0}", propertyInfo.Maximum.ToString());
                normalPressureInfo.Write("  Unit = {0}", propertyInfo.Unit.ToString());
                normalPressureInfo.WriteLine("  Res = {0}", propertyInfo.Resolution.ToString());
            }
        }
Example #4
0
        /// <summary>
        /// Builds the Stroke Descriptor for this stroke based on Packet Layout and Extended Properties
        /// For details on how this is strored please refer to the spec.
        /// </summary>
        internal static void BuildStrokeDescriptor(
            Stroke stroke,
            GuidList guidList,
            StrokeCollectionSerializer.StrokeLookupEntry strokeLookupEntry,
            out StrokeDescriptor strokeDescriptor,
            out MetricBlock metricBlock)
        {
            // Initialize the metric block for this stroke
            metricBlock = new MetricBlock();

            // Clear any existing template
            strokeDescriptor = new StrokeDescriptor();

            // Uninitialized variable passed in AddMetricEntry
            MetricEntryType        metricEntryType;
            StylusPointDescription stylusPointDescription = stroke.StylusPoints.Description;

            KnownTagCache.KnownTagIndex tag = guidList.FindTag(KnownIds.X, true);
            metricEntryType = metricBlock.AddMetricEntry(stylusPointDescription.GetPropertyInfo(StylusPointProperties.X), tag);

            tag             = guidList.FindTag(KnownIds.Y, true);
            metricEntryType = metricBlock.AddMetricEntry(stylusPointDescription.GetPropertyInfo(StylusPointProperties.Y), tag);

            ReadOnlyCollection <StylusPointPropertyInfo> propertyInfos
                = stylusPointDescription.GetStylusPointProperties();

            int i = 0; //i is defined out of the for loop so we can use it later for buttons

            for (i = 2 /*past x,y*/; i < propertyInfos.Count; i++)
            {
                if (i == /*StylusPointDescription.RequiredPressureIndex //修复构建的代码 */ 2 &&
                    !strokeLookupEntry.StorePressure)
                {
                    //
                    // don't store pressure information
                    //
                    continue;
                }
                StylusPointPropertyInfo propertyInfo = propertyInfos[i];
                if (propertyInfo.IsButton)
                {
                    //we don't serialize buttons
                    break;
                }

                tag = guidList.FindTag(propertyInfo.Id, true);

                strokeDescriptor.Template.Add(tag);
                strokeDescriptor.Size += SerializationHelper.VarSize((uint)tag);

                // Create the MetricEntry for this property if necessary
                metricEntryType = metricBlock.AddMetricEntry(propertyInfo, tag);
            }

            /*
             * we drop button data on the floor.
             * int buttonCount = stylusPointDescription.ButtonCount;
             * // Now write the button tags in the Template
             * if (buttonCount > 0)
             * {
             *  // First write the TAG_BUTTONS
             *  strokeDescriptor.Template.Add(KnownTagCache.KnownTagIndex.Buttons);
             *  strokeDescriptor.Size += SerializationHelper.VarSize((uint)KnownTagCache.KnownTagIndex.Buttons);
             *
             *  // Next write the i of buttons
             *  strokeDescriptor.Template.Add((KnownTagCache.KnownTagIndex)buttonCount);
             *  strokeDescriptor.Size += SerializationHelper.VarSize((uint)buttonCount);
             *
             *  //we broke above on i when it was a button, it still
             *  //points to the first button
             *  for (; i < propertyInfos.Count; i++)
             *  {
             *      StylusPointPropertyInfo propertyInfo = propertyInfos[i];
             *      tag = guidList.FindTag(propertyInfo.Id, false);
             *
             *      strokeDescriptor.Template.Add(tag);
             *      strokeDescriptor.Size += SerializationHelper.VarSize((uint)tag);
             *  }
             * }
             */

            // Now write the extended properties in the template
            if (stroke.ExtendedProperties.Count > 0)
            {
                strokeDescriptor.Template.Add(KnownTagCache.KnownTagIndex.StrokePropertyList);
                strokeDescriptor.Size += SerializationHelper.VarSize((uint)KnownTagCache.KnownTagIndex.StrokePropertyList);

                // Now write the tags corresponding to each extended properties of the stroke
                for (int x = 0; x < stroke.ExtendedProperties.Count; x++)
                {
                    tag = guidList.FindTag(stroke.ExtendedProperties[(int)x].Id, false);

                    strokeDescriptor.Template.Add(tag);
                    strokeDescriptor.Size += SerializationHelper.VarSize((uint)tag);
                }
            }
        }