// 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); } } } } } }
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); }
// 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(); } } }
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); } } } }
// 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); } }