#region CPL License /* Nuclex Framework Copyright (C) 2002-2011 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using DeviceEventHandler = System.EventHandler; namespace Nuclex.Game { /// /// Lightweight variant DrawableGameComponent that doesn't reference the Game class /// /// /// /// This is a lightweight version of DrawableGameComponent that can be used /// without requiring a Game class to be present. Useful to get all the /// advantages of the XNA GameServices architecture even when you have /// initialized and manage the graphics device yourself. /// /// /// The name of this class is the same as 'DrawableGameComponent' minus the /// 'Game' part as the Game reference is what this class removes from its namesake. /// /// public class DrawableComponent : Component, IDrawable { /// Triggered when the value of the draw order property is changed. public event DeviceEventHandler DrawOrderChanged; /// Triggered when the value of the visible property is changed. public event DeviceEventHandler VisibleChanged; /// Initializes a new drawable component. public DrawableComponent() { this.visible = true; } /// Called when the drawable component needs to draw itself /// Provides a snapshot of the game's timing values public virtual void Draw(GameTime gameTime) { } /// /// Indicates when the drawable component should be drawn in relation to other /// drawables. Has no effect by itself. /// public int DrawOrder { get { return this.drawOrder; } set { if (value != this.drawOrder) { this.drawOrder = value; OnDrawOrderChanged(); } } } /// True when the drawable component is visible and should be drawn. public bool Visible { get { return this.visible; } set { if (value != this.visible) { this.visible = value; OnVisibleChanged(); } } } /// Fires the DrawOrderChanged event protected virtual void OnDrawOrderChanged() { if (this.DrawOrderChanged != null) { this.DrawOrderChanged(this, EventArgs.Empty); } } /// Fires the VisibleChanged event protected virtual void OnVisibleChanged() { if (this.VisibleChanged != null) { this.VisibleChanged(this, EventArgs.Empty); } } /// /// Used to determine the drawing order of this object in relation to other /// objects in the same list. /// private int drawOrder; /// Whether this object is visible (and should thus be drawn) private bool visible; } } // namespace Nuclex.Graphics