コード例 #1
0
		void OnDisposed(object sender, EventArgs e)
		{
			this.component.Disposed -= DisposeHandler;

			if (this.owner != null)
			{
				this.owner.Remove(this);
				this.owner = null;
			}

			//remove from the game components list
			Microsoft.Xna.Framework.GameComponentCollection components = application.XnaComponents;

			for (int i = 0; i < components.Count; i++)
			{
				XnaDrawableGameComponentWrapper wrapper = components[i] as XnaDrawableGameComponentWrapper;
				if ((wrapper != null && wrapper.component == component))
				{
					components.RemoveAt(i);
					break;
				}
			}

			if (UpdateOrderChangedHandler != null)
			{
				this.component.UpdateOrderChanged -= UpdateOrderChangedHandler;
			}

			this.Dispose();
		}
コード例 #2
0
		public XnaDrawableGameComponentWrapper(Microsoft.Xna.Framework.DrawableGameComponent component, Xen.Graphics.DrawTarget owner, Application application)
			: base(component.Game)
		{
			if (owner == null || application == null) throw new ArgumentNullException();

			this.owner = owner;
			this.component = component;
			this.application = application;

			this.component.Initialize();
			this.DisposeHandler = new EventHandler<EventArgs>(OnDisposed);
			this.component.Disposed += DisposeHandler;

			//add this object to the main XNA update list, unless it's already there
			bool addToUpdateList = true;
			Microsoft.Xna.Framework.GameComponentCollection components = application.XnaComponents;

			foreach (Microsoft.Xna.Framework.GameComponent item in components)
			{
				XnaDrawableGameComponentWrapper wrapper = item as XnaDrawableGameComponentWrapper;
				if (item == component || (wrapper != null && wrapper.component == component))
				{
					//already in the list...
					addToUpdateList = false;
					break;
				}
			}

			if (addToUpdateList)
			{
				components.Add(this);

				this.UpdateOrderChangedHandler = new EventHandler<EventArgs>(OnUpdateOrderChangedHandler);
				this.component.UpdateOrderChanged += UpdateOrderChangedHandler;
			}
		}
コード例 #3
0
		public void RemovedFromOwner()
		{
			this.owner = null;
		}