/*
* FillBarMenuItem.cs
* Authors:
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace tAC_Engine.ScreenStates
{
///
/// Represents a menu item with a fill bar.
///
public class FillBarMenuItem : MenuItem
{
#region Fields
///
/// The percent the current bar is filled.
///
protected float m_PercentFilled;
#endregion
#region Properties
///
/// Gets/Sets the percent the current bar is filled.
///
public float PercentFilled
{
get { return m_PercentFilled; }
set { m_PercentFilled = value; }
}
#endregion
#region Constructs
///
/// Vreate the new fill bar menu item.
///
/// The text for the item.
/// The position of the item.
/// The startup percentage filled.
public FillBarMenuItem(string p_Text, Vector2 p_Position, float p_PercentFilled)
: base(p_Text, p_Position)
{
// Set the startup percent filled
m_PercentFilled = p_PercentFilled;
}
#endregion
#region Draw
///
/// Draw's the given menu item.
///
/// The sprite batch to draw with.
/// The font to use for the drawing.
/// The texture for the background of the bar
/// The texture for filling the bar
[Obsolete("Texture2Ds should not be passed into constructors to be displayed.")]
public void Draw(SpriteBatch p_SpriteBatch, SpriteFont p_SpriteFont,
Texture2D p_BackTexture, Texture2D p_FillTexture)
{
// Begin drawing
p_SpriteBatch.Begin();
// Draw the text for the texture
p_SpriteBatch.DrawString(p_SpriteFont, m_Text, m_Position, m_DrawColor);
// Get the length of the string in the font
Vector2 stringSize = p_SpriteFont.MeasureString(m_Text);
stringSize += p_SpriteFont.MeasureString("A");
stringSize.Y = 0;
// Now use the size to place the bacxk texture bar
p_SpriteBatch.Draw(p_BackTexture, m_Position + stringSize, Color.White);
// Now draw the filled texture
p_SpriteBatch.Draw(p_FillTexture, m_Position + stringSize,
null, Color.White, 0.0f, Vector2.Zero, new Vector2(m_PercentFilled, 1),
SpriteEffects.None, 0.0f);
p_SpriteBatch.End();
}
#endregion
}
}