A energy indicator color bar for a floating point value in the range 0 - 100 (i.e. percentage). Includes optional one character label. More...
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. | |
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.
| NewGamePhysics.GraphicalElements.EnergyIndicator.EnergyIndicator | ( | ScreenManager | screenManager, | |
| string | label | |||
| ) |
Create new indicator object for use with autosizing.
| 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 }
| void NewGamePhysics.GraphicalElements.EnergyIndicator.Draw | ( | GameTime | gameTime | ) |
Draws the indicator.
| 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.
| position |
Definition at line 121 of file EnergyIndicator.cs.
| void NewGamePhysics.GraphicalElements.EnergyIndicator.SetValue | ( | double | value | ) |
Sets a new value, but limit range to 0-100.
| value | The value to set. |
Definition at line 100 of file EnergyIndicator.cs.
| const float NewGamePhysics.GraphicalElements.EnergyIndicator.Height = 102.0f |
The height of the indicator in pixels.
Definition at line 28 of file EnergyIndicator.cs.
| const float NewGamePhysics.GraphicalElements.EnergyIndicator.Width = 14.0f |
The width of the indicator in pixels.
Definition at line 23 of file EnergyIndicator.cs.
1.6.2