示例#1
0
        private void PathTrackerOnPathEnd(PathEventArgs args)
        {
            if (IsInCaptureMode)
            {
                OnGestureCaptured(_gesture);
                return;
            }

            if (_effectiveIntent == null)
            {
                if (IntentOrPathCanceled != null)
                {
                    IntentOrPathCanceled();
                }
                return;
            }

            //如果是一个允许修饰符执行的手势,显然,它必然已经被执行过了(在被识别为滚轮手势随后)
            //所以不执行而直接结束
            if (_effectiveIntent.CanExecuteOnModifier())
            {
                var modifierStateAwareCmd = _effectiveIntent.Command as IGestureModifiersAware;
                if (modifierStateAwareCmd != null)
                {
                    modifierStateAwareCmd.GestureEnded();
                    modifierStateAwareCmd.ReportStatus -= OnCommandReportStatus;
                }

                //发布事件
                OnIntentReadyToExecute(_effectiveIntent);
                if (IntentExecuted != null)
                {
                    IntentExecuted(_effectiveIntent, null);
                }
                return;
            }


            OnIntentReadyToExecute(_effectiveIntent);
            var result = _effectiveIntent.Execute(args.Context, this);

            //发布事件
            if (IntentExecuted != null)
            {
                IntentExecuted(_effectiveIntent, result);
            }
        }
示例#2
0
        private void PathTrackerOnPathModifier(PathEventArgs args)
        {
            Debug.WriteLineIf(_gesture.Modifier != args.Modifier,"Gesture:" + _gesture);

            _gesture.Modifier = args.Modifier;

            if (IsInCaptureMode)
            {
                return;
            }

            //如果当前被“捕获”了,则把修饰符事件发送给命令。
            if (_effectiveIntent != null)
            {
                var modifierStateAwareCommand = _effectiveIntent.Command as IGestureModifiersAware;
                if (PathTracker.IsSuspended && modifierStateAwareCommand != null)
                {
                    modifierStateAwareCommand.ModifierTriggered(args.Modifier);
                    return;
                }

            }

            var lastEffectiveIntent = _effectiveIntent;
            _effectiveIntent = IntentFinder.Find(_gesture, args.Context);

            if (_effectiveIntent != null)
            {
                if (IntentRecognized != null && _effectiveIntent != lastEffectiveIntent) IntentRecognized(_effectiveIntent);

                //如果设置了允许滚动时执行 且 确实可以执行(手势包含滚轮),则执行
                //这样执行之后,在释放手势的时候应该 不再执行!
                if (_effectiveIntent.CanExecuteOnModifier())
                {
                    OnIntentReadyToExecuteOnModifier(args.Modifier);

                    var modifierStateAwareCommand = _effectiveIntent.Command as IGestureModifiersAware;

                    //todo: 这个逻辑似乎应该放在GestureIntent中
                    if (modifierStateAwareCommand != null)
                    {
                        modifierStateAwareCommand.ReportStatus += OnCommandReportStatus;
                        GestureModifier observedModifiers;
                        modifierStateAwareCommand.GestureRecognized(out observedModifiers);

                        //要观察的modifier事件与PathTracker需要排除的恰好相反
                        PathTracker.SuspendTemprarily(filteredModifiers: GestureModifier.All &~ observedModifiers);
                    }
                    else
                    {
                        //对于非组合手势,同样unhook除了触发修饰符之外的所有修饰符,这样可以仍然反复执行,实现类似“多出粘贴”的功能!
                        PathTracker.SuspendTemprarily(filteredModifiers: GestureModifier.None);//GestureModifier.All &~ args.Modifier);

                        //todo:在这里发布一个事件应该是合理的
                        _effectiveIntent.Execute(args.Context, this);
                    }

                }
            }
            else if (lastEffectiveIntent != null)
            {
                if (IntentInvalid != null) IntentInvalid();
            }
        }
示例#3
0
        private void PathTrackerOnPathModifier(PathEventArgs args)
        {
            Debug.WriteLineIf(_gesture.Modifier != args.Modifier, "Gesture:" + _gesture);

            _gesture.Modifier = args.Modifier;

            if (IsInCaptureMode)
            {
                return;
            }

            //如果当前被“捕获”了,则把修饰符事件发送给命令。
            if (_effectiveIntent != null)
            {
                var modifierStateAwareCommand = _effectiveIntent.Command as IGestureModifiersAware;
                if (PathTracker.IsSuspended && modifierStateAwareCommand != null)
                {
                    modifierStateAwareCommand.ModifierTriggered(args.Modifier);
                    return;
                }
            }

            var lastEffectiveIntent = _effectiveIntent;

            _effectiveIntent = IntentFinder.Find(_gesture, args.Context);

            if (_effectiveIntent != null)
            {
                if (IntentRecognized != null && _effectiveIntent != lastEffectiveIntent)
                {
                    IntentRecognized(_effectiveIntent);
                }

                //如果设置了允许滚动时执行 且 确实可以执行(手势包含滚轮),则执行
                //这样执行之后,在释放手势的时候应该 不再执行!
                if (_effectiveIntent.CanExecuteOnModifier())
                {
                    OnIntentReadyToExecuteOnModifier(args.Modifier);


                    var modifierStateAwareCommand = _effectiveIntent.Command as IGestureModifiersAware;

                    //todo: 这个逻辑似乎应该放在GestureIntent中
                    if (modifierStateAwareCommand != null)
                    {
                        modifierStateAwareCommand.ReportStatus += OnCommandReportStatus;
                        GestureModifier observedModifiers;
                        modifierStateAwareCommand.GestureRecognized(out observedModifiers);

                        //要观察的modifier事件与PathTracker需要排除的恰好相反
                        PathTracker.SuspendTemprarily(filteredModifiers: GestureModifier.All & ~observedModifiers);
                    }
                    else
                    {
                        //对于非组合手势,同样unhook除了触发修饰符之外的所有修饰符,这样可以仍然反复执行,实现类似“多出粘贴”的功能!
                        PathTracker.SuspendTemprarily(filteredModifiers: GestureModifier.None);//GestureModifier.All &~ args.Modifier);

                        //todo:在这里发布一个事件应该是合理的
                        _effectiveIntent.Execute(args.Context, this);
                    }
                }
            }
            else if (lastEffectiveIntent != null)
            {
                if (IntentInvalid != null)
                {
                    IntentInvalid();
                }
            }
        }