NewGamePhysics.GraphicalElements.EnergyIndicator Class Reference

A energy indicator color bar for a floating point value in the range 0 - 100 (i.e. percentage). Includes optional one character label. More...

Inheritance diagram for NewGamePhysics.GraphicalElements.EnergyIndicator:
NewGamePhysics.GraphicalElements.GraphicalElementBase

List of all members.

Public Member Functions

 EnergyIndicator (ScreenManager screenManager, string label)
 Create new indicator object for use with autosizing.
void SetValue (double value)
 Sets a new value, but limit range to 0-100.
void SetPosition (Vector2 position)
 Reposition indicator object.
void Draw (GameTime gameTime)
 Draws the indicator.

Public Attributes

const float Width = 14.0f
 The width of the indicator in pixels.
const float Height = 102.0f
 The height of the indicator in pixels.

Detailed Description

A energy indicator color bar for a floating point value in the range 0 - 100 (i.e. percentage). Includes optional one character label.

Definition at line 18 of file EnergyIndicator.cs.


Constructor & Destructor Documentation

NewGamePhysics.GraphicalElements.EnergyIndicator.EnergyIndicator ( ScreenManager  screenManager,
string  label 
)

Create new indicator object for use with autosizing.

Parameters:
screenManager The screen manager to use for drawing the indicator.
label The label of the indicator.

Definition at line 70 of file EnergyIndicator.cs.

00072                           : base(screenManager)
00073         {
00074             // Store settings
00075             this.label = label;
00076 
00077             // Default position and size
00078             this.position = new Vector2();
00079 
00080             // Black hide texture
00081             this.blackTexture = TextureHelpers.Create(screenManager.GraphicsDevice, Color.Black);
00082 
00083             // Colored bar texture
00084             this.barTexture = screenManager.Game.Content.Load<Texture2D>(@"Sprites\energybar");
00085 
00086             // Color for box and font
00087             this.drawColor = new Color(255, 255, 255);
00088 
00089             // The font to use
00090             this.textFont = ScreenManager.Fonts["small"];
00091 
00092             // Now set a default value, set bar color.
00093             this.SetValue(0.0);
00094         }


Member Function Documentation

void NewGamePhysics.GraphicalElements.EnergyIndicator.Draw ( GameTime  gameTime  ) 

Draws the indicator.

Parameters:
gameTime The game time for drawing.

Definition at line 131 of file EnergyIndicator.cs.

00132         {
00133             Rectangle destination;
00134 
00135             // Draw bar
00136             destination = new Rectangle(
00137                 (int)this.position.X, 
00138                 (int)this.position.Y,
00139                 (int)Width,
00140                 (int)Height);
00141             SpriteBatch.Begin();
00142             SpriteBatch.Draw(this.barTexture, destination, Color.White);
00143             SpriteBatch.End();
00144 
00145             // Hide invisible part of bar
00146             int hiddenHeight = (int)((100.0 - this.value) * 0.01 * (double)Height); 
00147             destination = new Rectangle(
00148                 (int)this.position.X, 
00149                 (int)this.position.Y, 
00150                 (int)Width, 
00151                 (int)hiddenHeight);
00152             SpriteBatch.Begin();
00153             SpriteBatch.Draw(this.blackTexture, destination, Color.DarkSlateGray);
00154             SpriteBatch.End();
00155 
00156             // Lines
00157             PrimitiveBatch.Begin(PrimitiveType.LineList);
00158 
00159             // Box
00160             PrimitiveBatch.AddVertex(this.position, this.drawColor);
00161             PrimitiveBatch.AddVertex(this.position + new Vector2(Width, 0.0f), this.drawColor);
00162 
00163             PrimitiveBatch.AddVertex(this.position + new Vector2(Width, 0.0f), this.drawColor);
00164             PrimitiveBatch.AddVertex(this.position + new Vector2(Width, Height), this.drawColor);
00165 
00166             PrimitiveBatch.AddVertex(this.position + new Vector2(Width, Height), this.drawColor);
00167             PrimitiveBatch.AddVertex(this.position + new Vector2(0.0f, Height), this.drawColor);
00168 
00169             PrimitiveBatch.AddVertex(this.position + new Vector2(0.0f, Height), this.drawColor);
00170             PrimitiveBatch.AddVertex(this.position, this.drawColor);
00171 
00172             PrimitiveBatch.End();
00173 
00174             // Label (sits on top of visible area)
00175             if (!String.IsNullOrEmpty(this.label))
00176             {
00177                 float ySpacing = 2.0f;
00178                 Vector2 textSize = this.textFont.MeasureString(this.label);
00179                 int visibleHeight = (int)(this.value * 0.01 * (double)Height);
00180                 Vector2 textPosition = new Vector2();
00181                 textPosition.X = this.position.X + (Width - textSize.X) / 2;
00182                 float delta = ySpacing + visibleHeight + textSize.Y;
00183                 if (delta > (Height - ySpacing))
00184                 {
00185                     textPosition.Y = this.position.Y + ySpacing;
00186                 }
00187                 else
00188                 {
00189                     textPosition.Y = this.position.Y + Height - delta;
00190                 }
00191 
00192                 SpriteBatch.Begin();
00193                 SpriteBatch.DrawString(
00194                     this.textFont,
00195                     this.label,
00196                     textPosition,
00197                     this.drawColor, 0, new Vector2(), 1.0f,
00198                     SpriteEffects.None, 0);
00199                 SpriteBatch.End();
00200             }
00201         }

void NewGamePhysics.GraphicalElements.EnergyIndicator.SetPosition ( Vector2  position  ) 

Reposition indicator object.

Parameters:
position 

Definition at line 121 of file EnergyIndicator.cs.

00122         {
00123             this.position.X = position.X;
00124             this.position.Y = position.Y;
00125         }

void NewGamePhysics.GraphicalElements.EnergyIndicator.SetValue ( double  value  ) 

Sets a new value, but limit range to 0-100.

Parameters:
value The value to set.

Definition at line 100 of file EnergyIndicator.cs.

00101         {
00102             // Set value but limit range
00103             if (value < 0.0)
00104             {
00105                 this.value = 0.0;
00106             }
00107             else if (value > 100.0)
00108             {
00109                 this.value = 100.0;
00110             }
00111             else
00112             {
00113                 this.value = value;
00114             }
00115         }


Member Data Documentation

The height of the indicator in pixels.

Definition at line 28 of file EnergyIndicator.cs.

The width of the indicator in pixels.

Definition at line 23 of file EnergyIndicator.cs.


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2