Exemplo n.º 1
0
        /// <summary>Gets the pinch ratio of the fingers (reciprocal of pinch scale).</summary>
        public static bool TryGetPinchRatio(List <LeanFinger> fingers, Vector2 center, Vector2 lastCenter, ref float ratio, float wheelSensitivity = 0.0f)
        {
            var distance     = GetScreenDistance(fingers, center);
            var lastDistance = GetLastScreenDistance(fingers, lastCenter);

            if (distance > 0.0f)
            {
                ratio = lastDistance / distance;

                return(true);
            }

            if (wheelSensitivity != 0.0f)
            {
                var scroll = LeanInput.GetMouseWheelDelta();

                if (scroll > 0.0f)
                {
                    ratio = 1.0f + wheelSensitivity; return(true);
                }

                if (scroll < 0.0f)
                {
                    ratio = 1.0f - wheelSensitivity; return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private bool RequiredButtonPressed(LeanFinger finger)
        {
            if (finger.Index < 0)
            {
                if (LeanInput.GetMouseExists() == true)
                {
                    if ((requiredButtons & ButtonTypes.LeftMouse) != 0 && LeanInput.GetMousePressed(0) == true)
                    {
                        return(true);
                    }

                    if ((requiredButtons & ButtonTypes.RightMouse) != 0 && LeanInput.GetMousePressed(1) == true)
                    {
                        return(true);
                    }

                    if ((requiredButtons & ButtonTypes.MiddleMouse) != 0 && LeanInput.GetMousePressed(2) == true)
                    {
                        return(true);
                    }
                }
            }
            else if ((requiredButtons & ButtonTypes.Touch) != 0)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>This method returns a list of all fingers based on the current settings.
        /// NOTE: This method must be called every frame/Update.</summary>
        public List <LeanFinger> UpdateAndGetFingers(bool ignoreUpFingers = false)
        {
            if (filteredFingers == null)
            {
                filteredFingers = new List <LeanFinger>();
            }

            filteredFingers.Clear();

            if (Filter == FilterType.AllFingers)
            {
                filteredFingers.AddRange(LeanSelectableByFinger.GetFingers(IgnoreStartedOverGui, false, 0, RequiredSelectable));
            }
            else if (fingers != null)
            {
                filteredFingers.AddRange(fingers);

                for (var i = fingers.Count - 1; i >= 0; i--)
                {
                    if (fingers[i].Up == true)
                    {
                        fingers.RemoveAt(i);
                    }
                }
            }

            if (ignoreUpFingers == true)
            {
                for (var i = filteredFingers.Count - 1; i >= 0; i--)
                {
                    if (filteredFingers[i].Up == true)
                    {
                        filteredFingers.RemoveAt(i);
                    }
                }
            }

            if (RequiredMouseButtons > 0 && SimulatedFingersExist(filteredFingers) == true)
            {
                for (var i = 0; i < 5; i++)
                {
                    var mask = 1 << i;

                    if ((RequiredMouseButtons & mask) != 0 && LeanInput.GetMousePressed(i) == false)
                    {
                        filteredFingers.Clear();
                    }
                }

                return(filteredFingers);
            }

            if (RequiredFingerCount > 0 && filteredFingers.Count != RequiredFingerCount)
            {
                filteredFingers.Clear();
            }

            return(filteredFingers);
        }
Exemplo n.º 5
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();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>This method returns a list of all fingers based on the current settings.</summary>
        public List <LeanFinger> GetFingers(bool ignoreUpFingers = false)
        {
            if (fingers == null)
            {
                fingers = new List <LeanFinger>();
            }

            switch (Filter)
            {
            case FilterType.AllFingers:
            {
                fingers.Clear();

                fingers.AddRange(LeanSelectable.GetFingers(IgnoreStartedOverGui, false, RequiredFingerCount, RequiredSelectable));
            }
            break;
            }

            if (ignoreUpFingers == true)
            {
                for (var i = fingers.Count - 1; i >= 0; i--)
                {
                    if (fingers[i].Up == true)
                    {
                        fingers.RemoveAt(i);
                    }
                }
            }

            if (RequiredMouseButtons != 0)
            {
                var keep = true;

                for (var i = 0; i < 5; i++)
                {
                    var mask = 1 << i;

                    if ((RequiredMouseButtons & mask) != 0 && LeanInput.GetMousePressed(i) == false)
                    {
                        keep = false; break;
                    }
                }

                if (keep == false)
                {
                    for (var i = fingers.Count - 1; i >= 0; i--)
                    {
                        if (fingers[i].Index < 0)
                        {
                            fingers.RemoveAt(i);
                        }
                    }
                }
            }

            return(fingers);
        }
 protected virtual void Update()
 {
     if (this == Instances[0])
     {
         if (LeanInput.GetDown(CloseKey) == true)
         {
             CloseTopMost();
         }
     }
 }
Exemplo n.º 8
0
        protected virtual void Update()
        {
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

            if (RequiredMouseButton >= 0 && LeanInput.GetMousePressed(RequiredMouseButton) == false)
            {
                return;
            }

            var finalDelta = LeanInput.GetMouseWheelDelta();

            if (finalDelta == 0.0f)
            {
                return;
            }

            switch (Modify)
            {
            case ModifyType.Sign:
            {
                finalDelta = Mathf.Sign(finalDelta);
            }
            break;
            }

            finalDelta *= Multiplier;

            switch (Coordinate)
            {
            case CoordinateType.OneBased:
            {
                finalDelta += 1.0f;
            }
            break;
            }

            if (onDelta != null)
            {
                onDelta.Invoke(finalDelta);
            }
        }
Exemplo n.º 9
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);
                    }
                }
            }
        }
Exemplo n.º 10
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);
            }
        }