Beispiel #1
0
        public static void Initialize()
        {
            viewControlHelper  = ViewControlHelper.Instance;
            geoNodeParams      = new MyGestureParams();
            myPath             = new MyGesturePath(oldPoint, newPoint);
            needDebouncing     = false;
            inkCanvasMouseDown = false;
            debouncingTimer    = null;
            hoveredButton      = null;
            hoveredInkCanvas   = null;

            parentWindow     = App.Current.MainWindow;
            XLabel           = (Label)parentWindow.FindName("XLabel");
            YLabel           = (Label)parentWindow.FindName("YLabel");
            hand_palm        = (Image)parentWindow.FindName("hand_palm");
            hand_grip        = (Image)parentWindow.FindName("hand_grip");
            testLabel        = (Label)parentWindow.FindName("testLabel");
            currentPageLabel = (Label)parentWindow.FindName("currentPageLabel");
            debouncingLabel  = (Label)parentWindow.FindName("debouncingLabel");
            eventBox         = (TextBox)parentWindow.FindName("eventBox");
            newPoint         = new Point();
            oldPoint         = new Point(-1, -1);
        }
Beispiel #2
0
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.ProgressPercentage == 1)
            {
                backgroundWorker2.RunWorkerAsync();
                return;
            }

            //GestureControlHelper.geoNodeParams = (MyGestureParams)e.UserState;
            //GestureControlHelper.hoveredButton = hoveredButton;
            //GestureControlHelper.hoveredInkCanvas = hoveredInkCanvas;
            //GestureControlHelper.RunGestureControl();


            MyGestureParams geoNodeParams = new MyGestureParams();

            geoNodeParams = (MyGestureParams)e.UserState;
            MyGesturePath myPath = null;

            //move the hand
            XLabel.Content = geoNodeParams.nodeX.ToString();
            YLabel.Content = geoNodeParams.nodeY.ToString();

            //check existance of geoNode
            if ((geoNodeParams.alertLabel != PXCMGesture.Alert.Label.LABEL_ANY) &&
                (geoNodeParams.alertLabel != PXCMGesture.Alert.Label.LABEL_GEONODE_INACTIVE) &&
                (geoNodeParams.alertLabel != PXCMGesture.Alert.Label.LABEL_FOV_BLOCKED))
            {
                NativeMethods.SetCursorPos(
                    (int)Application.Current.MainWindow.Left + (int)SystemParameters.FixedFrameVerticalBorderWidth + 1 + 640 - (int)geoNodeParams.nodeX * 2,
                    (int)Application.Current.MainWindow.Top + (int)SystemParameters.FixedFrameHorizontalBorderHeight + (int)SystemParameters.WindowCaptionHeight + 1 + (int)geoNodeParams.nodeY * 2
                    );

                if ((geoNodeParams.alertLabel == PXCMGesture.Alert.Label.LABEL_FOV_LEFT) ||
                    (geoNodeParams.alertLabel == PXCMGesture.Alert.Label.LABEL_FOV_RIGHT) ||
                    (geoNodeParams.alertLabel == PXCMGesture.Alert.Label.LABEL_FOV_TOP) ||
                    (geoNodeParams.alertLabel == PXCMGesture.Alert.Label.LABEL_FOV_BOTTOM))
                {
                    //signalLight.FillColor = Color.Yellow;
                    //signalLabel.Text = "Too close to dection boundary";
                }
                else
                {
                    // signalLight.FillColor = Color.Green;
                    //signalLabel.Text = "Under detection";
                }

                newPoint = new Point(640 - Convert.ToInt32(geoNodeParams.nodeX) * 2, Convert.ToInt32(geoNodeParams.nodeY) * 2);
                //check opennes
                if (geoNodeParams.opennes > opennesThreadshold)
                {
                    this.hand_palm.Visibility = Visibility.Visible;
                    this.hand_grip.Visibility = Visibility.Hidden;

                    //======Start of method 1========
                    raiseInkCanvasMouseEvent("MouseUpEvent");
                    //======End of method 1========
                }
                else if (geoNodeParams.opennes >= 0 && geoNodeParams.opennes <= opennesThreadshold)
                {
                    this.hand_palm.Visibility = Visibility.Hidden;
                    this.hand_grip.Visibility = Visibility.Visible;

                    //draw line
                    //SolidBrush color = new SolidBrush(Color.Black);

                    if ((oldPoint.X == -1) || (oldPoint.Y == -1))
                    {
                        oldPoint = newPoint;
                    }
                    else
                    {
                        myPath = new MyGesturePath(oldPoint, newPoint);

                        //if ((newPoint.X > 160) && (newPoint.X < 480) &&
                        //      (newPoint.Y > 110) && (newPoint.Y < 430))
                        //  {
                        //      myPath = new MyGesturePath(oldPoint, newPoint);

                        //      if ((oldPoint.X != newPoint.X) || (oldPoint.Y != newPoint.Y))
                        //      {
                        //          //this.myPathList.Add(myPath);
                        //      }
                        //      //panel1.Invalidate();
                        //      //drawingCanvas.Invalidate();
                        //      // signalLight.Invalidate();
                        //  }
                    }
                    // Perform actions on the hit test results list.
                    //Raise the Button mouse click event
                    if (hoveredButton != null && needDebouncing == false)
                    {
                        needDebouncing = true;
                        hoveredButton.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left)
                        {
                            RoutedEvent = Button.ClickEvent
                        });
                        debouncingTimer = EasyTimer.SetTimeout(() =>
                        {
                            needDebouncing = false;
                        }, 1000);
                    }
                    //Raise the InkCanvas mouse down event
                    //if (hoveredInkCanvas != null)
                    if (hoveredInkCanvas != null && inkCanvasMouseDown == false)
                    {
                        //======Start of method 1========
                        raiseInkCanvasMouseEvent("MouseDownEvent");
                        //======End of method 1========

                        //======Start of method 2========

                        //  Problem: can show the stroke correctly, but very high latency
                        //  Findings: probably because this method simply add child to Inkcanvas, processing power and memory consuming
                        //Line linetodraw = new Line();
                        //linetodraw.X1 = myPath.OldPoint.X;//0
                        //linetodraw.Y1 = myPath.OldPoint.Y;//0
                        //linetodraw.X2 = myPath.NewPoint.X;//10
                        //linetodraw.Y2 = myPath.NewPoint.Y;//10
                        //linetodraw.StrokeThickness = 2;
                        //linetodraw.Stroke = new SolidColorBrush(Colors.Black);
                        //this.hoveredInkCanvas.Children.Add(linetodraw);
                        //=======End of method 2=========

                        //======Method 3 under investigation=====

                        //  Target:
                        //StrokeCollection strokeCollection = new StrokeCollection();
                        //Stroke stroke = new Stroke();
                        //strokeCollection.

                        //======Method 3 under investigation=====
                    }
                }
                //if (geoNodeParams.opennes <= opennesThreadshold) selectable = false;
                oldPoint = newPoint;

                if (geoNodeParams.gestureLabel == PXCMGesture.Gesture.Label.LABEL_NAV_SWIPE_DOWN)
                {
                    viewControlHelper.gotoPreviousView();
                }
            }
            else
            {
                this.hand_palm.Visibility = Visibility.Hidden;
                this.hand_grip.Visibility = Visibility.Hidden;
                //======Start of method 1========
                raiseInkCanvasMouseEvent("MouseUpEvent");
                //======End of method 1========
            }
            var viewString = "Views:";

            foreach (var view in viewControlHelper.getViewsHistory())
            {
                viewString += view.ToString() + ",";
            }
            this.testLabel.Content = viewString;
            //this.testLabel.Content = viewControlHelper.previousViews.Count().ToString();
            this.currentPageLabel.Content = viewControlHelper.getCurrentView().ToString();
            this.debouncingLabel.Content  = needDebouncing.ToString();

            //capture the events
            //var events = EventManager.GetRoutedEvents();
            //foreach (var routedEvent in events)
            //{
            //    EventManager.RegisterClassHandler(typeof(UserControl), routedEvent, new RoutedEventHandler(handler));
            //}
            //eventBox.ScrollToEnd();
        }