internal void SetPrimaryUserTrackingId(int newId, EventQueueSection section) { int oldId = PrimaryUserTrackingId; PrimaryUserTrackingId = newId; if (oldId != newId) { section.Enqueue( () => { if (PrimaryUserChanged != null) { var args = new UserTrackingIdChangedEventArgs(oldId, newId); PrimaryUserChanged(this, args); } }); // If the new primary user is the same as the engaged user, then there is no candidate user. // Otherwise, we have a new candidate user as long as the new primary user is a valid user. SetCandidateUserTrackingId( (EngagedUserTrackingId != InvalidUserTrackingId) && (EngagedUserTrackingId == newId) ? InvalidUserTrackingId : newId, section); } }
private void SendTrackedUsersChanged(EventQueueSection section) { section.Enqueue( () => { if (TrackedUsersChanged != null) { TrackedUsersChanged(this, EventArgs.Empty); } }); }
/// <summary> /// Resets all state to the initial state, with no users remembered as engaged or tracked. /// </summary> public void Reset() { using (var section = new EventQueueSection()) { activityMeter.Clear(); TrackedUserTrackingIds.Clear(); PrimaryUserTrackingId = InvalidUserTrackingId; SetCandidateUserTrackingId(InvalidUserTrackingId, section); SetEngagedUserTrackingId(InvalidUserTrackingId, section); SendTrackedUsersChanged(section); } }
/// <summary> /// Called whenever the set of tracked hand pointers has changed. /// </summary> /// <param name="trackedHandPointers"> /// Hand pointers from which we'll update the set of tracked users and the primary user. /// </param> public void UpdateHandPointers(IEnumerable <HandPointer> trackedHandPointers) { bool foundEngagedUser = false; bool foundCandidateUser = false; int primaryUserTrackingId = InvalidUserTrackingId; using (var section = new EventQueueSection()) { TrackedUserTrackingIds.Clear(); foreach (HandPointer handPointer in trackedHandPointers) { if (handPointer.IsTracked && (handPointer.TrackingId != InvalidUserTrackingId)) { // Only consider valid user tracking ids TrackedUserTrackingIds.Add(handPointer.TrackingId); if (EngagedUserTrackingId == handPointer.TrackingId) { foundEngagedUser = true; } if (CandidateUserTrackingId == handPointer.TrackingId) { foundCandidateUser = true; } if (handPointer.IsPrimaryUser) { primaryUserTrackingId = handPointer.TrackingId; } } } SendTrackedUsersChanged(section); // If engaged user was not found in list of candidate users, engaged user has become invalid. if (!foundEngagedUser) { SetEngagedUserTrackingId(InvalidUserTrackingId, section); } // If candidate user was not found in list of candidate users, candidate user has become invalid. if (!foundCandidateUser) { SetCandidateUserTrackingId(InvalidUserTrackingId, section); } SetPrimaryUserTrackingId(primaryUserTrackingId, section); } }
/// <summary> /// Promote candidate user to be the engaged user. /// </summary> /// <param name="candidateTrackingId"> /// Tracking Id of user to be promoted to engaged user. /// If tracking Id does not match the Id of current candidate user, /// no action is taken. /// </param> /// <returns> /// True if specified candidate could be confirmed as the new engaged user, /// false otherwise. /// </returns> public bool ConfirmCandidateEngagement(int candidateTrackingId) { bool isConfirmed = false; if ((candidateTrackingId != InvalidUserTrackingId) && (candidateTrackingId == CandidateUserTrackingId)) { using (var section = new EventQueueSection()) { SetCandidateUserTrackingId(InvalidUserTrackingId, section); SetEngagedUserTrackingId(candidateTrackingId, section); } isConfirmed = true; } return(isConfirmed); }
private void SetCandidateUserTrackingId(int newId, EventQueueSection section) { int oldId = CandidateUserTrackingId; CandidateUserTrackingId = newId; if (oldId != newId) { section.Enqueue( () => { if (CandidateUserChanged != null) { var args = new UserTrackingIdChangedEventArgs(oldId, newId); CandidateUserChanged(this, args); } }); } }