Ejemplo n.º 1
0
        /// <summary>
        /// We create a stroke with points close and then add the stroke to the canvas.
        /// If the points are far apart, we create a new stroke for those points.
        /// </summary>
        /// <param name="inkCanvas"></param>
        /// <param name="strokeInfo"></param>
        public static void AddStrokePreview(this InkCanvas inkCanvas, StrokeInfo strokeInfo)
        {
            StylusPoint           firstPoint = strokeInfo.PointCollection[0];
            StylusPointCollection tmpPoints  = new StylusPointCollection();

            tmpPoints.Add(firstPoint);

            for (int i = 0; i < strokeInfo.PointCollection.Count - 1; i++)
            {
                if (CalculateDistance(strokeInfo.PointCollection[i], strokeInfo.PointCollection[i + 1]) < 5)
                {
                    tmpPoints.Add(strokeInfo.PointCollection[i + 1]);
                }
                else
                {
                    inkCanvas.Strokes.Add(CreateStroke(strokeInfo, tmpPoints.Clone()));
                    tmpPoints.Clear();
                    tmpPoints.Add(strokeInfo.PointCollection[i + 1]);
                }
            }

            if (tmpPoints.Count > 0)
            {
                inkCanvas.Strokes.Add(CreateStroke(strokeInfo, tmpPoints));
            }
        }
Ejemplo n.º 2
0
        void ClonePoints()
        {
            //<Snippet18>
            Point[] rawPoints = new Point[]
            {
                new Point(100, 100),
                new Point(100, 200),
                new Point(200, 250),
                new Point(300, 300)
            };

            StylusPointCollection points1 = new StylusPointCollection(rawPoints);

            // Create a copy of points1 and change the second StylusPoint.
            StylusPointCollection points2 = points1.Clone();

            points2[1] = new StylusPoint(200, 100);

            // Create a stroke from each StylusPointCollection and add them to
            // inkCanvas1. Note that changing a StylusPoint in point2 did not
            // affect points1.
            Stroke stroke1 = new Stroke(points1);

            inkCanvas1.Strokes.Add(stroke1);

            Stroke stroke2 = new Stroke(points2);

            stroke2.DrawingAttributes.Color = Colors.Red;
            inkCanvas1.Strokes.Add(stroke2);
            //</Snippet18>
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Returns a StylusPointCollection object for processing the data in the packet.
        ///     This method creates a new StylusPointCollection and copies the data.
        /// </summary>
        internal override StylusPointCollection GetStylusPoints(IInputElement relativeTo)
        {
            VerifyAccess();

            // Fake up an empty one if we have to.
            if (_currentStylusPoints == null)
            {
                return(new StylusPointCollection(_tabletDevice.StylusPointDescription));
            }
            return(_currentStylusPoints.Clone(StylusDevice.GetElementTransform(relativeTo), _currentStylusPoints.Description));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Replaces the StylusPoints.
        /// </summary>
        /// <remarks>
        ///     Callers must have Unmanaged code permission to call this API.
        /// </remarks>
        /// <param name="stylusPoints">stylusPoints</param>
        public void SetStylusPoints(StylusPointCollection stylusPoints)
        {
            if (null == stylusPoints)
            {
                throw new ArgumentNullException("stylusPoints");
            }

            if (!StylusPointDescription.AreCompatible(stylusPoints.Description,
                                                      _report.StylusPointDescription))
            {
                throw new ArgumentException(SR.Get(SRID.IncompatibleStylusPointDescriptions), "stylusPoints");
            }
            if (stylusPoints.Count == 0)
            {
                throw new ArgumentException(SR.Get(SRID.Stylus_StylusPointsCantBeEmpty), "stylusPoints");
            }

            _stylusPoints = stylusPoints.Clone();
        }
Ejemplo n.º 5
0
        public void SetStylusPoints(StylusPointCollection stylusPoints)
        {
            // To modify the points we require Unmanaged code permission.
            SecurityHelper.DemandUnmanagedCode();

            if (null == stylusPoints)
            {
                throw new ArgumentNullException("stylusPoints");
            }

            if (!StylusPointDescription.AreCompatible(stylusPoints.Description,
                                                      _report.StylusPointDescription))
            {
                throw new ArgumentException(SR.Get(SRID.IncompatibleStylusPointDescriptions), "stylusPoints");
            }
            if (stylusPoints.Count == 0)
            {
                throw new ArgumentException(SR.Get(SRID.Stylus_StylusPointsCantBeEmpty), "stylusPoints");
            }

            _stylusPoints = stylusPoints.Clone();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Retrieve the packet description, packets data and XFORM which is the information the native recognizer needs.
        /// The method is called from AddStrokes.
        /// </summary>
        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);
            }
        }
Ejemplo n.º 7
0
        public void SetStylusPoints(StylusPointCollection stylusPoints)
        {
            // To modify the points we require Unmanaged code permission.
            SecurityHelper.DemandUnmanagedCode();
            
            if (null == stylusPoints)
            {
                throw new ArgumentNullException("stylusPoints");
            }

            if (!StylusPointDescription.AreCompatible(  stylusPoints.Description,
                                                        _report.StylusPointDescription))
            {
                throw new ArgumentException(SR.Get(SRID.IncompatibleStylusPointDescriptions), "stylusPoints");
            }
            if (stylusPoints.Count == 0)
            {
                throw new ArgumentException(SR.Get(SRID.Stylus_StylusPointsCantBeEmpty), "stylusPoints");
            }

            _stylusPoints = stylusPoints.Clone();
        }