NewGamePhysics.GraphicalElements.ValueIndicator Class Reference

A value indicator box for a floating point value. Displays a formatted value, optionally a bar graph in a minimum/maximum range, and optionally a color change of the bar graph for low/high setting. More...

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

List of all members.

Public Member Functions

 ValueIndicator (ScreenManager manager, string label, string format)
 Create new indicator object for use with autosizing.
 ValueIndicator (ScreenManager manager, string label, string format, double minimum, double maximum)
 Create new indicator object with fixed value range.
void SetValue (double value)
 Sets a new value and autoupdates min/max + low/high values.
void SetValueInRange (double value)
 Sets a new value within the currently defined min/max range. The value is clipped to the current min or max if out of bounds.
void SetMinimum (double value)
 Sets the minimum.
void SetMaximum (double value)
 Sets the maximum.
void SetPosition (Vector2 position)
 Reposition indicator object.
void Draw (GameTime gameTime)
 Draws the indicator.

Public Attributes

const float Width = 200.0f
 The width of the indicator in pixels.
const float Height = 40.0f
 The height of the indicator in pixels.

Properties

double MinimumValue = Sprites\value_gauge" [get, set]
 Gets or sets the minimum value for the bar indicator.
double MaximumValue [get, set]
 Gets or sets the maximum value for the bar indicator.
double LowValue [get, set]
 Gets or sets the low value for the bar indicator when the color changes.
double HighValue [get, set]
 Gets or sets the high value for the bar indicator when the color changes.
bool LowHighColoring [get, set]
 Gets or sets flag indicating of low/high coloring is done.
double UpdateInterval [get, set]
 Gets or sets the minimum time in milliseconds between value updates. Default: 250 (quarter second).

Detailed Description

A value indicator box for a floating point value. Displays a formatted value, optionally a bar graph in a minimum/maximum range, and optionally a color change of the bar graph for low/high setting.

Definition at line 20 of file ValueIndicator.cs.


Constructor & Destructor Documentation

NewGamePhysics.GraphicalElements.ValueIndicator.ValueIndicator ( ScreenManager  manager,
string  label,
string  format 
)

Create new indicator object for use with autosizing.

Parameters:
manager The screen manager to use for drawing the indicator.
label The label of the indicator.
format The numeric format string to use to convert the number for display.

Definition at line 144 of file ValueIndicator.cs.

00148             : this(manager, label, format, 0.0, 0.0)
00149         {
00150         }

NewGamePhysics.GraphicalElements.ValueIndicator.ValueIndicator ( ScreenManager  manager,
string  label,
string  format,
double  minimum,
double  maximum 
)

Create new indicator object with fixed value range.

Parameters:
manager The screen manager to use for display.
label The label of the indicator.
format The display to use for the value.
minimum The minimum value of the indicator.
maximum The maximum value of the indicator.

Definition at line 160 of file ValueIndicator.cs.

00165                             : base(manager)
00166         {
00167             // Store settings
00168             this.label = label;
00169             this.format = format;
00170 
00171             // Reset ranges
00172             this.minimumValue = minimum;
00173             this.maximumValue = maximum;
00174             double delta = 0.1 * (maximum - minimum);
00175             this.lowValue = minimum + delta;
00176             this.highValue = maximum - delta;
00177 
00178             // Update flag
00179             this.haveZero = ((this.minimumValue < 0.0) && (this.maximumValue > 0.0));
00180 
00181             // Default position and size
00182             this.position = new Vector2();
00183 
00184             // Color for numbers
00185             this.drawColor = new Color(180, 255, 180);
00186 
00187             // Bar indicator colors
00188             this.barColors = new Color[3];
00189             // red
00190             this.barColors[0] = new Color(255, 0, 0);
00191             // yellow
00192             this.barColors[1] = new Color(255, 255, 0);
00193             // green
00194             this.barColors[2] = new Color(0, 255, 0);
00195 
00196             // Guage backdrop texture
00197             this.backgroundTexture = ScreenManager.Game.Content.Load<Texture2D>(@"Sprites\value_gauge");
00198 
00199             // White indicator texture
00200             this.whiteTexture = TextureHelpers.Create(ScreenManager.GraphicsDevice, Color.White);
00201 
00202             // Now set a default value, set bar color.
00203             this.SetValue(0.0);
00204 
00205             // Label font
00206             this.spriteFont = ScreenManager.Fonts["small"];
00207         }


Member Function Documentation

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

Draws the indicator.

Parameters:
primitiveBatch The primitive batch to use for drawing the lines.
dotColor The color for the dots.

Definition at line 399 of file ValueIndicator.cs.

00400         {
00401             float outerHeight = Height;
00402             float innerHeightStep = 12.0f;
00403             float innerHeight = 3.0f * innerHeightStep;
00404 
00405             float outerWidth = Width;
00406             float innerWidth = Width - 4.0f;
00407             float rowOffsetX = 2.0f;
00408             float row1OffsetY = 2.0f;
00409             float row2OffsetY = 2.0f + innerHeightStep;
00410             float row3OffsetY = 2.0f + 2.0f*innerHeightStep;
00411             float rowHeight = 10.0f;
00412             float valueOffset = innerWidth * (float)((this.value - this.minimumValue) / (this.maximumValue - this.minimumValue));
00413             float zeroOffset = innerWidth * (float)((0.0 - this.minimumValue) / (this.maximumValue - this.minimumValue));
00414 
00415             Rectangle destination;
00416 
00417             // Prepare value string
00418             DateTime currentDate = DateTime.Now;
00419             TimeSpan elapsedSpan = new TimeSpan(currentDate.Ticks - valueUpdate.Ticks);
00420             if (elapsedSpan.TotalMilliseconds > this.updateInterval)
00421             {
00422                 valueAsString = String.Format(
00423                     this.format,
00424                     this.value);
00425                 valueUpdate = currentDate;
00426             }
00427 
00428             // Backdrop of gauge
00429             destination = new Rectangle((int)this.position.X, (int)this.position.Y, (int)outerWidth, (int)outerHeight);
00430             SpriteBatch.Begin();
00431             SpriteBatch.Draw(this.backgroundTexture, destination, Color.White);
00432             SpriteBatch.End();            
00433 
00434             // Row 1: value + unit
00435             Vector2 textSize = spriteFont.MeasureString(valueAsString);
00436             SpriteBatch.Begin();
00437             SpriteBatch.DrawString(
00438                 spriteFont, 
00439                 valueAsString,
00440                 new Vector2(this.position.X + rowOffsetX, this.position.Y + row1OffsetY),
00441                 this.drawColor, 0, new Vector2(), 1.0f,
00442                 SpriteEffects.None, 0);
00443             SpriteBatch.End();
00444 
00445             // Row 2: Bar indicator
00446             if ((this.haveZero) && (valueOffset < zeroOffset))
00447             {
00448                 destination = new Rectangle((int)(this.position.X + rowOffsetX + valueOffset), (int)(this.position.Y + row2OffsetY) + 1, (int)(zeroOffset - valueOffset), (int)rowHeight - 1);
00449             }
00450             else
00451             {
00452                 destination = new Rectangle((int)(this.position.X + rowOffsetX + zeroOffset),  (int)(this.position.Y + row2OffsetY) + 1, (int)(valueOffset - zeroOffset), (int)rowHeight - 1);
00453             }
00454             SpriteBatch.Begin();
00455             SpriteBatch.Draw(this.whiteTexture, destination, this.barColor);
00456             SpriteBatch.End();
00457 
00458             // Lines
00459             PrimitiveBatch.Begin(PrimitiveType.LineList);
00460             Vector2 offset = new Vector2(rowOffsetX, row2OffsetY);
00461 
00462             // Zero
00463             if (this.haveZero)
00464             {
00465                 Color lineColor = new Color(this.drawColor, 128);
00466                 PrimitiveBatch.AddVertex(this.position + offset + new Vector2(zeroOffset, 0.0f), lineColor);
00467                 PrimitiveBatch.AddVertex(this.position + offset + new Vector2(zeroOffset, rowHeight), lineColor);
00468             }
00469 
00470             // Value
00471             PrimitiveBatch.AddVertex(this.position + offset + new Vector2(valueOffset, 0.0f), this.drawColor);
00472             PrimitiveBatch.AddVertex(this.position + offset + new Vector2(valueOffset, rowHeight), this.drawColor);
00473 
00474             PrimitiveBatch.End();
00475 
00476             // Label
00477             if (!String.IsNullOrEmpty(this.label))
00478             {
00479                 textSize = spriteFont.MeasureString(this.label);
00480                 float textOffset = (innerWidth - textSize.X) * 0.5f;
00481                 SpriteBatch.Begin();
00482                 SpriteBatch.DrawString(
00483                     spriteFont,
00484                     this.label,
00485                     new Vector2(this.position.X + rowOffsetX + textOffset, this.position.Y + row3OffsetY),
00486                     Color.Black, 0, new Vector2(), 1.0f,
00487                     SpriteEffects.None, 0);
00488                 SpriteBatch.End();
00489             }
00490         }

void NewGamePhysics.GraphicalElements.ValueIndicator.SetMaximum ( double  value  ) 

Sets the maximum.

Parameters:
value New maximum.

Definition at line 379 of file ValueIndicator.cs.

00380         {
00381             this.maximumValue = value;
00382         }

void NewGamePhysics.GraphicalElements.ValueIndicator.SetMinimum ( double  value  ) 

Sets the minimum.

Parameters:
value New minimum.

Definition at line 370 of file ValueIndicator.cs.

00371         {
00372             this.minimumValue = value;
00373         }

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

Reposition indicator object.

Parameters:
position 

Definition at line 388 of file ValueIndicator.cs.

00389         {
00390             this.position.X = position.X;
00391             this.position.Y = position.Y;
00392         }

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

Sets a new value and autoupdates min/max + low/high values.

Parameters:
value The value to set.

Definition at line 325 of file ValueIndicator.cs.

00326         {
00327             // Recalculate min and max
00328             this.MinimumValue = Math.Min(this.minimumValue, Autorange.GetSnapValue(value, false));
00329             this.MaximumValue = Math.Max(this.maximumValue, Autorange.GetSnapValue(value, true));
00330 
00331             // Use 10% for low/high ranges
00332             double delta = 0.1 * (this.maximumValue - this.minimumValue);
00333             this.LowValue = this.minimumValue + delta;
00334             this.HighValue = this.maximumValue - delta;
00335 
00336             // Set value
00337             this.value = value;
00338             UpdateBarColor();
00339         }

void NewGamePhysics.GraphicalElements.ValueIndicator.SetValueInRange ( double  value  ) 

Sets a new value within the currently defined min/max range. The value is clipped to the current min or max if out of bounds.

Parameters:
value The value to set.

Definition at line 347 of file ValueIndicator.cs.

00348         {
00349             // Set value, but keep it in range
00350             if (value < minimumValue)
00351             {
00352                 this.value = this.minimumValue;
00353             }
00354             else if (value > maximumValue)
00355             {
00356                 this.value = this.maximumValue;
00357             }
00358             else
00359             {
00360                 this.value = value;
00361             }
00362 
00363             UpdateBarColor();
00364         }


Member Data Documentation

The height of the indicator in pixels.

Definition at line 86 of file ValueIndicator.cs.

The width of the indicator in pixels.

Definition at line 81 of file ValueIndicator.cs.


Property Documentation

double NewGamePhysics.GraphicalElements.ValueIndicator.HighValue [get, set]

Gets or sets the high value for the bar indicator when the color changes.

Definition at line 285 of file ValueIndicator.cs.

bool NewGamePhysics.GraphicalElements.ValueIndicator.LowHighColoring [get, set]

Gets or sets flag indicating of low/high coloring is done.

Definition at line 303 of file ValueIndicator.cs.

double NewGamePhysics.GraphicalElements.ValueIndicator.LowValue [get, set]

Gets or sets the low value for the bar indicator when the color changes.

Definition at line 266 of file ValueIndicator.cs.

double NewGamePhysics.GraphicalElements.ValueIndicator.MaximumValue [get, set]

Gets or sets the maximum value for the bar indicator.

Definition at line 240 of file ValueIndicator.cs.

double NewGamePhysics.GraphicalElements.ValueIndicator.MinimumValue = Sprites\value_gauge" [get, set]

Gets or sets the minimum value for the bar indicator.

Definition at line 215 of file ValueIndicator.cs.

double NewGamePhysics.GraphicalElements.ValueIndicator.UpdateInterval [get, set]

Gets or sets the minimum time in milliseconds between value updates. Default: 250 (quarter second).

Definition at line 313 of file ValueIndicator.cs.


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

Generated by  doxygen 1.6.2