/// <summary> /// Averages the position of the touchEvent.HitTestDetails position based on the number of touches. /// </summary> /// <param name="touchEvent">The new TouchTargetEvent</param> /// <param name="hitTestDetails">The contacEvent.HitTestDetails as ScrollViewerHitTestDetails</param> /// <param name="averageX"></param> /// <param name="averageY"></param> private void AverageTouchPosition(TouchTargetEvent touchEvent, ScrollViewerHitTestDetails hitTestDetails, out float averageX, out float averageY) { // Get the down hitTestDetails for this touch. ScrollViewerHitTestDetails downDetails = touchDownTouchInformation[touchEvent.Touch.Id].HitTestDetails as ScrollViewerHitTestDetails; // Calculate how much has changed since last move. averageX = (downDetails.HorizontalPosition - hitTestDetails.HorizontalPosition) * HorizontalViewportSize; averageY = (downDetails.VerticalPosition - hitTestDetails.VerticalPosition) * VerticalViewportSize; // Average the change by the number of touches on the Surface. averageX /= touchDownTouchInformation.Count; averageY /= touchDownTouchInformation.Count; }
/// <summary> /// Updates manipulators to reflect the touch change. /// </summary> /// <param name="touchEvent">The new TouchTargetEvent</param> /// <param name="details">The contacEvent.HitTestDetails as ScrollViewerHitTestDetails</param> private void UpdateCurrentManipulators(TouchTargetEvent touchEvent, ScrollViewerHitTestDetails details) { // Try to find the changed touch in the manipulators list. bool foundManipulator = false; for (int i = 0; i < manipulations.Count; i++) { Manipulator2D manipulator = manipulations[i]; if (manipulator.Id == touchEvent.Touch.Id) { manipulations.Remove(manipulator); Manipulator2D manipulatorToAdd = new Manipulator2D(touchEvent.Touch.Id, ConvertFromHorizontalValueToScreenSpace(details.HorizontalPosition), ConvertFromVerticalValueToScreenSpace(details.VerticalPosition)); // Performance: It doesn't matter where we insert, but if all the touches are being updated, // then putting the most recent change at the end will mean that there is one less touch // to go through the next time this loop is executed. if (manipulations.Count == 0) { manipulations.Add(manipulatorToAdd); } else { manipulations.Insert(manipulations.Count - 1, manipulatorToAdd); } foundManipulator = true; break; } } // The manipulator isn't in the list so add it. if (!foundManipulator) { manipulations.Add(new Manipulator2D(touchEvent.Touch.Id, ConvertFromHorizontalValueToScreenSpace(details.HorizontalPosition), ConvertFromVerticalValueToScreenSpace(details.VerticalPosition))); } }
/// <summary> /// Averages the position of the contactEvent.HitTestDetails position based on the number of contacts. /// </summary> /// <param name="contactEvent">The new ContactTargetEvent</param> /// <param name="hitTestDetails">The contacEvent.HitTestDetails as ScrollViewerHitTestDetails</param> /// <param name="averageX"></param> /// <param name="averageY"></param> private void AverageContactPosition(ContactTargetEvent contactEvent, ScrollViewerHitTestDetails hitTestDetails, out float averageX, out float averageY) { // Get the down hitTestDetails for this contact. ScrollViewerHitTestDetails downDetails = contactDownContactInformation[contactEvent.Contact.Id].HitTestDetails as ScrollViewerHitTestDetails; // Calculate how much has changed since last move. averageX = (downDetails.HorizontalPosition - hitTestDetails.HorizontalPosition) * HorizontalViewportSize; averageY = (downDetails.VerticalPosition - hitTestDetails.VerticalPosition) * VerticalViewportSize; // Average the change by the number of contacts on the Surface. averageX /= contactDownContactInformation.Count; averageY /= contactDownContactInformation.Count; }