示例#1
0
        internal override void Synchronize()
        {
            // Simulate a stylus move (if we are current stylus, inrange, visuals still valid to update
            // and has moved).
            if (InRange && _inputSource != null && _inputSource.Value != null &&
                _inputSource.Value.CompositionTarget != null && !_inputSource.Value.CompositionTarget.IsDisposed)
            {
                Point rawScreenPoint = new Point(_pointerData.Info.ptPixelLocationRaw.X, _pointerData.Info.ptPixelLocationRaw.Y);
                Point ptDevice       = PointUtil.ScreenToClient(rawScreenPoint, _inputSource.Value);

                // GlobalHitTest always returns an IInputElement, so we are sure to have one.
                IInputElement stylusOver     = Input.StylusDevice.GlobalHitTest(_inputSource.Value, ptDevice);
                bool          fOffsetChanged = false;

                if (_stylusOver == stylusOver)
                {
                    Point ptOffset = GetPosition(stylusOver);
                    fOffsetChanged = MS.Internal.DoubleUtil.AreClose(ptOffset.X, _rawElementRelativePosition.X) == false || MS.Internal.DoubleUtil.AreClose(ptOffset.Y, _rawElementRelativePosition.Y) == false;
                }

                if (fOffsetChanged || _stylusOver != stylusOver)
                {
                    int timeStamp = Environment.TickCount;

                    if (_currentStylusPoints != null &&
                        _currentStylusPoints.Count > 0 &&
                        StylusPointDescription.AreCompatible(PointerTabletDevice.StylusPointDescription, _currentStylusPoints.Description))
                    {
                        StylusPoint stylusPoint = _currentStylusPoints[_currentStylusPoints.Count - 1];
                        int[]       data        = stylusPoint.GetPacketData();

                        // get back to the correct coordinate system
                        Matrix m = _tabletDevice.TabletToScreen;
                        m.Invert();
                        Point ptTablet = ptDevice * m;

                        data[0] = (int)ptTablet.X;
                        data[1] = (int)ptTablet.Y;

                        RawStylusInputReport report = new RawStylusInputReport(InputMode.Foreground,
                                                                               timeStamp,
                                                                               _inputSource.Value,
                                                                               InAir ? RawStylusActions.InAirMove : RawStylusActions.Move,
                                                                               () => { return(PointerTabletDevice.StylusPointDescription); },
                                                                               TabletDevice.Id,
                                                                               Id,
                                                                               data);


                        report.Synchronized = true;

                        InputReportEventArgs inputReportEventArgs = new InputReportEventArgs(StylusDevice, report);
                        inputReportEventArgs.RoutedEvent = InputManager.PreviewInputReportEvent;

                        InputManager.Current.ProcessInput(inputReportEventArgs);
                    }
                }
            }
        }
示例#2
0
        private void HandleInteraction(object clientData, RawStylusSystemGestureInputReport originalReport)
        {
            RawStylusSystemGestureInputReport report = new RawStylusSystemGestureInputReport(
                InputMode.Foreground,
                Environment.TickCount,
                CriticalActiveSource,
                () => { return(PointerTabletDevice.StylusPointDescription); },
                TabletDevice.Id,
                Id,
                originalReport.SystemGesture,
                originalReport.GestureX,
                originalReport.GestureY,
                originalReport.ButtonState)
            {
                StylusDevice = StylusDevice,
            };

            // For a flick, update the points in the stylus device to the flick location.
            // This forces processing of the stylus over to use the initial flick location
            // instead of the last WM_POINTER message location allowing command processing to
            // be done on the flick location itself.
            if (report.SystemGesture == SystemGesture.Flick)
            {
                StylusPoint flickPoint = _currentStylusPoints[_currentStylusPoints.Count - 1];

                flickPoint.X = report.GestureX;
                flickPoint.Y = report.GestureY;

                _currentStylusPoints = new StylusPointCollection(flickPoint.Description,
                                                                 flickPoint.GetPacketData(),
                                                                 GetTabletToElementTransform(null),
                                                                 Matrix.Identity);
            }

            InputReportEventArgs irea = new InputReportEventArgs(StylusDevice, report)
            {
                RoutedEvent = InputManager.PreviewInputReportEvent,
            };

            // Now send the input report
            InputManager.UnsecureCurrent.ProcessInput(irea);
        }