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
        private void HandleSimulateFingers()
        {
            // Simulate pinch & twist?
            if (LeanInput.GetMouseExists() == true && LeanInput.GetKeyboardExists() == true)
            {
                var mousePosition = LeanInput.GetMousePosition();
                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)
                {
                    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);

                        cachedTouch.AddFinger(-2, center - (mousePosition - center), 1.0f, mouseSet);
                    }
                    // Simulate multi drag?
                    else if (LeanInput.GetPressed(MultiDragKey) == true)
                    {
                        cachedTouch.AddFinger(-2, mousePosition, 1.0f, mouseSet);
                    }
                }
            }
        }
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);
            }
        }