Ejemplo n.º 1
0
        //Stopwatch sw = new Stopwatch();
        private void PathTrackerOnEffectivePathGrow(PathEventArgs args)
        {
            if (_gesture.Count() >= MaxGestureSteps)
            {
                return;
            }

            var gestureChanged = Parse(args);

            //如果手势同之前则不需要判断
            if (!gestureChanged)
            {
                return;
            }

            Debug.WriteLine("GestureChanged");

            if (IsInCaptureMode)
            {
                return;
            }

            var lastEffectiveIntent = _effectiveIntent;

            _effectiveIntent = IntentFinder.Find(_gesture, _currentApp);

            if (_effectiveIntent != null)
            {
                Debug.WriteLine("Call IntentRecognized");
                if (IntentRecognized != null)
                {
                    IntentRecognized(_effectiveIntent);
                }
            }
            else if (lastEffectiveIntent != null)
            {
                if (IntentInvalid != null)
                {
                    IntentInvalid();
                }
            }

            Debug.WriteLine("Gesture:" + _gesture);
        }
Ejemplo n.º 2
0
        //决定是否应该开始路径
        private void PathTrackerOnBeforePathStart(BeforePathStartEventArgs args)
        {
            if (IsInCaptureMode)
            {
                return;
            }

            //全屏下禁止手势的情况
            if (DisableInFullScreenMode && args.Context.IsInFullScreenMode)
            {
                Debug.WriteLine("全屏禁用");
                args.ShouldPathStart = false;
                return;
            }

            var shouldStart = IntentFinder.IsGesturingEnabledForContext(args.PathEventArgs.Context);

            args.ShouldPathStart = shouldStart;
        }
Ejemplo n.º 3
0
 protected override List <Type> ApplicationIntentTypes()
 {
     return(IntentFinder.FindIntentTypes(new[] { typeof(LaunchIntent).GetTypeInfo().Assembly }).ToList());
 }
Ejemplo n.º 4
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();
                }
            }
        }