protected void OnIntentReadyToExecute(GestureIntent intent) { if (IntentReadyToExecute != null) { IntentReadyToExecute(intent); } }
private void PathTrackerOnPathStart(PathEventArgs args) { //初始化 _effectiveIntent = null; _pointCount = 1; _gesture = new Gesture(args.Context.GestureButton); _lastPoint = args.Location; }
public OrderableIntent(GestureIntent from) { var t = from.GetType(); foreach (var fieldInf in t.GetFields()) { fieldInf.SetValue(this, fieldInf.GetValue(from)); } foreach (var propInf in t.GetProperties()) { propInf.SetValue(this, propInf.GetValue(from,null),null); } }
//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); }
//如果inApp不为null, 则为编辑模式 public EditGestureForm(GestureParser gestureParser, AbstractApp inApp, GestureIntent intent = null) { _gestureParser = gestureParser; _app = inApp; _intent = intent; InitializeComponent(); if (_intent != null) { if (inApp.Find(intent.Gesture) != intent) { throw new InvalidOperationException("intent必须是inApp中的"); } Text = "编辑手势"; lb_mnemonic.Text = _intent.Gesture.ToString(); tb_gestureName.Text = _intent.Name; } BeginCapture(); }
//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); }
public virtual void Remove(GestureIntent intent) { GestureIntents.Remove(intent); }
protected void OnIntentReadyToExecute(GestureIntent intent) { if (IntentReadyToExecute != null) IntentReadyToExecute(intent); }
private void LoadCommandView(GestureIntent intent) { var cmdView = Controller.CommandViewFactory.GetCommandView(intent.Command); if (cmdView != null) { //如果目标视图实现了该接口,则注入选中的app var view = cmdView as ITargetAppAware; if (view != null) { view.TargetApp = GetSelectedAppOrGlobal(); } cmdView.CommandValueChanged -= CommandValueChangedHandler; cmdView.CommandValueChanged += CommandValueChangedHandler; //如果就是先前那个,则不用清除再加载了 if (!panel_commandView.Controls.Contains(cmdView)) { panel_commandView.Controls.Clear(); panel_commandView.Controls.Add(cmdView); } } }
public virtual void Add(GestureIntent intent) { GestureIntents.Add(intent.Gesture.GetHashCode(), intent); }
private void AddOrReplaceGestureIntent(GestureIntent intent) { listGestureIntents.BeginUpdate(); foreach (ListViewItem item in listGestureIntents.Items) { var current = item.Tag as GestureIntent; if (current.Gesture.Equals(intent.Gesture)) { listGestureIntents.Items.Remove(item); break; } } var i = AddGestureIntent(intent); i.Selected = true; listGestureIntents.Focus(); listGestureIntents.EnsureVisible(i.Index); listGestureIntents.EndUpdate(); }
private void LoadCommand(GestureIntent intent) { //SuspendDrawingControl.SuspendDrawing(group_Command); if (!group_Command.Enabled) group_Command.Enabled = true; if (group_Command.Text != intent.Name) group_Command.Text = string.Format("手势 \"{0}\" 的参数", intent.Name); //根据intent的Gesture是否包WheelDirection来决定是显示“滚动滚轮时立即执行”选框 //check_executeOnMouseWheeling.Text = "识别手势时立即执行"; check_executeOnMouseWheeling.Visible = (intent.Gesture.Modifier != GestureModifier.None); if (check_executeOnMouseWheeling.Visible) //设定其值 { check_executeOnMouseWheeling.Checked = intent.ExecuteOnModifier; } //修改下拉框 bool itemMatched = false; foreach (CommandTypesComboBoxItem item in combo_CommandTypes.Items) { if (item.CommandType == intent.Command.GetType()) { //如果与前一个command相同,则不会引发changed事件,需要手动修改。 if (combo_CommandTypes.SelectedItem == item) { LoadCommandView(intent); } combo_CommandTypes.SelectedItem = item; itemMatched = true; break; } } if (!itemMatched) combo_CommandTypes.SelectedIndex = -1; //SuspendDrawingControl.ResumeDrawing(group_Command); }
private void HandleCommandReportStatus(string status, GestureIntent intent) { if (ShowCommandName) { var modifierText = intent.Gesture.Modifier.ToMnemonic(); var newLabelText = (modifierText == String.Empty ? String.Empty : (modifierText + " ")) + intent.Name + status; if (newLabelText.Equals(_labelText)) return; _labelText = newLabelText; ShowLabel(Color.White, newLabelText, Color.FromArgb(70, 0, 0, 0)); DrawAndUpdate(); if (ShowCommandName) _labelChanged = false; } }
private ListViewItem AddGestureIntent(GestureIntent intent) { var item = new ListViewItem(intent.Name) { Tag = intent }; var mnemonic = intent.Gesture.ToString(); item.SubItems.Add(mnemonic); item.SubItems.Add(intent.Command.Description()); listGestureIntents.Items.Add(item); return item; }
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 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 HandleIntentReadyToExecute(GestureIntent intent) { if (!ShowPath && !ShowCommandName) return; Debug.WriteLine("WhenIntentReadyToExecute"); //update //if (ShowPath) ResetPathDirtyRect(); if (ShowCommandName)// && !_gestureParser.PathTracker.IsSuspended { //var modifierText = intent.Gesture.Modifier.ToMnemonic(); //var newLabelText = (modifierText == String.Empty ? String.Empty : (modifierText + " ")) + intent.Name; //if (!newLabelText.Equals(_labelText)) //{ ShowLabel(Color.White, _labelText, Color.FromArgb(120, 0, 0, 0)); //} } //draw DrawAndUpdate(); //clear if (ShowPath) _pathVisible = false; if (ShowCommandName) _labelChanged = false; if (ViewFadeOut) FadeOut(); else EndView(); }
private void HandleIntentRecognized(GestureIntent intent) { if (!ShowPath && !ShowCommandName) return; Debug.WriteLine("IntentRecognized"); if (ShowCommandName) { var modifierText = intent.Gesture.Modifier.ToMnemonic(); var newLabelText = (modifierText == String.Empty ? String.Empty : (modifierText + " ")) + intent.Name; ShowLabel(Color.White, newLabelText, Color.FromArgb(70, 0, 0, 0)); } if (!_isCurrentRecognized && ShowPath) { _isCurrentRecognized = true; _recognizeStateChanged = true; _pathPen = _tempMainPen; //ResetPathDirtyRect(); } DrawAndUpdate(); if (ShowCommandName) _labelChanged = false; _recognizeStateChanged = false; }
public virtual void Add(GestureIntent intent) { GestureIntents.Add(intent.Gesture, intent); }
private void HandleIntentReadyToExecute(GestureIntent intent) { if (!ShowPath && !ShowCommandName) return; Debug.WriteLine("WhenIntentReadyToExecute"); if (ShowCommandName) { ShowLabel(Color.White, _labelText, Color.FromArgb(120, 0, 0, 0)); } //draw DrawAndUpdate(); //clear if (ShowPath) _pathVisible = false; if (ShowCommandName) _labelChanged = false; if (ViewFadeOut) FadeOut(); else EndView(); }