예제 #1
0
 /// <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!");
             }
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Executes the saved sensor operations.
        /// </summary>
        private void ExecuteSensorOperations()
        {
            for (int i = 0; i < this.tmpSensorOperations.Count; i++)
            {
                if (this.tmpSensorOperations[i])
                {
                    /// Register sensor
                    UIMouseSensor newSensor = this.tmpSensors[i];
                    this.allSensors.Add(newSensor);
                }
                else
                {
                    /// Unregister sensor
                    UIMouseSensor deletedSensor = this.tmpSensors[i];
                    if (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!");
                    }
                }
            }
            this.tmpSensorOperations.Clear();
            this.tmpSensors.Clear();
        }