private void PathTrackerOnPathStart(PathEventArgs args) { //初始化 _effectiveIntent = null; _pointCount = 1; _gesture = new Gesture(args.Context.GestureButton); _lastPoint = args.Location; }
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); } }
//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); }
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(); } }
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); }
//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); }
//返回告知手势是否发生了变化 private bool Parse(PathEventArgs args) { var gestureChanged = false; if (_pointCount != 0 && args.Location != _lastPoint) { var vector = new Point(args.Location.X - _lastPoint.X, -args.Location.Y + _lastPoint.Y); Gesture.GestureDir dir; if (Enable8DirGesture) { var count = _gesture.Count(); switch (count) { case 0: dir = Get8DirectionDir(vector); _lastVector = vector; _firstStrokeEndPoint = args.Location; break; case 1: var last = _gesture.Last().Value; if ((int)last % 2 == 0) //如果不是斜线 { dir = Get4DirectionDir(vector); break; } dir = Get8DirectionDir(vector); if (dir != last) { if (GetAngle(new Point(_firstStrokeEndPoint.X - args.Context.StartPoint.X, _firstStrokeEndPoint.Y - args.Context.StartPoint.X), new Point(args.Location.X - _firstStrokeEndPoint.X, args.Location.Y - _firstStrokeEndPoint.Y)) < 36f) { dir = last; break; } dir = Get4DirectionDir(vector); var lastDirShouldBe = Get4DirectionDir(_lastVector); _gesture.Dirs[0] = lastDirShouldBe; gestureChanged = true; } else { //如果依然延续斜线,则记录下最后一个点 _firstStrokeEndPoint = args.Location; } break; default: dir = Get4DirectionDir(vector); break; } } else { dir = Get4DirectionDir(vector); } if (dir != _gesture.Last()) { _gesture.Add(dir); gestureChanged = true; } if (_gesture.Modifier != args.Modifier) { _gesture.Modifier = args.Modifier; gestureChanged = true; } } _lastPoint = args.Location; _pointCount++; return gestureChanged; }
public BeforePathStartEventArgs(PathEventArgs pathEventArgs) { PathEventArgs = pathEventArgs; Context = pathEventArgs.Context; ShouldPathStart = true; }
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(); } } }
//返回告知手势是否发生了变化 private bool Parse(PathEventArgs args) { var gestureChanged = false; if (_pointCount != 0 && args.Location != _lastPoint) { var vector = new Point(args.Location.X - _lastPoint.X, -args.Location.Y + _lastPoint.Y); Gesture.GestureDir dir; if (Enable8DirGesture) { var count = _gesture.Count(); switch (count) { case 0: dir = Get8DirectionDir(vector); _lastVector = vector; _firstStrokeEndPoint = args.Location; break; case 1: var last = _gesture.Last().Value; if ((int)last % 2 == 0) //如果不是斜线 { dir = Get4DirectionDir(vector); break; } dir = Get8DirectionDir(vector); if (dir != last) { if (GetAngle(new Point(_firstStrokeEndPoint.X - args.Context.StartPoint.X, _firstStrokeEndPoint.Y - args.Context.StartPoint.X), new Point(args.Location.X - _firstStrokeEndPoint.X, args.Location.Y - _firstStrokeEndPoint.Y)) < 36f) { dir = last; break; } dir = Get4DirectionDir(vector); var lastDirShouldBe = Get4DirectionDir(_lastVector); _gesture.Dirs[0] = lastDirShouldBe; gestureChanged = true; } else { //如果依然延续斜线,则记录下最后一个点 _firstStrokeEndPoint = args.Location; } break; default: dir = Get4DirectionDir(vector); break; } } else { dir = Get4DirectionDir(vector); } if (dir != _gesture.Last()) { _gesture.Add(dir); gestureChanged = true; } if (_gesture.Modifier != args.Modifier) { _gesture.Modifier = args.Modifier; gestureChanged = true; } } _lastPoint = args.Location; _pointCount++; return(gestureChanged); }
private void HandlePathTimeout(PathEventArgs args) { if (!ShowPath && !ShowCommandName) return; Debug.WriteLine("PathTimeout"); //if (ShowPath) ResetPathDirtyRect(); EndView(); }
private void HandlePathStart(PathEventArgs args) { if (!ShowPath && !ShowCommandName) return; Debug.WriteLine("WhenPathStart"); _screenBounds = Screen.ScreenBoundsFromPoint(args.Location);//Screen.FromPoint(args.Location); _prevPoint = args.Location;//ToUpLeftCoord(args.Location); _pointCount = 1; _tempMainPen = args.Button == GestureButtons.RightButton ? _mainPen : _middleBtnPen; _isCurrentRecognized = false; _recognizeStateChanged = false; BeginView(); }
private void HandlePathGrow(PathEventArgs args) { if (!ShowPath && !ShowCommandName) return; if (_pointCount > _pathMaxPointCount) return; _pointCount++; if (_pointCount == _pathMaxPointCount) { ShowLabel(Color.White, "您是有多无聊啊 :)", Color.FromArgb(128, 255, 0, 0)); DrawAndUpdate(); _labelChanged = false; _recognizeStateChanged = false; return; } if (ShowPath) { var curPos = args.Location;//ToUpLeftCoord(args.Location); //需要将点换算为基于窗口的坐标 var pA = new Point(_prevPoint.X - _screenBounds.X, _prevPoint.Y - _screenBounds.Y); var pB = new Point(curPos.X - _screenBounds.X, curPos.Y - _screenBounds.Y); if (pA != pB) { _gPath.AddLine(pA, pB); _gPathDirty.Reset(); _gPathDirty.AddLine(pA, pB); _gPathDirty.Widen(_dirtyMarkerPen); } //_pathDirtyRect = GetDirtyRect(_prevPoint, curPos); //_pathDirtyRegion.Union(_pathDirtyRect); } DrawAndUpdate(); _recognizeStateChanged = false; _prevPoint = args.Location;//ToUpLeftCoord(args.Location); }