/// <summary> /// Compares two bindings and returns a value indicating whether /// one is less than, equal to, or greater than the other. /// </summary> /// <param name="binding">The first binding to compare.</param> /// <param name="other">The second binding to compare.</param> /// <returns>A signed integer that indicates the relative values of binding and other.</returns> public static int Compare(SingleTouchBinding binding, SingleTouchBinding other) { int result = 0; if (result == 0) { result = binding.Priority.CompareTo(other.Priority) * -1; } if (result == 0) { result = binding.Identifier.CompareTo(other.Identifier); } return(result); }
/// <summary> /// Adds a binding for the observer if one doesn't exist. /// Modifies existing binding otherwise. /// </summary> /// <param name="observer">The observer to add.</param> /// <param name="priority"> /// The priority of the observer. Observers /// with higher priority will receive touch events before observers with /// lower priority. The default value is zero. /// </param> /// <param name="swallowsTouches"> /// The value indicating if the binding should swallow touches. If the value /// is <c>true</c> and the observer's <see cref="ISingleTouchObserver.OnTouchBegan" /> /// method returns <c>true</c>, other observers with lower priority will not receive any /// events for the touch. /// </param> public void Add(ISingleTouchObserver observer, int priority = 0, bool swallowsTouches = true) { SingleTouchBinding binding; binding = this.GetBinding(observer); if (binding == null) { binding = new SingleTouchBinding(); binding.Observer = observer; binding.Priority = priority; binding.SwallowsTouches = swallowsTouches; this.AddBinding(binding); } else if (binding.Priority != priority || binding.SwallowsTouches != swallowsTouches) { binding.Priority = priority; binding.SwallowsTouches = swallowsTouches; this.Dirty = true; } }
private void RemoveBinding(SingleTouchBinding binding) { if (this.Locked) { if (this.BindingsToAdd.Contains(binding) == true) { this.BindingsToAdd.Remove(binding); } if (this.BindingsToRemove.Contains(binding) == false) { this.BindingsToRemove.Add(binding); } } else { if (this.Bindings.Contains(binding) == true) { this.Bindings.Remove(binding); this.Dirty = true; } } }