/// <summary> /// Checks each contact to see if the thumb has moved under it. /// </summary> private void CheckForTrackCaptureAndChange() { foreach (KeyValuePair<int, ScrollBarHitTestDetails> details in this.captureContactsHitTestDetails) { ScrollBarPart part = GetScrollBarPartHit(details.Value); // If they aren't the same and the part is now a thumb then we capture this contact to the Thumb. if (this.capturedCollectionLookup[details.Key] != part && part == ScrollBarPart.Thumb) { // Recapture this contact to the thumb. this.capturedCollectionLookup.Remove(details.Key); this.capturedCollectionLookup.Add(details.Key, ScrollBarPart.Thumb); this.thumbCapturedContactsList.Add(details.Key); // We want to move the thumb from the point at which it was hit not the top, so store the offset in scrollbar space. distanceOffset.Add(details.Key, details.Value.Position - (Value * (1 - ViewportSize))); StopFlick(); // Pause the animation if we are playing. if (scrollAnimation != null && scrollAnimation.IsPlaying) { scrollAnimation.Pause(); } selectedPart = ScrollBarPart.Thumb; } } }
/// <summary> /// Handles the <strong>ContactDown</strong> event. /// </summary> /// <param name="contactEvent">The container for the contact that the event is about.</param> protected override void OnContactDown(ContactTargetEvent contactEvent) { base.OnContactDown(contactEvent); // Did the contact hit the thumb or the track. ScrollBarPart partHit = GetScrollBarPartHit(contactEvent.HitTestDetails as ScrollBarHitTestDetails); // The contact went down on the ScrollBar so capture it. Controller.Capture(contactEvent.Contact, this); ScrollBarHitTestDetails details = contactEvent.HitTestDetails as ScrollBarHitTestDetails; // Check to make sure the details are of the correct type. // We assert because this should already be caught by HitTestResult.SetHitTestInformation. if (details == null) { Debug.Fail("contactEvent.HitTestDetails should be of type ScrollBarHitTestDetails."); return; } // Stop any flicking behavior. StopFlick(); switch (partHit) { // The Thumb was hit. case ScrollBarPart.Thumb: // Pause the animation if we are playing. if (scrollAnimation != null && scrollAnimation.IsPlaying) { scrollAnimation.Pause(); } // Set the part hit to the thumb. selectedPart = ScrollBarPart.Thumb; // Add this contact to the thumb list so that it can be used for averaging. thumbCapturedContactsList.Add(contactEvent.Contact.Id); // Tie this contact id to the Thumb. capturedCollectionLookup.Add(contactEvent.Contact.Id, ScrollBarPart.Thumb); // We need to be able to look up the hit test details later so save that off. captureContactsHitTestDetails.Add(contactEvent.Contact.Id, details); // We want to move the thumb from the point at which it was hit not the top, so store the offset in scrollbar space. distanceOffset.Add(contactEvent.Contact.Id, details.Position - (Value * (1 - ViewportSize))); break; // The Track was hit. case ScrollBarPart.Track: // Place the contact at the end of the track queue. trackQueue.Enqueue(contactEvent.Contact.Id); // Tie this contact to the Track. capturedCollectionLookup.Add(contactEvent.Contact.Id, ScrollBarPart.Track); // We need to be able to look up the hit test details later so save that off. captureContactsHitTestDetails.Add(contactEvent.Contact.Id, details); // The thumb has contacts captured so don't proceed. if (thumbCapturedContactsList.Count != 0) return; int id = GetFrontOfTrackQueue(); // If the id isn't the same as contact id which went down don't proceed. if (id != contactEvent.Contact.Id) return; selectedPart = ScrollBarPart.Track; // The contact hit before the thumb. if (details.Position < ThumbStartPosition) { if (isReversed) { PageForward(); } else { PageBack(); } } else // The contact hit after the thumb { if (isReversed) { PageBack(); } else { PageForward(); } } break; default: break; } }
/// <summary> /// Handles the <strong>ContactUp</strong> event. /// </summary> /// <param name="contactEvent">The container for the contact that the event is about.</param> protected override void OnContactUp(ContactTargetEvent contactEvent) { base.OnContactUp(contactEvent); int id = contactEvent.Contact.Id; // Depending on state, the contact will be in some of these dictionaries. // we don't need to track their state after this point for the given id // so just call remove since remove doesn't throw exceptions for items not the collection. thumbCapturedContactsList.Remove(id); capturedCollectionLookup.Remove(id); // If there aren't any contacts on the thumb stop manipulating. if (thumbCapturedContactsList.Count == 0 && captureContactsHitTestDetails.Count != 0) { if (manipulationProcessor != null) { ScrollBarHitTestDetails hitTestDetails = captureContactsHitTestDetails[id] as ScrollBarHitTestDetails; float offset = 0; if (distanceOffset.ContainsKey(id)) { offset = distanceOffset[id]; } // The Manipulations should all run in screen space. manipulationProcessor.ProcessManipulators(stopwatch.ElapsedTicks, new List<Manipulator>(), new List<Manipulator> { new Manipulator(id, ToScreenSpace(hitTestDetails.Position - offset), 0) }); } // The thumb is no longer captured so check to see what the selected part should be. if (GetFrontOfTrackQueue() == -1) selectedPart = ScrollBarPart.None; else selectedPart = ScrollBarPart.Track; } distanceOffset.Remove(id); captureContactsHitTestDetails.Remove(id); }
/// <summary> /// Handles the <strong>TouchUp</strong> event. /// </summary> /// <param name="touchEvent">The container for the touch that the event is about.</param> protected override void OnTouchUp(TouchTargetEvent touchEvent) { base.OnTouchUp(touchEvent); int id = touchEvent.Touch.Id; // Depending on state, the touch will be in some of these dictionaries. // we don't need to track their state after this point for the given id // so just call remove since remove doesn't throw exceptions for items not the collection. thumbCapturedTouchesList.Remove(id); capturedCollectionLookup.Remove(id); // If there aren't any touches on the thumb stop manipulating. if (thumbCapturedTouchesList.Count == 0 && captureTouchesHitTestDetails.Count != 0) { if (manipulationProcessor != null) { // No more touches manipulationProcessor.ProcessManipulators(stopwatch.Elapsed100Nanoseconds(), null); } // The thumb is no longer captured so check to see what the selected part should be. if (GetFrontOfTrackQueue() == -1) selectedPart = ScrollBarPart.None; else selectedPart = ScrollBarPart.Track; } distanceOffset.Remove(id); captureTouchesHitTestDetails.Remove(id); }