internal void UpdateByRawMouse(ref NativeMethods.RAWMOUSE mouse)
        {
            FrameNumber++;
            switch (StatusForMouseEmulation)
            {
            case EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.StandingBy:
                Reset();
                break;

            case EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.DetectingFace:
                Reset();
                FaceDetectionArea = new System.Drawing.Rectangle(10, 10, 320, 240);
                break;

            case EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.DetectedFace:
            case EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.SelectedFaceAndDetectingHands:
            {
                Reset();
                FaceDetectionArea   = new System.Drawing.Rectangle(10, 10, 320, 240);
                DetectedFacesCount  = 1;
                Faces[0].IsDetected = true;
                Faces[0].Area       = new System.Drawing.Rectangle(100, 100, 50, 50);
                Faces[0].Score      = 100;
                SelectedFaceIndex   = -1;
                Faces[0].IsSelected = false;
                if (StatusForMouseEmulation == EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.SelectedFaceAndDetectingHands)
                {
                    SelectedFaceIndex         = 0;
                    Faces[0].IsSelected       = true;
                    Hands[0].RecognitionState = EgsGestureHidReportRecognitionState.Detecting;
                    Hands[0].DetectionArea    = new System.Drawing.Rectangle(160, 50, 100, 100);
                }
            }
            break;

            case EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.DetectedAndScreenMappedRightHand:
                UpdateByRawMouseWhileDetectedAndScreenMappedRightHand(ref mouse);
                StatusForMouseEmulation = EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.TrackingRightHand;
                break;

            case EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.TrackingRightHand:
                UpdateByRawMouseWhileTrackingRightHand(ref mouse);
                break;

            case EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.StoppedTrackingRightHand:
                Hands[0].Reset();
                StatusForMouseEmulation = EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.StandingBy;
                break;

            default:
                break;
            }
            if (mouse.buttons.usButtonFlags == NativeMethods.RawMouseButtonFlags.RI_MOUSE_RIGHT_BUTTON_DOWN)
            {
                var nextStatusAsInt = (((int)StatusForMouseEmulation) + 1) % (int)EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick.Count;
                StatusForMouseEmulation = (EgsDeviceEgsGestureHidReportStatusEmulatedByMouseAndChangedByRightClick)nextStatusAsInt;
            }
            OnReportUpdated(EventArgs.Empty);
        }
 void UpdateByRawMouseWhileDetectedAndScreenMappedRightHand(ref NativeMethods.RAWMOUSE mouse)
 {
     // MUSTDO: check this usage.
     DetectedFacesCount        = 1;
     SelectedFaceIndex         = 0;
     TrackingHandsCount        = 1;
     Hands[0].RecognitionState = EgsGestureHidReportRecognitionState.OnScreenMappedAreaUpdated;
     Hands[0].ObjectKind       = 0;
     Hands[0].TrackingArea     = new System.Drawing.Rectangle(170, 60, 80, 60);
     Hands[0].ScreenMappedArea = new System.Drawing.Rectangle(190, 80, 40, 30);
     Hands[0].X          = System.Windows.Forms.Cursor.Position.X;
     Hands[0].Y          = System.Windows.Forms.Cursor.Position.Y;
     Hands[0].IsTouching = false;
     Hands[1].Reset();
 }
Beispiel #3
0
        internal void UpdateByRawMouse(ref NativeMethods.RAWMOUSE mouse)
        {
            // MUSTDO: remember the purpose of this method.
            // NOTE: mouse.lLastX and mouse.lLastY are different between mouse operation and EGS HID operation.
            // By input from EgsDevice,    mouse.usFlags == NativeMethods.RawMouseFlags.MOUSE_MOVE_ABSOLUTE. Absolute coordinate.
            // By input from normal mouse, mouse.usFlags == NativeMethods.RawMouseFlags.MOUSE_MOVE_RELATIVE. Relative coordinate, i.e. displacement from previous position.
            if (mouse.usFlags != NativeMethods.RawMouseFlags.MOUSE_MOVE_ABSOLUTE && mouse.usFlags != NativeMethods.RawMouseFlags.MOUSE_MOVE_RELATIVE)
            {
                Contacts[0].Reset();
                Contacts[1].Reset();
                OnReportUpdated(EventArgs.Empty);
                return;
            }

            Contacts[0].X = System.Windows.Forms.Cursor.Position.X;
            Contacts[0].Y = System.Windows.Forms.Cursor.Position.Y;
            var previousIsTouching = Contacts[0].TipSwitch;

            if (previousIsTouching == false && (mouse.buttons.usButtonFlags == NativeMethods.RawMouseButtonFlags.RI_MOUSE_LEFT_BUTTON_DOWN))
            {
                Contacts[0].TipSwitch = true;
            }
            else if (previousIsTouching == true && (mouse.buttons.usButtonFlags == NativeMethods.RawMouseButtonFlags.RI_MOUSE_LEFT_BUTTON_UP))
            {
                Contacts[0].TipSwitch = false;
            }
            // RAWMOUSE does not have information about tracking.  Basically mouse is always active, so it is always "IsTracking == true".
            Contacts[0].IsTracking = true;

            if (false)
            {
                Console.Write("mouse.lLastX={0}  ", mouse.lLastX);
                Console.Write("mouse.lLastY={0}  ", mouse.lLastY);
                Console.Write("Contacts[0].X={0}  ", Contacts[0].X);
                Console.Write("Contacts[0].Y={0}  ", Contacts[0].Y);
                Console.Write("Contacts[0].TipSwitch={0}  ", Contacts[0].TipSwitch);
                Console.WriteLine();
            }
            // 2nd point is not used.
            Contacts[1].Reset();
            OnReportUpdated(EventArgs.Empty);
        }
        void UpdateByRawMouseWhileTrackingRightHand(ref NativeMethods.RAWMOUSE mouse)
        {
            DetectedFacesCount = 1;
            SelectedFaceIndex  = 0;
            TrackingHandsCount = 1;

            Hands[0].RecognitionState = EgsGestureHidReportRecognitionState.Tracking;
            Hands[0].ObjectKind       = 0;

            if (ApplicationCommonSettings.IsToEmulateReportByActualMouseRawInputToDebugViews)
            {
                Hands[0].X = System.Windows.Forms.Cursor.Position.X;
                Hands[0].Y = System.Windows.Forms.Cursor.Position.Y;
                // NOTE: The value of the next line is not correct!  So It's no use.
                Hands[0].IsTouching = (System.Windows.Forms.Control.MouseButtons & System.Windows.Forms.MouseButtons.Left) == System.Windows.Forms.MouseButtons.Left;
                Hands[1].Reset();
                return;
            }
            else if (mouse.usFlags == NativeMethods.RawMouseFlags.MOUSE_MOVE_ABSOLUTE)
            {
                if (ApplicationCommonSettings.IsDebugging)
                {
                    Debugger.Break();
                }
                // Absolute coordinate.  EGS devices send the value in the absolute coordinates.
                Hands[0].X = (int)(mouse.lLastX * Hands[0].XScaleFactor);
                Hands[0].Y = (int)(mouse.lLastY * Hands[0].YScaleFactor);
            }
            else if (mouse.usFlags == NativeMethods.RawMouseFlags.MOUSE_MOVE_RELATIVE)
            {
                // Relative coordinate from previous position.  Normal mouses send the value in the relative coordinates.
                if (ApplicationCommonSettings.IsDebugging)
                {
                    Debugger.Break();
                }
                Hands[0].X += (int)(mouse.lLastX * Hands[0].XScaleFactor);
                Hands[0].Y += (int)(mouse.lLastY * Hands[0].YScaleFactor);
            }
            else
            {
                Hands[0].Reset();
                Hands[1].Reset();
                OnReportUpdated(EventArgs.Empty);
                return;
            }
            // NOTE: Must save the previous ON/OFF state.  In dragging, LEFT_BUTTON_DOWN is false, so it cannot recognize touch state in dragging.
            var isHand0TouchingPrevious = Hands[0].IsTouching;
            var isMouseLeftButtonDown   = (mouse.buttons.usButtonFlags == NativeMethods.RawMouseButtonFlags.RI_MOUSE_LEFT_BUTTON_DOWN);
            var isMouseLeftButtonUp     = (mouse.buttons.usButtonFlags == NativeMethods.RawMouseButtonFlags.RI_MOUSE_LEFT_BUTTON_UP);

            if (isMouseLeftButtonDown && (isHand0TouchingPrevious == false))
            {
                Hands[0].IsTouching = true;
            }
            else if (isMouseLeftButtonUp && (isHand0TouchingPrevious == true))
            {
                Hands[0].IsTouching = false;
            }

            if (false)
            {
                Console.Write("mouse.lLastX={0}  ", mouse.lLastX);
                Console.Write("mouse.lLastY={0}  ", mouse.lLastY);
                //Console.Write("isHand0TouchingPrevious={0}  ", isHand0TouchingPrevious);
                Console.Write("isMouseLeftButtonDown={0}  ", isMouseLeftButtonDown);
                Console.Write("isMouseLeftButtonUp={0}  ", isMouseLeftButtonUp);
                //Console.Write("Hands[0].X={0}  ", Hands[0].X);
                //Console.Write("Hands[0].Y={0}  ", Hands[0].Y);
                Console.WriteLine();
            }

            // It does not use 2nd point.
            Hands[1].Reset();
        }