Example #1
0
        // Read new hardware finger data
        private void PollFingers()
        {
            // Update real fingers
            if (LeanInput.GetTouchCount() > 0)
            {
                for (var i = 0; i < LeanInput.GetTouchCount(); i++)
                {
                    int id; Vector2 position; float pressure; bool set;

                    LeanInput.GetTouch(i, out id, out position, out pressure, out set);

                    AddFinger(id, position, pressure, set);
                }
            }
            // If there are no real touches, simulate some from the mouse?
            else if (LeanInput.GetMouseExists() == true)
            {
                var mouseSet = false;
                var mouseUp  = false;

                for (var i = 0; i < 5; i++)
                {
                    mouseSet |= LeanInput.GetMousePressed(i);
                    mouseUp  |= LeanInput.GetMouseUp(i);
                }

                if (mouseSet == true || mouseUp == true)
                {
                    var mousePosition = LeanInput.GetMousePosition();

                    // Is the mouse within the screen?
                    //if (new Rect(0, 0, Screen.width, Screen.height).Contains(mousePosition) == true)
                    {
                        AddFinger(-1, mousePosition, 1.0f, mouseSet);

                        // Simulate pinch & twist?
                        if (SimulateMultiFingers == true && LeanInput.GetKeyboardExists() == true)
                        {
                            if (LeanInput.GetPressed(MovePivotKey) == true)
                            {
                                pivot.x = mousePosition.x / Screen.width;
                                pivot.y = mousePosition.y / Screen.height;
                            }

                            if (LeanInput.GetPressed(PinchTwistKey) == true)
                            {
                                var center = new Vector2(Screen.width * pivot.x, Screen.height * pivot.y);

                                AddFinger(-2, center - (mousePosition - center), 1.0f, mouseSet);
                            }
                            // Simulate multi drag?
                            else if (LeanInput.GetPressed(MultiDragKey) == true)
                            {
                                AddFinger(-2, mousePosition, 1.0f, mouseSet);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        // Read new hardware finger data
        private void PollFingers()
        {
            // Submit real fingers?
            if (useTouch == true && LeanInput.GetTouchCount() > 0)
            {
                for (var i = 0; i < LeanInput.GetTouchCount(); i++)
                {
                    int id; Vector2 position; float pressure; bool set;

                    LeanInput.GetTouch(i, out id, out position, out pressure, out set);

                    AddFinger(id, position, pressure, set);
                }
            }

            // Submit mouse hover as finger?
            if (useHover == true && LeanInput.GetMouseExists() == true)
            {
                var mousePosition = LeanInput.GetMousePosition();
                var hoverFinger   = AddFinger(HOVER_FINGER_INDEX, mousePosition, 0.0f, true);

                hoverFinger.StartedOverGui = false;
                hoverFinger.LastSet        = true;
            }

            // Submit mouse buttons as finger?
            if (useMouse == true && LeanInput.GetMouseExists() == true)
            {
                var mouseSet = false;
                var mouseUp  = false;

                for (var i = 0; i < 5; i++)
                {
                    mouseSet |= LeanInput.GetMousePressed(i);
                    mouseUp  |= LeanInput.GetMouseUp(i);
                }

                if (mouseSet == true || mouseUp == true)
                {
                    var mousePosition = LeanInput.GetMousePosition();

                    // Is the mouse within the screen?
                    //if (new Rect(0, 0, Screen.width, Screen.height).Contains(mousePosition) == true)
                    {
                        AddFinger(MOUSE_FINGER_INDEX, mousePosition, 1.0f, mouseSet);
                    }
                }
            }

            // Simulate other fingers?
            if (useSimulator == true)
            {
                if (OnSimulateFingers != null)
                {
                    OnSimulateFingers.Invoke();
                }
            }
        }
Example #3
0
        // Read new hardware finger data
        private void PollFingers()
        {
            // Store all active fingers (these are later removed in AddFinger)
            missingFingers.Clear();

            for (var i = Fingers.Count - 1; i >= 0; i--)
            {
                missingFingers.Add(Fingers[i]);
            }

            // Update real fingers
            if (LeanInput.GetTouchCount() > 0)
            {
                for (var i = 0; i < LeanInput.GetTouchCount(); i++)
                {
                    int id; Vector2 position; float pressure; bool set;

                    LeanInput.GetTouch(i, out id, out position, out pressure, out set);

                    AddFinger(id, position, pressure, set);
                }
            }
            // If there are no real touches, simulate some from the mouse?
            else if (LeanInput.GetMouseExists() == true)
            {
                var mouseSet = false;
                var mouseUp  = false;

                for (var i = 0; i < 5; i++)
                {
                    mouseSet |= LeanInput.GetMousePressed(i);
                    mouseUp  |= LeanInput.GetMouseUp(i);
                }

                if (mouseSet == true || mouseUp == true)
                {
                    var mousePosition = LeanInput.GetMousePosition();

                    // Is the mouse within the screen?
                    //if (new Rect(0, 0, Screen.width, Screen.height).Contains(mousePosition) == true)
                    {
                        AddFinger(-1, mousePosition, 1.0f, mouseSet);

                        // Simulate pinch & twist?
                        if (SimulateMultiFingers == true && LeanInput.GetKeyboardExists() == true)
                        {
                            if (LeanInput.GetPressed(MovePivotKey) == true)
                            {
                                pivot.x = mousePosition.x / Screen.width;
                                pivot.y = mousePosition.y / Screen.height;
                            }

                            if (LeanInput.GetPressed(PinchTwistKey) == true)
                            {
                                var center = new Vector2(Screen.width * pivot.x, Screen.height * pivot.y);

                                AddFinger(-2, center - (mousePosition - center), 1.0f, mouseSet);
                            }
                            // Simulate multi drag?
                            else if (LeanInput.GetPressed(MultiDragKey) == true)
                            {
                                AddFinger(-2, mousePosition, 1.0f, mouseSet);
                            }
                        }
                    }
                }
            }

            // Force missing fingers to go up (there normally shouldn't be any)
            tempFingers.Clear();

            tempFingers.AddRange(missingFingers);

            foreach (var finger in tempFingers)
            {
                AddFinger(finger.Index, finger.ScreenPosition, finger.Pressure, false);
            }
        }