private void InputDeviceEvents_PreProcessInput(object sender, PreProcessInputEventArgs e) { if (e.StagingItem.Input.Device is TouchDevice) { InputReportEventArgs irea = e.StagingItem.Input as InputReportEventArgs; if (irea != null) { RawTouchInputReport rtir = irea.Report as RawTouchInputReport; if (rtir != null) { // cancel any touch event that does not start within the modal window //if (!this.ContainsPoint(rtir.Touches[0].X, rtir.Touches[0].Y)) // e.Cancel(); int x = rtir.Touches[0].X; int y = rtir.Touches[0].Y; PointToClient(ref x, ref y); if (!Utils.IsWithinRectangle(x, y, ActualWidth, ActualWidth)) { e.Cancel(); } } } } }
private void InputDeviceEvents_PreProcessInput(object sender, PreProcessInputEventArgs e) { if (e.StagingItem.Input.Device is TouchDevice) { InputReportEventArgs irea = e.StagingItem.Input as InputReportEventArgs; if (irea != null) { RawTouchInputReport rtir = irea.Report as RawTouchInputReport; if (rtir != null) { int x = rtir.Touches[0].X; int y = rtir.Touches[0].Y; PointToClient(ref x, ref y); if (!Utils.IsWithinRectangle(x, y, ActualWidth, ActualWidth)) { e.Cancel(); } } } } }
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); }