using System;
using System.Drawing;
using Microsoft.DirectX.DirectDraw;
using DebugGlobal.Debug;
using Global.GlobalClass;
using KillerInstinct.DirectX;
namespace KillerInstinct{
public class ProgressBarClass
{
private int m_range;
private int m_currentValue;
private int m_width;
private int m_height;
private Color m_borderColor;
private Color m_barColor;
private Color m_backColor;
// this controls how much of the progress bar is filled in
public int CurrentValue
{
set
{ m_currentValue = value; }
}
public Color BarColor
{
get
{ return m_barColor; }
}
// allow maximum (range) to be changed
public int Max
{
set
{ m_range = value; }
}
public ProgressBarClass(int width, int height, int curValue, int range, Color borderColor, Color barColor, Color backColor)
{
global.dbg.Out(Debug.DBG2, "ProgressBarClass called, width=[" + width + "] height=[" + height + "] curVal=[" + curValue + "] range=[" + range + "] borderColor=[" + borderColor + "] barColor=[" + barColor + "] backColor=[" + backColor + "]");
m_borderColor = borderColor; // progress bar's color
m_barColor = barColor; // color of how much of the bar is filled (background)
m_backColor = backColor; // behind bar color
m_currentValue = curValue; // current position in the progress bar
m_range = range; // maximum range of this progress bar
m_width = width; // width (in pixels) of bar
m_height = height; // height (in pixels) of bar
if (range <= 0)
global.dbg.Out(Debug.ERR, "ProgressBarClass range is invalid [" + range + "].");
}
public void Draw(int x, int y, int curValue)
{
Draw(x, y, curValue, Color.Empty);
}
public void Draw(int x, int y, int curValue, Color barColor)
{
if (m_range <= 0)
{
global.dbg.Out(Debug.ERR, "ProgressBarClass.Draw:: range is invalid [" + m_range + "].");
return;
}
try
{
Color drawColor = barColor;
// don't allow to over-step maximum value
if (curValue <= m_range)
{
// if a color was NOT specified, use the default set in constructor
if (barColor == Color.Empty)
drawColor = m_barColor;
m_currentValue = curValue;
// right, // bottom //rw, //rh
//dest.DrawRoundedBox(m_x, m_y, m_x+30, m_y+10, 0, 0);
// draw entire progress bar (empty)
global.DC.DrawBox(x, y, m_width, m_height, m_borderColor, m_backColor);
// draw filled in portion of the bar
// curVal(60) / range(100) = 0.67 * 100 = diff(67) x width(50) = 3350 / 100 = 33.5
float diff = (m_currentValue*100) / m_range;
float width = (diff * (m_width-1)) / 100;
// only draw if something to draw
if ((int)width > 1)
global.DC.DrawBox(x+1, y+1, (int)width, m_height-2, drawColor, drawColor);
}
}
catch( Exception e )
{
global.dbg.Out(Debug.ERR, "ProgressBarClass.Draw exception: " + e);
}
}
}
}
|