Esempio n. 1
0
        /// <summary>
        /// Sets the position relative to object.
        /// </summary>
        /// <param name="objectBound">Object bound.</param>
        /// <param name="offset">Offset.</param>
        public void SetPositionRelativeToObject(IDraw objectBound, Vector2 offset, bool followBound = true)
        {
            PositionMode      = PositionType.ObjectRelative;
            ObjectBoundOffset = offset;

            // I put it here to have to the movement code at the same place.
            if (MoveEvent == null)
            {
                MoveEvent = (Bound) => {
                    // Replace the current IDraw.
                    Position = Vector2.Add(offset, Bound.Position);
                };
            }

            // If there is currently no bound, it can simply add everyting.
            if (ObjectBound == null)
            {
                ObjectBound = objectBound;
                if (followBound)
                {
                    objectBound.Moved += MoveEvent;
                }
            }
            // If it is a new bound, remove old event handler.
            else if (ObjectBound != objectBound)
            {
                if (followBound)
                {
                    ObjectBound.Moved -= MoveEvent;
                }
                ObjectBound = objectBound;
                if (followBound)
                {
                    objectBound.Moved += MoveEvent;
                }
            }

            MoveEvent(objectBound);
        }
Esempio n. 2
0
		/// <summary>
		/// Adds the child with a specified z-index.
		/// </summary>
		/// <param name="child">Child.</param>
		/// <param name="z">The z coordinate.</param>
		public virtual void AddChild(IDraw child, int z)
		{
			Debug.Assert(child != null);

			if(child.Parent == null)
			{
				if (Content != null) {
					child.Load(this, GetGraphics());
				}
				child.Z=z;
				int index = Children.FindLastIndex(c => child.Z > c.Z);
				if(index == -1)
				{
					index = Children.FindLastIndex(c => child.Z == c.Z);
				}

				++index;

				Children.Insert(Children.Count == 0 ? 0 : index, child);
			}
			else
				throw new Exception("The IDraw is already in a container");
		}
Esempio n. 3
0
 /// <summary>
 /// Adds the child with a default z-index of 0.
 /// </summary>
 /// <param name="child">Child.</param>
 public virtual void AddChild(IDraw child)
 {
     AddChild(child, 1);
 }
Esempio n. 4
0
		/// <summary>
		/// Removes the specified child.
		/// </summary>
		/// <param name="child">Child.</param>
		public void RemoveChild(IDraw child)
		{
			if (child != null) {
				toRemove.Add(child);
			}
		}
Esempio n. 5
0
		/// <summary>
		/// Adds the child with a default z-index of 0.
		/// </summary>
		/// <param name="child">Child.</param>
		public virtual void AddChild(IDraw child)
		{
			AddChild(child, 1);
		}
Esempio n. 6
0
		/// <summary>
		/// Sets the position relative to object.
		/// </summary>
		/// <param name="objectBound">Object bound.</param>
		/// <param name="offset">Offset.</param>
		public void SetPositionRelativeToObject(IDraw objectBound, Vector2 offset, bool followBound = true)
		{
			PositionMode = PositionType.ObjectRelative;
			ObjectBoundOffset = offset;

			// I put it here to have to the movement code at the same place.
			if (MoveEvent == null) {
				MoveEvent = (Bound) => {
					// Replace the current IDraw.
					Position = Vector2.Add(offset,Bound.Position);
				};
			}

			// If there is currently no bound, it can simply add everyting.
			if (ObjectBound == null) {
				ObjectBound = objectBound;
				if (followBound) {
					objectBound.Moved += MoveEvent;
				}
			} 
			// If it is a new bound, remove old event handler.
			else if (ObjectBound != objectBound) {
				if (followBound) {
					ObjectBound.Moved -= MoveEvent;
				}
				ObjectBound = objectBound;
				if (followBound) {
					objectBound.Moved += MoveEvent;
				}
			}

			MoveEvent(objectBound);
		}