//Inertia is completed, we can reuse the object public void Completed(PictureTracker pictureTracker) { pictureTracker.Picture = null; _pictureTrackers.Push(pictureTracker); }
private PictureTracker GetPictureTracker(int touchId, Point location) { PictureTracker pictureTracker; //See if we already track the picture with the touchId if (_pictureTrackerMap.TryGetValue(touchId, out pictureTracker)) return pictureTracker; //Get the picture under the touch location Picture picture = FindPicture(location); if (picture == null) return null; //See if we track the picture with other ID pictureTracker = (from KeyValuePair<int, PictureTracker> entry in _pictureTrackerMap where entry.Value.Picture == picture select entry.Value).FirstOrDefault(); //First time if (pictureTracker == null) { //take from stack if (_pictureTrackers.Count > 0) pictureTracker = _pictureTrackers.Pop(); else //create new pictureTracker = new PictureTracker(this); pictureTracker.Picture = picture; BringPictureToFront(picture); } //remember the corelation between the touch id and the picture _pictureTrackerMap[touchId] = pictureTracker; return pictureTracker; }
//We remove the touchID from the tracking map since the fingers are no longer touch //the picture public void InInertia(PictureTracker pictureTracker) { //remove all touch id from the map foreach (int id in (from KeyValuePair<int, PictureTracker> entry in _pictureTrackerMap where entry.Value == pictureTracker select entry.Key).ToList()) { _pictureTrackerMap.Remove(id); } }