コード例 #1
0
ファイル: FormSelRegion.cs プロジェクト: stndstn/InkNote
        void mInkPicture_NewPackets(object sender, InkCollectorNewPacketsEventArgs e)
        {
            //Console.WriteLine("mInkPicture_NewPackets PacketCount={0}", e.PacketCount);
            //if (this.DialogResult != System.Windows.Forms.DialogResult.None) return;
            if (dlgRes != System.Windows.Forms.DialogResult.None) return;

            float[] intersections = e.Stroke.SelfIntersections;
            if (intersections.Length > 0)
            {
                String msg = "SelfIntersections=";
                foreach (float f in intersections)
                {
                    msg += f + " ";
                }
                Console.WriteLine(msg);

                try
                {
                    int ipt1 = (int)Math.Round(intersections[0], 0);
                    int ipt2 = (int)Math.Round(intersections[intersections.Length - 1], 0);
                    int count = ipt2 - ipt1;
                    Point[] pts = e.Stroke.GetPoints();
                    Point[] ptPath = new Point[count];
                    //Graphics g = Graphics.FromImage(mBgBmp);
                    Graphics g = mInkPicture.CreateGraphics();
                    mInkPicture.Renderer.InkSpaceToPixel(g, ref pts);
                    Array.Copy(pts, ipt1, ptPath, 0, count);
                    Pen p = new Pen(Color.Red);
                    g.DrawPolygon(p, ptPath);

                    dlgRes = MessageBox.Show("Clip and Copy this region?", "Selection", MessageBoxButtons.YesNoCancel);
                    if (dlgRes == System.Windows.Forms.DialogResult.Yes)
                    {
                        System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                        path.AddClosedCurve(ptPath);
                        if (mSelRegion != null) mSelRegion.Dispose();
                        mSelRegion = new Region(path);
                        mRegionPath = ptPath;
                    }
                    g.Dispose();

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        /// <summary>
        /// Event Handler from Ink Collector's NewPackets event
        ///
        /// This event is fired when the Ink Collector receives
        /// new packet data.
        /// </summary>
        /// <param name="sender">The control that raised the event.</param>
        /// <param name="e">The event arguments.</param>
        private void myInkCollector_NewPackets(object sender, InkCollectorNewPacketsEventArgs e)
        {
            // If the cursor is inverted
            if (e.Cursor.Inverted)
            {
                // retrieve the size of each packet
                int packetSize = e.Stroke.PacketSize;

                Point pt = Point.Empty;

                // Perform a hit test with each point and delete
                // the hit strokes
                for (int i = 0; i < e.PacketCount; i++)
                {
                    // retrieve the x and y packet values
                    pt.X = e.PacketData[i * packetSize + XPacketIndex];
                    pt.Y = e.PacketData[i * packetSize + YPacketIndex];

                    EraseStrokes(pt, e.Stroke);
                }
            }
        }
コード例 #4
0
        // --------------- Ink Collector Events ---------------
        /// <summary>
        /// Event Handler from Ink Collector's NewPackets event
        /// 
        /// This event is fired when the Ink Collector receives 
        /// new packet data and the user is drawing a lasso.  
        /// In this case,  it is necessary to intercept the new packets
        /// and use them to draw the selection lasso.
        /// </summary>
        /// <param name="sender">The control that raised the event.</param>
        /// <param name="e">The event arguments.</param>
        private void myInkCollector_NewPackets(object sender, InkCollectorNewPacketsEventArgs e)
        {
            // retrieve the size of each packet
            int packetDescriptionLength = e.Stroke.PacketDescription.Length;

            // the index where the new lasso points will be added
            int newPacketIndex = lassoPoints.Count;

            using (Graphics g = CreateGraphics())
            {

                // Add each new packet into the lasso points collection
                for (int i = 0; i < e.PacketCount; i++)
                {

                    // retrieve the x and y packet values
                    Point pt = new Point(e.PacketData[i * packetDescriptionLength + XPacketIndex],
                                         e.PacketData[i * packetDescriptionLength + YPacketIndex]);

                    myInkCollector.Renderer.InkSpaceToPixel(g, ref pt);

                    // If the x or y packet values fall outside of
                    // the drawing area , update them to the nearest
                    // location on the drawing area.  This adjustment
                    // prevents the lasso's boundaries from going
                    // beyond the drawing area.
                    if (pt.X<0)
                    {
                        pt.X = 0;
                    }
                    if (pt.X>ClientSize.Width)
                    {
                        pt.X = ClientSize.Width;
                    }
                    if (pt.Y<0)
                    {
                        pt.Y = 0;
                    }
                    if (pt.Y>this.ClientSize.Height)
                    {
                        pt.Y = ClientSize.Height;
                    }

                    // Add the new point into the lasso points collection
                    lassoPoints.Add(pt);

                }

                // Draw the updated lasso.  In order to improve performance,
                // only the new lasso packets will be drawn.
                DrawLasso(g,newPacketIndex);
            }
        }
コード例 #5
0
        /// <summary>
        /// Event Handler from Ink Collector's NewPackets event
        /// 
        /// This event is fired when the Ink Collector receives 
        /// new packet data.  
        /// </summary>
        /// <param name="sender">The control that raised the event.</param>
        /// <param name="e">The event arguments.</param>
        private void myInkCollector_NewPackets(object sender, InkCollectorNewPacketsEventArgs e)
        {
            // If the cursor is inverted
            if (e.Cursor.Inverted)
            {

                // retrieve the size of each packet
                int packetSize = e.Stroke.PacketSize;

                Point pt = Point.Empty;

                // Perform a hit test with each point and delete
                // the hit strokes
                for (int i = 0; i < e.PacketCount; i++)
                {
                    // retrieve the x and y packet values
                    pt.X = e.PacketData[i*packetSize+XPacketIndex];
                    pt.Y = e.PacketData[i*packetSize+YPacketIndex];

                    EraseStrokes(pt,e.Stroke);
                }
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: AMitchell-GitHub/FreePad
 private void inkCollector_NewPackets(object sender, InkCollectorNewPacketsEventArgs e)
 {
 }