#region Copyright /* -------------------------------------------------------------------------------- This source file is part of Xenocide by Project Xenocide Team For the latest info on Xenocide, see http://www.projectxenocide.com/ This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA. -------------------------------------------------------------------------------- */ /* * @file Screen.cs * @date Created: 2007/01/20 * @author File creator: dteviot * @author Credits: none */ #endregion #region Using Statements using System; using System.Collections.Generic; using System.Text; using System.Drawing; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using CeGui; using CeGui.Renderers.Xna; #endregion namespace ProjectXenocide.UI.Screens { /// /// This is the base class that all screens derive from /// A "screen" is a window that fills the entire display /// The screen is responsible for: /// 1. Creating the CeGeui widgets on the display /// 2. Handing events from the widgets /// 3. Managing the 3D scene (if there is one) on the screen /// 4. Pumping Update() and Draw() to scene and game's model /// Because the CeGui widgets are XNA Components /// the Screen class does NOT pump Update() and Draw() to the widgets /// themselves. That's done by the XNA framework /// public abstract class Screen : Frame { /// /// Constructor (obviously) /// /// CeGui's identifer for this screen /// Name of the file holding the window's background protected Screen(string ceguiId, String backgroundFilename) : base(ceguiId, new System.Drawing.SizeF(1.0f, 1.0f)) { this.backgroundFilename = backgroundFilename; } /// /// Constructor (obviously) /// /// CeGui's identifer for this screen protected Screen(string ceguiId) : this(ceguiId, @"Content\Textures\UI\GeoscapeScreenBackground.png") { } /// /// Update any model data /// /// Provides a snapshot of timing values. public virtual void Update(GameTime gameTime) { } /// /// Render the 3D scene /// /// Provides a snapshot of timing values. /// To use for drawing (obviously) public virtual void Draw(GameTime gameTime, GraphicsDevice device) { } /// /// Construct the widget that will be the parent for all widgets on this screen /// /// the widget protected override CeGui.Window ConstructRootWidget() { CeGui.Widgets.StaticImage imageWidget = GuiBuilder.CreateImage(CeguiId); LoadBackgroundImage(imageWidget); return imageWidget; } /// /// Load the background image into the Screen's root widget /// /// the screen's root widget private void LoadBackgroundImage(CeGui.Widgets.StaticImage imageWidget) { // load background image for window if (!String.IsNullOrEmpty(backgroundFilename)) { // if image not already loaded, load it Imageset imageset = null; if (!ImagesetManager.Instance.IsImagesetPresent(backgroundFilename)) { CeGui.Texture texture = GuiSystem.Instance.Renderer.CreateTexture(); texture.LoadFromFile(backgroundFilename); imageset = ImagesetManager.Instance.CreateImageset(backgroundFilename, texture); Rect imagesize = new Rect(0.0f, 0.0f, texture.Width, texture.Height); imageset.DefineImage(backgroundFilename, imagesize, new PointF(0.0f, 0.0f)); } else { imageset = ImagesetManager.Instance.GetImageset(backgroundFilename); } // Set to window's background imageWidget.Image = imageset.GetImage(backgroundFilename); } } #region Fields // name of file holding the image that makes up the background of this window private String backgroundFilename; #endregion Fields } }