예제 #1
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            if (!e.StagingItem.Input.Handled)
            {
                RoutedEvent routedEvent = e.StagingItem.Input.RoutedEvent;
                if (routedEvent == InputManager.InputReportEvent)
                {
                    InputReportEventArgs input = e.StagingItem.Input as InputReportEventArgs;
                    if (input != null)
                    {
                        RawTouchInputReport report = input.Report as RawTouchInputReport;
                        if (report != null)
                        {
                            TouchEventArgs args = new TouchEventArgs(
                                this,
                                report.Timestamp,
                                report.Touches);

                            UIElement target = report.Target;
                            if (report.EventMessage == (byte)TouchMessages.Down)
                            {
                                args.RoutedEvent = TouchEvents.TouchDownEvent;
                            }
                            else if (report.EventMessage == (byte)TouchMessages.Up)
                            {
                                args.RoutedEvent = TouchEvents.TouchUpEvent;
                            }
                            else if (report.EventMessage == (byte)TouchMessages.Move)
                            {
                                args.RoutedEvent = TouchEvents.TouchMoveEvent;
                            }
                            else
                            {
                                throw new Exception("Unknown touch event.");
                            }

                            args.Source = (target == null ? _focus : target);
                            e.PushInput(args, e.StagingItem);
                        }
                    }
                }
            }
        }
예제 #2
0
        public bool OnEvent(BaseEvent ev)
        {
            InputReport ir = null;
            InputDevice dev = null;

            /// Process known events, otherwise forward as generic to MainWindow.
            ///

            TouchEvent touchEvent = ev as TouchEvent;
            if (touchEvent != null)
            {
                Microsoft.SPOT.Presentation.UIElement targetWindow = TouchCapture.Captured;

                ///
                ///  Make sure the current event's coordinates are contained in the current
                ///  stylus/touch window, if not then search for the appropriate window
                ///
                if (targetWindow != null && touchEvent.EventMessage == (byte)TouchMessages.Down)
                {
                    int x = 0, y = 0, w, h;
                    int xSrc = touchEvent.Touches[0].X;
                    int ySrc = touchEvent.Touches[0].Y;

                    targetWindow.PointToScreen(ref x, ref y);
                    targetWindow.GetRenderSize(out w, out h);

                    if (!(x <= xSrc && xSrc <= (x + w) &&
                        y <= ySrc && ySrc <= (y + h)))
                    {
                        // only look for different target window if the touch point is inside 
                        // the system metrics, otherwise, it may be a touch calibration point
                        // which is translated in the application layer.
                        if(xSrc <= SystemMetrics.ScreenWidth &&
                           ySrc <= SystemMetrics.ScreenHeight)
                        {
                            targetWindow = null;
                        }
                    }
                }

                if (targetWindow == null)
                {
                    //If we can enforce that the first event in the array is always the primary touch, we don't have to
                    //search.
                    targetWindow = WindowManager.Instance.GetPointerTarget(touchEvent.Touches[0].X, touchEvent.Touches[0].Y);
                }

                if (targetWindow != null)
                {
                    _inputManager.TouchDevice.SetTarget(targetWindow);
                }
                else
                {
                    _inputManager.TouchDevice.SetTarget(MainWindow);
                }

                ir =
                   new RawTouchInputReport(
                       null,
                       touchEvent.Time,
                       touchEvent.EventMessage,
                       touchEvent.Touches
                       );

                dev = _inputManager._touchDevice;

            }
            else if (ev is GenericEvent)
            {
                GenericEvent genericEvent = (GenericEvent)ev;

                    Microsoft.SPOT.Presentation.UIElement targetWindow = TouchCapture.Captured;

                    if (targetWindow == null)
                    {
                        targetWindow = WindowManager.Instance.GetPointerTarget(genericEvent.X, genericEvent.Y);
                    }

                    if (targetWindow != null)
                    {
                        _inputManager.GenericDevice.SetTarget(targetWindow);
                    }
                    else
                    {
                        _inputManager.GenericDevice.SetTarget(MainWindow);
                    }

                    ir = new RawGenericInputReport(
                           null,
                           genericEvent
                           );

                    dev = _inputManager._genericDevice;

            }
            else
            {
                /// Unkown event.
            }

            this.Dispatcher.BeginInvoke(_reportInputMethod, new InputReportArgs(dev, ir));

            return true;
        }