Beispiel #1
0
        public override void Perform()
        {
            ApplicationGesture[] allAppGestures = (ApplicationGesture[])Enum.GetValues(ApplicationGesture.Up.GetType());

            //Get a number of gestures we will enable
            int gestureCount = CountIndex % (allAppGestures.Length - 2) + 1;

            ArrayList enableGesturesArrayList = new ArrayList();

            //Fill the arraylist with the number of gestures we want to enable
            while (gestureCount > 0)
            {
                int index = GestureIndex % allAppGestures.Length;
                GestureIndex++;

                //If adding an AllGestures,reject it and continue to get the next gesture to add
                if (allAppGestures[index] == ApplicationGesture.AllGestures)
                {
                    continue;
                }

                bool gestureExists = false;

                //Check if the appgesture is already added. if there are duplicates, API throws exception
                for (int i = 0; i < enableGesturesArrayList.Count; i++)
                {
                    ApplicationGesture currentGesture = (ApplicationGesture)enableGesturesArrayList[i];
                    //Don't add something that already exists in the enableGestures list
                    if (allAppGestures[index] == currentGesture)
                    {
                        gestureExists = true;
                        break;
                    }
                }
                //Not added so far, add and continue
                if (gestureExists == false)
                {
                    enableGesturesArrayList.Add(allAppGestures[index]);
                    gestureCount--; //One less thing to add
                }
            }

            ApplicationGesture[] applicationGestureArray = (ApplicationGesture[])enableGesturesArrayList.ToArray(ApplicationGesture.ArrowDown.GetType());

            //Sets the application gestures that the InkCanvas recognizes.
            InkCanvas.SetEnabledGestures(applicationGestureArray);
        }
        public void Analyzer()
        {
            StrokeCollection collection = null;

            try
            {
                if (this.Count < 10)
                {
                    return;
                }

                GestureRecognizer gestureRecognizer = new GestureRecognizer();

                canvas.SetEnabledGestures(new ApplicationGesture[] { ApplicationGesture.AllGestures });
                gestureRecognizer.SetEnabledGestures(new ApplicationGesture[] { ApplicationGesture.AllGestures });

                Stroke stroke = new Stroke(pointCollection);
                collection = new StrokeCollection();
                collection.Add(stroke);

                var result = gestureRecognizer.Recognize(collection);

                if (result[0].ApplicationGesture != null)
                {
                    if (result[0].ApplicationGesture != ApplicationGesture.NoGesture)
                    {
                        var resultGesture = VSGestureService.Current.VSGestureInfo.GestureActionMapper.Find(
                            o => o.GestureActionType.ToString() == result[0].ApplicationGesture.ToString());

                        if (resultGesture != null)
                        {
                            //MessageBox.Show(resultGesture.Value);
                            var action = VSGestureService.Current.GestureActionList.GestureItem.Find(o => o.Name == resultGesture.GestureItemName);
                            if (action == null)
                            {
                                return;
                            }

                            if (resultGesture.ActionType == ActionType.Command)
                            {
                                var cmd = new ActionCommand(new ExecuteCommand(action.Value, action.Argument));
                                cmd.Execute();
                            }
                            else if (resultGesture.ActionType == ActionType.Action)
                            {
                                var cmd = new ActionCommand(new ExecuteCustomCommand(action.Value));
                                cmd.Execute();
                            }
                        }
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException exCom)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                pointCollection = null;
                pointCollection = new StylusPointCollection();
            }
        }
Beispiel #3
0
 public MainWindow()
 {
     InitializeComponent();
     InkCanvas.SetEnabledGestures(new[] { ApplicationGesture.AllGestures });
 }