Пример #1
0
 private void OnTouchUpHandler(object sender, WMTouchEventArgs e)
 {
     lock (m_touchlock)
     {
         this.touches.Remove(e.Id);
     }
 }
        private void OnTouchUpHandler(object sender, WMTouchEventArgs e)
        {
            Stroke stroke = ActiveStrokes.Remove(e.Id);

            Debug.Assert(stroke != null);
            FinishedStrokes.Add(stroke);
            Invalidate();
        }
        private void OnTouchMoveHandler(object sender, WMTouchEventArgs e)
        {
            Stroke stroke = ActiveStrokes.Get(e.Id);

            Debug.Assert(stroke != null);
            stroke.Add(new Point(e.LocationX, e.LocationY));
            stroke.DrawLast(graphics);
        }
Пример #4
0
 private void OnTouchMoveHandler(object sender, WMTouchEventArgs e)
 {
     lock (m_touchlock)
     {
         TouchData t = this.touches[e.Id];
         t.Pos = new Vector2(e.LocationX, e.LocationY);
     }
 }
        private void OnTouchDownHandler(object sender, WMTouchEventArgs e)
        {
            Debug.Assert(ActiveStrokes.Get(e.Id) == null);
            Stroke newStroke = new Stroke(penWidth);

            newStroke.Color = touchColor.GetColor(e.IsPrimaryContact);
            newStroke.Id    = e.Id;
            ActiveStrokes.Add(newStroke);
        }
        public static TouchUpNotification ToTouchUpNotification(this WMTouchEventArgs eventArgs, Control relativeTo)
        {
            if (STouchUpNotificationConstructor == null) //find correct constructor
            {
                STouchUpNotificationConstructor = FindTouchNotificationConstructor <TouchUpNotification>();
            }

            return(ConstructTouchNotification <TouchUpNotification>(STouchUpNotificationConstructor, eventArgs, relativeTo));
        }
Пример #7
0
 private void OnTouchDownHandler(object sender, WMTouchEventArgs e)
 {
     lock (m_touchlock)
     {
         TouchData t = new TouchData();
         t.Id    = e.Id;
         t.IsNew = true;
         t.Pos   = new Vector2(e.LocationX, e.LocationY);
         this.touches.Add(e.Id, t);
     }
 }
Пример #8
0
        private bool DecodeTouch(ref Message m)
        {
            int inputCount = LoWord(m.WParam.ToInt32());

            TOUCHINPUT[] inputs;
            inputs = new TOUCHINPUT[inputCount];

            if (!GetTouchInputInfo(m.LParam, inputCount, inputs, touchInputSize))
            {
                return(false);
            }

            bool handled = false;

            for (int i = 0; i < inputCount; i++)
            {
                TOUCHINPUT ti = inputs[i];
                EventHandler <WMTouchEventArgs> handler = null;
                if ((ti.dwFlags & TOUCHEVENTF_DOWN) != 0)
                {
                    handler = Touchdown;
                }
                else if ((ti.dwFlags & TOUCHEVENTF_UP) != 0)
                {
                    handler = Touchup;
                }
                else if ((ti.dwFlags & TOUCHEVENTF_MOVE) != 0)
                {
                    handler = TouchMove;
                }
                if (handler != null)
                {
                    WMTouchEventArgs te = new WMTouchEventArgs();

                    te.ContactY = ti.cyContact / 100;
                    te.ContactX = ti.cxContact / 100;
                    te.Id       = ti.dwID;
                    {
                        Point pt = PointToClient(new Point(ti.x / 100, ti.y / 100));
                        te.LocationX = pt.X;
                        te.LocationY = pt.Y;
                    }
                    te.Time  = ti.dwTime;
                    te.Mask  = ti.dwMask;
                    te.Flags = ti.dwFlags;
                    handler(this, te);
                    handled = true;
                }
            }

            CloseTouchInputHandle(m.LParam);

            return(handled);
        }
        // Touch up event handler.
        // Finishes the stroke and moves it to the collection of finished strokes.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchUpHandler(object sender, WMTouchEventArgs e)
        {
            // Find the stroke in the collection of the strokes in drawing
            // and remove it from this collection.
            Stroke stroke = ActiveStrokes.Remove(e.Id);

            Debug.Assert(stroke != null);

            // Add this stroke to the collection of finished strokes.
            FinishedStrokes.Add(stroke);

            // Request full redraw.
            Invalidate();
        }
        // Touch down event handler.
        // Starts a new stroke and assigns a color to it. 
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchDownHandler(object sender, WMTouchEventArgs e)
        {
            // We have just started a new stroke, which must have an ID value unique
            // among all the strokes currently being drawn. Check if there is a stroke
            // with the same ID in the collection of the strokes in drawing.
            Debug.Assert(ActiveStrokes.Get(e.Id) == null);

            // Create new stroke, add point and assign a color to it.
            Stroke newStroke = new Stroke ();
            newStroke.Color = touchColor.GetColor(e.IsPrimaryContact);
            newStroke.Id = e.Id;

            // Add new stroke to the collection of strokes in drawing.
            ActiveStrokes.Add(newStroke);
        }
        // Touch move event handler.
        // Adds a point to the active stroke and draws new stroke segment.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchMoveHandler(object sender, WMTouchEventArgs e)
        {
            // Find the stroke in the collection of the strokes in drawing.
            Stroke stroke = ActiveStrokes.Get(e.Id);

            Debug.Assert(stroke != null);

            // Add contact point to the stroke
            stroke.Add(new Point(e.LocationX, e.LocationY));

            // Partial redraw: only the last line segment
            Graphics g = this.CreateGraphics();

            stroke.DrawLast(g);
        }
        static T ConstructTouchNotification <T>(ConstructorInfo constructor, WMTouchEventArgs eventArgs, Control relativeTo) where T : TouchNotification
        {
            switch (TouchAge)
            {
            case TouchNotificationAge.Newer:
                return((T)constructor.Invoke(new object[] { eventArgs.Location(), relativeTo.ClientSize, eventArgs.Id, eventArgs.IsPrimaryContact, eventArgs.ContactArea(), eventArgs.TouchDeviceID }));

            case TouchNotificationAge.Intermediate:
                return((T)constructor.Invoke(new object[] { eventArgs.Location(), relativeTo.ClientSize, eventArgs.Id, eventArgs.IsPrimaryContact, eventArgs.ContactArea() }));

            case TouchNotificationAge.Older:
                return((T)constructor.Invoke(new object[] { eventArgs.Location(), relativeTo.ClientSize, eventArgs.Id, eventArgs.ContactArea() }));
            }

            return(null);
        }
        // Touch down event handler.
        // Starts a new stroke and assigns a color to it.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchDownHandler(object sender, WMTouchEventArgs e)
        {
            // We have just started a new stroke, which must have an ID value unique
            // among all the strokes currently being drawn. Check if there is a stroke
            // with the same ID in the collection of the strokes in drawing.
            Debug.Assert(ActiveStrokes.Get(e.Id) == null);

            // Create new stroke, add point and assign a color to it.
            Stroke newStroke = new Stroke();

            newStroke.Color = touchColor.GetColor(e.IsPrimaryContact);
            newStroke.Id    = e.Id;

            // Add new stroke to the collection of strokes in drawing.
            ActiveStrokes.Add(newStroke);
        }
Пример #14
0
        // Touch move event handler.
        // Adds a point to the active stroke and draws new stroke segment.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchMoveHandler(object sender, WMTouchEventArgs e)
        {
            // Find the stroke in the collection of the strokes in drawing.
            Stroke stroke = ActiveStrokes.Get(e.Id);

            Debug.Assert(stroke != null);

            // Add contact point to the stroke
            stroke.Add(new Point(e.LocationX, e.LocationY));

#if (DEBUG_XY)
            label5.Text = "TOUCH MOVING";
            richTextBox1.AppendText("x: " + e.LocationX.ToString() + " ");
            richTextBox1.AppendText("y: " + e.LocationY.ToString() + "\n");
#endif
            // Partial redraw: only the last line segment
            Graphics g = this.CreateGraphics();
            stroke.DrawLast(g);
        }
Пример #15
0
        // Touch up event handler.
        // Finishes the stroke and moves it to the collection of finished strokes.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchUpHandler(object sender, WMTouchEventArgs e)
        {
            // Find the stroke in the collection of the strokes in drawing
            // and remove it from this collection.
            Stroke stroke = ActiveStrokes.Remove(e.Id);

            Debug.Assert(stroke != null);

            // Add this stroke to the collection of finished strokes.
            FinishedStrokes.Add(stroke);
//#if (DEBUG_XY)
            label5.Text = "TOUCH UP";
            richTextBox1.AppendText("x: " + e.LocationX.ToString() + " ");
            richTextBox1.AppendText("y: " + e.LocationY.ToString() + "\n");
//#endif
            BoundaryCheck(0, e);

            // Request full redraw.
            Invalidate();
        }
Пример #16
0
        // Touch down event handler.
        // Starts a new stroke and assigns a color to it.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchDownHandler(object sender, WMTouchEventArgs e)
        {
            // We have just started a new stroke, which must have an ID value unique
            // among all the strokes currently being drawn. Check if there is a stroke
            // with the same ID in the collection of the strokes in drawing.
            Debug.Assert(ActiveStrokes.Get(e.Id) == null);

            // Create new stroke, add point and assign a color to it.
            Stroke newStroke = new Stroke();

            newStroke.Color = touchColor.GetColor(e.IsPrimaryContact);
            newStroke.Id    = e.Id;

            // Add new stroke to the collection of strokes in drawing.
            ActiveStrokes.Add(newStroke);

//#if (DEBUG_XY)
            label5.Text = "TOUCH DOWN";
            richTextBox1.AppendText("x: " + e.LocationX.ToString() + " ");
            richTextBox1.AppendText("y: " + e.LocationY.ToString() + "\n");
//#endif
            BoundaryCheck(1, e);
        }
Пример #17
0
        // Touch move event handler.
        // Adds a point to the active stroke and draws new stroke segment.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchMoveHandler(object sender, WMTouchEventArgs e)
        {
            // Find the stroke in the collection of the strokes in drawing.
            Stroke stroke = ActiveStrokes.Get(e.Id);
            Debug.Assert(stroke != null);

            // Add contact point to the stroke
            stroke.Add(new Point(e.LocationX, e.LocationY));

            #if (DEBUG_XY)
            label5.Text = "TOUCH MOVING";
            richTextBox1.AppendText("x: " + e.LocationX.ToString() + " ");
            richTextBox1.AppendText("y: " + e.LocationY.ToString() + "\n");
            #endif
            // Partial redraw: only the last line segment
            Graphics g = this.CreateGraphics();
            stroke.DrawLast(g);
        }
Пример #18
0
        private void BoundaryCheck(int down, WMTouchEventArgs e)
        {
            if (down == 1)
            {
                x0 = e.LocationX;
                y0 = e.LocationY;
            }

            else
            {
                x1 = e.LocationX;
                y1 = e.LocationY;

                if ((x1 - x0) >= boundary_x && (y0 <= boundary_min && y1 <= boundary_min))
                {
                    label5.Text = "Drawing Path 1 to 2 Passed";
                    richTextBox1.AppendText("Path 1 to 2 Passed\n");
                    passflag++;
                }

                else if ((x1 - x0) >= boundary_x && (y1 - y0) >= boundary_y)
                {
                    label5.Text = "Drawing Path 1 to 3 Passed";
                    richTextBox1.AppendText("Path 1 to 3 Passed\n");
                    passflag++;
                }

                else if ((y1 - y0) >= boundary_y && (x0 <= boundary_min && x1 <= boundary_min))
                {
                    label5.Text = "Drawing Path 1 to 4 Passed";
                    richTextBox1.AppendText("Path 1 to 4 Passed\n");
                    passflag++;
                }

                else if ((x1 - x0) >= boundary_x && (y0 >= boundary_y && y1 >= boundary_y))
                {
                    label5.Text = "Drawing Path 4 to 3 Passed";
                    richTextBox1.AppendText("Path 4 to 3 Passed\n");
                    passflag++;
                }

                else if ((x1 - x0) >= boundary_x && (y1 - y0) <= -boundary_y)
                {
                    label5.Text = "Drawing Path 4 to 2 Passed";
                    richTextBox1.AppendText("Path 4 to 2 Passed\n");
                    passflag++;
                }

                else if ((y1 - y0) >= boundary_y && (x0 >= boundary_x && x1 >= boundary_x))
                {
                    label5.Text = "Drawing Path 2 to 3 Passed";
                    richTextBox1.AppendText("Path 2 to 3 Passed\n");
                    passflag++;
                }

                else
                {
                    FinishedStrokes.Clear();
                    //passflag = 0;
                }
            }

            /// All test cases are passed.
            /// Exit itself
            if (passflag == 6)
            {
                Environment.Exit(0);
            }
        }
Пример #19
0
        private bool DecodeTouch(ref Message m)
        {
            // More than one touchinput may be associated with a touch message,
            int inputCount = (m.WParam.ToInt32() & 0xffff); // Number of touch inputs, actual per-contact messages

            TOUCHINPUT[] inputs = new TOUCHINPUT[inputCount];

            if (!TouchConstants.GetTouchInputInfo(m.LParam, inputCount, inputs, Marshal.SizeOf(new TOUCHINPUT())))
            {
                return(false);
            }

            bool handled = false;

            for (int i = 0; i < inputCount; i++)
            {
                TOUCHINPUT ti = inputs[i];

                EventHandler <WMTouchEventArgs> handler = null;
                if ((ti.dwFlags & TouchConstants.TOUCHEVENTF_DOWN) != 0)
                {
                    handler = Touchdown;
                }
                else if ((ti.dwFlags & TouchConstants.TOUCHEVENTF_UP) != 0)
                {
                    handler = Touchup;
                }
                else if ((ti.dwFlags & TouchConstants.TOUCHEVENTF_MOVE) != 0)
                {
                    handler = TouchMove;
                }

                // Convert message parameters into touch event arguments and handle the event.
                if (handler != null)
                {
                    WMTouchEventArgs te = new WMTouchEventArgs();

                    // TOUCHINFO point coordinates and contact size is in 1/100 of a pixel; convert it to pixels.
                    // Also convert screen to client coordinates.
                    te.ContactY = ti.cyContact / 100;
                    te.ContactX = ti.cxContact / 100;
                    te.Id       = ti.dwID;
                    {
                        Point pt = PointToClient(new Point(ti.x / 100, ti.y / 100));
                        te.LocationX = pt.X;
                        te.LocationY = pt.Y;
                    }
                    te.Time  = ti.dwTime;
                    te.Mask  = ti.dwMask;
                    te.Flags = ti.dwFlags;

                    handler(this, te);

                    // Mark this event as handled.
                    handled = true;
                }
            }
            TouchConstants.CloseTouchInputHandle(m.LParam);

            return(handled);
        }
 public static Point Location(this WMTouchEventArgs args)
 {
     return(new Point(args.LocationX, args.LocationY));
 }
        // Touch move event handler.
        // Adds a point to the active stroke and draws new stroke segment.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchMoveHandler(object sender, WMTouchEventArgs e)
        {
            // Find the stroke in the collection of the strokes in drawing.
            Stroke stroke = ActiveStrokes.Get(e.Id);
            Debug.Assert(stroke != null);

            // Add contact point to the stroke
            stroke.Add(new Point(e.LocationX, e.LocationY));

            // Partial redraw: only the last line segment
            Graphics g = this.CreateGraphics();
            stroke.DrawLast(g);
        }
 public static Size ContactArea(this WMTouchEventArgs args)
 {
     return(new Size(args.ContactX, args.ContactY));
 }
Пример #23
0
        // Decodes and handles WM_TOUCH* messages.
        // Unpacks message arguments and invokes appropriate touch events.
        // in:
        //      m           window message
        // returns:
        //      flag whether the message has been handled
        public bool DecodeTouch(ref Message m)
        {
            // More than one touchinput may be associated with a touch message,
            // so an array is needed to get all event information.
            int inputCount = LoWord(m.WParam.ToInt32()); // Number of touch inputs, actual per-contact messages

            TOUCHINPUT[] inputs; // Array of TOUCHINPUT structures
            try
            {
                inputs = new TOUCHINPUT[inputCount]; // Allocate the storage for the parameters of the per-contact messages
            }
            catch (Exception exception)
            {
                Debug.Print("ERROR: Could not allocate inputs array");
                Debug.Print(exception.ToString());
                return false;
            }

            Debug.Print("Inputs: " + inputs.Length.ToString());

            // Unpack message parameters into the array of TOUCHINPUT structures, each
            // representing a message for one single contact.
            //Exercise2-Task1-Step3
            if (!GetTouchInputInfo(m.LParam, inputCount, inputs, touchInputSize))
            {
                // Get touch info failed.
                return false;
            }

            // For each contact, dispatch the message to the appropriate message
            // handler.
            // Note that for WM_TOUCHDOWN you can get down & move notifications
            // and for WM_TOUCHUP you can get up & move notifications
            // WM_TOUCHMOVE will only contain move notifications
            // and up & down notifications will never come in the same message
            bool handled = false; // // Flag, is message handled
            //Exercise2-Task1-Step4
            for (int i = 0; i < inputCount; i++)
            {
                TOUCHINPUT ti = inputs[i];

                // Assign a handler to this message.
                EventHandler<WMTouchEventArgs> handler = null;     // Touch event handler
                if ((ti.dwFlags & TOUCHEVENTF_DOWN) != 0)
                {
                    handler = Touchdown;
                }
                else if ((ti.dwFlags & TOUCHEVENTF_UP) != 0)
                {
                    handler = Touchup;
                }
                else if ((ti.dwFlags & TOUCHEVENTF_MOVE) != 0)
                {
                    handler = TouchMove;
                }

                Debug.Print("Inputs: " + inputs.Length.ToString() + "\r\nCoordinates: " + ti.x.ToString() + "," + ti.y.ToString());

                // Convert message parameters into touch event arguments and handle the event.
                if (handler != null)
                {
                    // Convert the raw touchinput message into a touchevent.
                    WMTouchEventArgs te; // Touch event arguments

                    try
                    {
                        te = new WMTouchEventArgs();
                    }
                    catch (Exception excep)
                    {
                        Debug.Print("Could not allocate WMTouchEventArgs");
                        Debug.Print(excep.ToString());
                        continue;
                    }

                    // TOUCHINFO point coordinates and contact size is in 1/100 of a pixel; convert it to pixels.
                    // Also convert screen to client coordinates.
                    te.ContactY = ti.cyContact / 100;
                    te.ContactX = ti.cxContact / 100;
                    te.Id = ti.dwID;
                    {
                        Point pt = PointToClient(new Point(ti.x / 100, ti.y / 100));
                        te.LocationX = pt.X;
                        te.LocationY = pt.Y;
                    }
                    te.Time = ti.dwTime;
                    te.Mask = ti.dwMask;
                    te.Flags = ti.dwFlags;

                    // Invoke the event handler.
                    handler(this, te);

                    // Mark this event as handled.
                    handled = true;
                }
            }

            CloseTouchInputHandle(m.LParam);

            return handled;
        }
        // Touch up event handler.
        // Finishes the stroke and moves it to the collection of finished strokes.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchUpHandler(object sender, WMTouchEventArgs e)
        {
            // Find the stroke in the collection of the strokes in drawing
            // and remove it from this collection.
            Stroke stroke = ActiveStrokes.Remove(e.Id);
            Debug.Assert(stroke != null);

            // Add this stroke to the collection of finished strokes.
            FinishedStrokes.Add(stroke);

            // Request full redraw.
            Invalidate();
        }
        // Decodes and handles WM_TOUCH message.
        // Unpacks message arguments and invokes appropriate touch events.
        // in:
        //      m           window message
        // returns:
        //      whether the message has been handled
        private bool DecodeTouch(ref Message m)
        {
            // More than one touchinput may be associated with a touch message,
            // so an array is needed to get all event information.
            int inputCount = LoWord(m.WParam.ToInt32()); // Number of touch inputs, actual per-contact messages

            TOUCHINPUT[] inputs; // Array of TOUCHINPUT structures
            inputs = new TOUCHINPUT[inputCount]; // Allocate the storage for the parameters of the per-contact messages

            // Unpack message parameters into the array of TOUCHINPUT structures, each
            // representing a message for one single contact.
            if (!GetTouchInputInfo(m.LParam, inputCount, inputs, touchInputSize))
            {
                // Get touch info failed.
                return false;
            }

            // For each contact, dispatch the message to the appropriate message
            // handler.
            bool handled = false; // Boolean, is message handled
            for (int i = 0; i < inputCount; i++)
            {
                TOUCHINPUT ti = inputs[i];

                // Assign a handler to this message.
                EventHandler<WMTouchEventArgs> handler = null;     // Touch event handler
                if ((ti.dwFlags & TOUCHEVENTF_DOWN) != 0)
                {
                    handler = Touchdown;
                }
                else if ((ti.dwFlags & TOUCHEVENTF_UP) != 0)
                {
                    handler = Touchup;
                }
                else if ((ti.dwFlags & TOUCHEVENTF_MOVE) != 0)
                {
                    handler = TouchMove;
                }

                // Convert message parameters into touch event arguments and handle the event.
                if (handler != null)
                {
                    // Convert the raw touchinput message into a touchevent.
                    WMTouchEventArgs te = new WMTouchEventArgs(); // Touch event arguments

                    // TOUCHINFO point coordinates and contact size is in 1/100 of a pixel; convert it to pixels.
                    // Also convert screen to client coordinates.
                    te.ContactY = ti.cyContact/100;
                    te.ContactX = ti.cxContact/100;
                    te.Id = ti.dwID;
                    {
                        Point pt = PointToClient(new Point(ti.x/100, ti.y/100));
                        te.LocationX = pt.X;
                        te.LocationY = pt.Y;
                    }
                    te.Time = ti.dwTime;
                    te.Mask = ti.dwMask;
                    te.Flags = ti.dwFlags;

                    // Invoke the event handler.
                    handler(this, te);

                    // Mark this event as handled.
                    handled = true;
                }
            }

            CloseTouchInputHandle(m.LParam);

            return handled;
        }
Пример #26
0
        private void BoundaryCheck(int down, WMTouchEventArgs e)
        {
            if (down == 1)
            {
                x0 = e.LocationX;
                y0 = e.LocationY;
            }

            else
            {
                x1 = e.LocationX;
                y1 = e.LocationY;

                if ((x1 - x0) >= boundary_x && (y0 <= boundary_min && y1 <= boundary_min))
                {
                    label5.Text = "Drawing Path 1 to 2 Passed";
                    richTextBox1.AppendText("Path 1 to 2 Passed\n");
                    passflag++;
                }

                else if ((x1 - x0) >= boundary_x && (y1 - y0) >= boundary_y)
                {
                    label5.Text = "Drawing Path 1 to 3 Passed";
                    richTextBox1.AppendText("Path 1 to 3 Passed\n");
                    passflag++;
                }

                else if ((y1 - y0) >= boundary_y && (x0 <= boundary_min && x1 <= boundary_min))
                {
                    label5.Text = "Drawing Path 1 to 4 Passed";
                    richTextBox1.AppendText("Path 1 to 4 Passed\n");
                    passflag++;
                }

                else if ((x1 - x0) >= boundary_x && (y0 >= boundary_y && y1 >= boundary_y))
                {
                    label5.Text = "Drawing Path 4 to 3 Passed";
                    richTextBox1.AppendText("Path 4 to 3 Passed\n");
                    passflag++;
                }

                else if ((x1 - x0) >= boundary_x && (y1 - y0) <= -boundary_y)
                {
                    label5.Text = "Drawing Path 4 to 2 Passed";
                    richTextBox1.AppendText("Path 4 to 2 Passed\n");
                    passflag++;
                }

                else if ((y1 - y0) >= boundary_y && (x0 >= boundary_x && x1 >= boundary_x))
                {
                    label5.Text = "Drawing Path 2 to 3 Passed";
                    richTextBox1.AppendText("Path 2 to 3 Passed\n");
                    passflag++;
                }

                else
                {
                    FinishedStrokes.Clear();
                    //passflag = 0;

                }
            }

            /// All test cases are passed.
            /// Exit itself
            if (passflag == 6)
            {
               Environment.Exit(0);
            }
        }
Пример #27
0
        // Touch down event handler.
        // Starts a new stroke and assigns a color to it.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchDownHandler(object sender, WMTouchEventArgs e)
        {
            // We have just started a new stroke, which must have an ID value unique
            // among all the strokes currently being drawn. Check if there is a stroke
            // with the same ID in the collection of the strokes in drawing.
            Debug.Assert(ActiveStrokes.Get(e.Id) == null);

            // Create new stroke, add point and assign a color to it.
            Stroke newStroke = new Stroke ();
            newStroke.Color = touchColor.GetColor(e.IsPrimaryContact);
            newStroke.Id = e.Id;

            // Add new stroke to the collection of strokes in drawing.
            ActiveStrokes.Add(newStroke);

            //#if (DEBUG_XY)
            label5.Text = "TOUCH DOWN";
            richTextBox1.AppendText("x: " + e.LocationX.ToString() + " ");
            richTextBox1.AppendText("y: " + e.LocationY.ToString() + "\n");
            //#endif
            BoundaryCheck(1, e);
        }
        // Decodes and handles WM_TOUCH message.
        // Unpacks message arguments and invokes appropriate touch events.
        // in:
        //      m           window message
        // returns:
        //      whether the message has been handled
        private bool DecodeTouch(ref Message m)
        {
            // More than one touchinput may be associated with a touch message,
            // so an array is needed to get all event information.
            int inputCount = LoWord(m.WParam.ToInt32()); // Number of touch inputs, actual per-contact messages

            TOUCHINPUT[] inputs;                         // Array of TOUCHINPUT structures
            inputs = new TOUCHINPUT[inputCount];         // Allocate the storage for the parameters of the per-contact messages

            // Unpack message parameters into the array of TOUCHINPUT structures, each
            // representing a message for one single contact.
            if (!GetTouchInputInfo(m.LParam, inputCount, inputs, touchInputSize))
            {
                // Get touch info failed.
                return(false);
            }

            // For each contact, dispatch the message to the appropriate message
            // handler.
            bool handled = false; // Boolean, is message handled

            for (int i = 0; i < inputCount; i++)
            {
                TOUCHINPUT ti = inputs[i];

                // Assign a handler to this message.
                EventHandler <WMTouchEventArgs> handler = null;     // Touch event handler
                if ((ti.dwFlags & TOUCHEVENTF_DOWN) != 0)
                {
                    handler = Touchdown;
                }
                else if ((ti.dwFlags & TOUCHEVENTF_UP) != 0)
                {
                    handler = Touchup;
                }
                else if ((ti.dwFlags & TOUCHEVENTF_MOVE) != 0)
                {
                    handler = TouchMove;
                }

                // Convert message parameters into touch event arguments and handle the event.
                if (handler != null)
                {
                    // Convert the raw touchinput message into a touchevent.
                    WMTouchEventArgs te = new WMTouchEventArgs(); // Touch event arguments

                    // TOUCHINFO point coordinates and contact size is in 1/100 of a pixel; convert it to pixels.
                    // Also convert screen to client coordinates.
                    te.ContactY = ti.cyContact / 100;
                    te.ContactX = ti.cxContact / 100;
                    te.Id       = ti.dwID;
                    {
                        Point pt = PointToClient(new Point(ti.x / 100, ti.y / 100));
                        te.LocationX = pt.X;
                        te.LocationY = pt.Y;
                    }
                    te.Time  = ti.dwTime;
                    te.Mask  = ti.dwMask;
                    te.Flags = ti.dwFlags;

                    // Invoke the event handler.
                    handler(this, te);

                    // Mark this event as handled.
                    handled = true;
                }
            }

            CloseTouchInputHandle(m.LParam);

            return(handled);
        }
Пример #29
0
        // Touch up event handler.
        // Finishes the stroke and moves it to the collection of finished strokes.
        // in:
        //      sender      object that has sent the event
        //      e           touch event arguments
        private void OnTouchUpHandler(object sender, WMTouchEventArgs e)
        {
            // Find the stroke in the collection of the strokes in drawing
            // and remove it from this collection.
            Stroke stroke = ActiveStrokes.Remove(e.Id);
            Debug.Assert(stroke != null);

            // Add this stroke to the collection of finished strokes.
            FinishedStrokes.Add(stroke);
            //#if (DEBUG_XY)
            label5.Text = "TOUCH UP";
            richTextBox1.AppendText("x: " + e.LocationX.ToString() + " ");
            richTextBox1.AppendText("y: " + e.LocationY.ToString() + "\n");
            //#endif
            BoundaryCheck(0, e);

            // Request full redraw.
            Invalidate();
        }