/// <summary> /// Called after a UISensitiveObject has been attached to the sensitive-tree. /// </summary> /// <param name="obj">The new object.</param> private void ObjectAttached(UISensitiveObject obj) { if (this.raisingMouseEvents) { /// Postpone the needed sensor operations List <UISensitiveObject> newObjects = new List <UISensitiveObject>(); obj.WalkSensitiveTreeDFS(ref newObjects); foreach (UISensitiveObject newObj in newObjects) { /// Save the created sensor and indicate that it will have to be registered. UIMouseSensor newSensor = newObj.MouseSensor as UIMouseSensor; if (newSensor == null) { throw new UIException("Incompatible mouse sensor!"); } this.tmpSensors.Add(newSensor); this.tmpSensorOperations.Add(true); } } else { /// Execute the needed sensor operations List <UISensitiveObject> newObjects = new List <UISensitiveObject>(); obj.WalkSensitiveTreeDFS(ref newObjects); foreach (UISensitiveObject newObj in newObjects) { UIMouseSensor newSensor = newObj.MouseSensor as UIMouseSensor; if (newSensor == null) { throw new UIException("Incompatible mouse sensor!"); } this.allSensors.Add(newSensor); } } }
/// <summary> /// Called before a UISensitiveObject is detached from the sensitive-tree. /// </summary> /// <param name="obj">The detaching object.</param> private void ObjectDetaching(UISensitiveObject obj) { if (this.raisingMouseEvents) { /// Postpone the needed sensor operations List <UISensitiveObject> detachingObjects = new List <UISensitiveObject>(); obj.WalkSensitiveTreeDFS(ref detachingObjects); foreach (UISensitiveObject detachingObj in detachingObjects) { /// Save the removed sensor and indicate that it will have to be unregistered. UIMouseSensor removedSensor = detachingObj.MouseSensor as UIMouseSensor; if (removedSensor == null) { throw new UIException("Incompatible mouse sensor!"); } this.tmpSensors.Add(removedSensor); this.tmpSensorOperations.Add(false); } } else { /// Execute the needed sensor operations List <UISensitiveObject> detachingObjects = new List <UISensitiveObject>(); obj.WalkSensitiveTreeDFS(ref detachingObjects); foreach (UISensitiveObject detachingObj in detachingObjects) { UIMouseSensor deletedSensor = detachingObj.MouseSensor as UIMouseSensor; if (deletedSensor != null && this.allSensors.Contains(deletedSensor)) { deletedSensor.Reset(); this.allSensors.Remove(deletedSensor); int idxOfDeleted = this.touchedSensors.IndexOf(deletedSensor); if (idxOfDeleted != -1) { this.touchedSensors.RemoveRange(idxOfDeleted, this.touchedSensors.Count - idxOfDeleted); } if (this.activeSensor == deletedSensor) { this.activeSensor = null; } } else { throw new UIException("UIMouseSensor not registered!"); } } } }