public TouchInfo GetInfoFromContactEvent(TouchAction2 action, System.Windows.Input.TouchEventArgs e)
        {
            //Get the  point position from the ContactEventArgs (can optionally use e.Contact.getCenterPosition here for more accuracy)
            System.Windows.Point position = e.GetTouchPoint(GestureFramework.LayoutRoot).Position; // new System.Windows.Point(e.TouchPoint.CenterX, e.TouchPoint.CenterY);

            //Create a new touchinfo which will be used later to add a touchpoint
            TouchInfo info = new TouchInfo();

            //IF not Using in surface there will be not size or tag, therefore all the points are fingers.
            System.Windows.Size size = e.TouchDevice.GetTouchPoint(GestureFramework.LayoutRoot).Size;
            if (size.Height <= MinimumSize.Height && size.Width <= MinimumSize.Width)
            {
                info.IsFinger = true;
                info.Tag = null;

            }
            else
            {
                info.IsFinger = e.TouchDevice.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().IsFinger;

                if (e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Tag != null)
                {

                   // info.Tag = e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Tag;
                    /*
                    switch (e.TouchPoint.Tag.Type)
                    {
                        case Microsoft.Surface.Presentation.TagType.Byte:
                            info.Tag = e.Contact.Tag.Byte.ToString();
                            break;
                        case Microsoft.Surface.Presentation.TagType.Identity:
                            info.Tag = e.Contact.Tag.Identity.ToString();
                            break;
                        default:
                            info.Tag = null;
                            break;

                    }*/

                }
                else if (!info.IsFinger)
                {
                    //info.Bounds = new Rect((double)e.TouchPoint.CenterX, (double)e.TouchPoint.CenterY, (double)e.TouchPoint.Bounds.Width, (double)e.TouchPoint.Bounds.Height);
                    info.Bounds = e.GetTouchPoint(GestureFramework.LayoutRoot).ToTouchInfo().Bounds;
                }
            }

            //Set the action type to the passed in action
            info.ActionType = action;

            //Set the position of the touchinfo to the previously found position from e
            info.Position = position;

            //Set the deviceid of the touchinfo to the id of the contact
            info.TouchDeviceId = e.GetTouchPoint(GestureFramework.LayoutRoot).TouchDevice.Id;

            return info;
        }
        public void UpdateActiveTouchPoints(TouchAction2 action, Point position, int iPointerID)
        {
            TouchInfo info = new TouchInfo();
            info.ActionType = action;
            info.Position = position;
            info.TouchDeviceId = iPointerID;

            TouchPoint2 touchPoint = null;

            //If it is contact down, we want to add the point, otherwise we want to update that particular point
            if (action == TouchAction2.Down)
            {
                //VisualTreeHelper.HitTest(mainWindow, null, new HitTestResultCallback(HitTestCallBack), new GeometryHitTestParameters(m_egHitArea));

                //add the new touch point to the base
                touchPoint = base.AddNewTouchPoint(info, null);
                touchPoint.UpdateSource();
            }
            else
            {
                touchPoint = base.UpdateActiveTouchPoint(info);
            }

            // Update local cache
            if (_activeTouchPoints.ContainsKey(info.TouchDeviceId))
            {
                _activeTouchPoints[info.TouchDeviceId] = touchPoint;
                _activeTouchInfos[info.TouchDeviceId] = info;
            }
            else
            {
                _activeTouchPoints.Add(info.TouchDeviceId, touchPoint);
                _activeTouchInfos.Add(info.TouchDeviceId, info);
            }

            _lastTouchInfo = info;

            RaiseEvents();
        }
        public void UpdateActiveTouchPoints(TouchAction2 action, TouchContactEventArgs e)
        {
            Point position = e.TouchContact.GetPosition(GestureFramework.LayoutRoot);

            TouchInfo info = new TouchInfo();

            info.ActionType = action;

            info.Position = position;

            info.TouchDeviceId = e.TouchContact.ID;

            TouchPoint2 touchPoint = null;

            //If it is contact down, we want to add the point, otherwise we want to update that particular point
            if (action == TouchAction2.Down)
            {
                //add the new touch point to the base
                touchPoint = base.AddNewTouchPoint(info, e.OriginalSource as UIElement);
            }
            else
            {
                touchPoint = base.UpdateActiveTouchPoint(info);
            }

            // Update local cache
            if (_activeTouchPoints.ContainsKey(info.TouchDeviceId))
            {
                _activeTouchPoints[info.TouchDeviceId] = touchPoint;
                _activeTouchInfos[info.TouchDeviceId] = info;
            }
            else
            {
                _activeTouchPoints.Add(info.TouchDeviceId, touchPoint);
                _activeTouchInfos.Add(info.TouchDeviceId, info);
            }
        }
        public TouchPoint2 UpdateActiveTouchPoints(TouchAction2 action, System.Windows.Input.TouchEventArgs e)
        {
            TouchPoint2 touchPoint = null;
            TouchInfo info = GetInfoFromContactEvent(action, e);

            //If it is contact down, we want to add the point, otherwise we want to update that particular point
            if (action == TouchAction2.Down)
            {
                //add the new touch point to the base
                touchPoint = base.AddNewTouchPoint(info, e.TouchDevice.Captured as UIElement);

            }
            else
            {
                //add the new touch point to the base
                touchPoint = base.UpdateActiveTouchPoint(info, e.TouchDevice.Captured as UIElement);
            }

               /* Image<Bgr, Byte> bitImg = ImageHelper.getBetterImage(AddSnapshots(touchPoint), touchPoint);

            if (bitImg != null)
            {
                touchPoint.Snapshot = ImageHelper.ExtractContourAndHull(bitImg);
            }
            */
            // Update local cache
            if (_activeTouchPoints.ContainsKey(touchPoint.TouchDeviceId))
            {
                //_activeTouchPoints[info.TouchDeviceId] = touchPoint;
                _activeTouchInfos[info.TouchDeviceId].Update(info);
                _activeTouchPoints[info.TouchDeviceId].Update(info);
                //  _activeTouchPoints[info.TouchDeviceId].Snapshot.AddRange(touchPoint.Snapshot);
            }
            else
            {
                _activeTouchPoints.Add(info.TouchDeviceId, touchPoint);
                _activeTouchInfos.Add(info.TouchDeviceId, info);
            }

            return touchPoint;
        }
Exemplo n.º 5
0
        private TouchInfo MakeInfo(TuioCursor c, TouchAction2 action)
        {
            Tuple<double, double> screenDim = GetDimensions();
            double screen_width = screenDim.Item1;
            double screen_height = screenDim.Item2;

            double x = c.getX() * screen_width;
            double y = c.getY() * screen_height;
            TouchInfo info = new TouchInfo();
            info.ActionType = action;
            info.Position = new Point(x, y);
            info.TouchDeviceId = (int)c.getSessionID();

            return info;
        }