示例#1
0
        private void Overlay_NewPackets(object sender, InkCollectorNewPacketsEventArgs e)
        {
            /*** THIS ROUTINE MUST BE EXTREMELY FAST ***/

            /*
             * Since we are handling a flurry of packet
             * data, this routine should not perform any
             * significant processing, just data recording.
             *
             * Asynchronous invocation on the windows forms
             * thread is used to delay as much sample
             * processing as possible.
             */

            //go over the packet data and store InkSamples
            int[] PacketData = e.PacketData;

            if (PacketData[2] == 0)            //new stroke since timer is 0; use the internal timer to compute the time of the first packet
            {
                //check if the packets have pressure data
                Tablet CurrentTablet = e.Cursor.Tablet;
                Overlay_NewPackets_PacketsHavePressure = CurrentTablet != null &&
                                                         CurrentTablet.IsPacketPropertySupported(PacketProperty.NormalPressure);

                //raise the NewInkSample event with an invalid ink sample to signal a new stroke to listeners
                _Overlay.AttachedControl.BeginInvoke(new NewRawInkSampleHandler(OnNewRawInkSample), new RawInkSample(_Timer.Now()));
            }

            for (int i = 0; i < PacketData.Length;)
            {
                RawInkSample s = new RawInkSample();

                s.Time = _Timer.Now();

                s.X = PacketData[i++];
                s.Y = PacketData[i++];
                i++;    //skip the timer sample
                s.Pressure = Overlay_NewPackets_PacketsHavePressure ? PacketData[i++] : 0;


                //have the form thread raise the NewInkSample event at its convenience
                _Overlay.AttachedControl.BeginInvoke(new NewRawInkSampleHandler(OnNewRawInkSample), s);
            }
        }