NewGamePhysics.GraphicalElements.InfoMessages Class Reference

Display (fy line-by-line fade) a collection of info messages. More...

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

List of all members.

Public Member Functions

 InfoMessages (ScreenManager manager, List< string > messages, Vector2 origin)
 Create an info-message display object at the specified location. Font defaults to the 'game' font. Color defaults to 'white'.
void Update (GameTime gameTime)
 Updates the state of the message list display.
void Draw (GameTime gameTime)
 Draws the tes message lines onto screen.

Properties

SpriteFont Font [get, set]
 Gets or sets the text font.
Color Color [get, set]
 Gets or sets the text color.
Vector2 MessagesOrigin [get, set]
 Gets or sets the origin of the messages.
InfoMessageAlignment Alignment [get, set]
 Gets or sets the alignment of the rows in the text block.
float Scale [get, set]
 Gets or sets the text scale.

Detailed Description

Display (fy line-by-line fade) a collection of info messages.

Definition at line 41 of file InfoMessages.cs.


Constructor & Destructor Documentation

NewGamePhysics.GraphicalElements.InfoMessages.InfoMessages ( ScreenManager  manager,
List< string >  messages,
Vector2  origin 
)

Create an info-message display object at the specified location. Font defaults to the 'game' font. Color defaults to 'white'.

Parameters:
screenManager The screen manager to use.
messages The messages to display.
origin Upper right corner where messages are displayed.

Definition at line 100 of file InfoMessages.cs.

00103                             : base(manager)
00104         {
00105             if (null == messages)
00106             {
00107                 throw new ArgumentNullException(
00108                     "messages", 
00109                     "List of messages cannot be null");
00110             }
00111 
00112             if (null == origin)
00113             {
00114                 throw new ArgumentNullException(
00115                     "origin", 
00116                     "Text origin cannot be null");
00117             }
00118 
00119             if (0 == messages.Count)
00120             {
00121                 throw new ArgumentOutOfRangeException(
00122                     "messages", 
00123                     "Message List cannot be empty");
00124             }
00125 
00126             // Remember messages and origin
00127             this.messages = messages;
00128             this.messagesOrigin = origin;
00129 
00130             // Reset text fader state
00131             this.numRows = messages.Count;
00132             this.currentRow = 0;
00133             this.textAlpha = new float[this.numRows];
00134             for (int i = 0; i < this.numRows; i++)
00135             {
00136                 this.textAlpha[i] = 0.0f;
00137             }
00138 
00139             // Initialize a font
00140             this.font = this.ScreenManager.Fonts["game"];
00141 
00142             // Initialize the color
00143             Color color = Color.White;
00144         }


Member Function Documentation

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

Draws the tes message lines onto screen.

Parameters:
gameTime Current game time.

Definition at line 214 of file InfoMessages.cs.

00215         {            
00216             Vector2 lineOrigin = new Vector2(0, 0);
00217             Vector2 linePosition = this.messagesOrigin;
00218             Vector2 textPosition;
00219             this.SpriteBatch.Begin();
00220             for (int i = 0; i < numRows; i++)
00221             {
00222                 // Current message
00223                 string message = messages[i];
00224 
00225                 // Align
00226                 textPosition = linePosition;
00227                 Vector2 textSize = font.MeasureString(message) * this.scale;
00228                 switch (this.alignment)
00229                 {
00230                     case InfoMessageAlignment.Left:
00231                         // already aligned
00232                         break;
00233                     case InfoMessageAlignment.Center:
00234                         textPosition.Y -= (font.LineSpacing / 2);
00235                         textPosition.X -= (textSize.X / 2);
00236                         break;
00237                     case InfoMessageAlignment.Right:
00238                         textPosition.X -= textSize.X;
00239                         break;
00240                 }
00241 
00242                 if (textAlpha[i] > 0.0f)
00243                 {
00244                     if (string.IsNullOrEmpty(message))
00245                     {
00246                         // Spacer
00247                         linePosition.Y += ((float)font.LineSpacing * 0.5f * this.scale);
00248                     }
00249                     else
00250                     {
00251                         // Textline
00252                         color = new Color(
00253                             Color.White, 
00254                             MathHelper.SmoothStep(0.0f, 1.0f, textAlpha[i]));
00255                         this.SpriteBatch.DrawString(
00256                             font,
00257                             message,
00258                             textPosition,
00259                             color,
00260                             0,
00261                             lineOrigin,
00262                             this.scale,
00263                             SpriteEffects.None,
00264                             0);
00265                         linePosition.Y += ((float)font.LineSpacing * 1.2f * this.scale);
00266                     }
00267                 }
00268             }
00269             this.SpriteBatch.End();
00270         }

void NewGamePhysics.GraphicalElements.InfoMessages.Update ( GameTime  gameTime  ) 

Updates the state of the message list display.

Parameters:
gameTime The current game time.

Definition at line 195 of file InfoMessages.cs.

00196         {
00197             // Fade logic
00198             if (this.currentRow < this.numRows)
00199             {
00200                 this.textAlpha[this.currentRow] += this.fadeSpeed;
00201                 if (string.IsNullOrEmpty(this.messages[this.currentRow]) ||
00202                    (this.textAlpha[this.currentRow] >= 1.0f))
00203                 {
00204                     this.textAlpha[this.currentRow] = 1.0f;
00205                     this.currentRow++;
00206                 }
00207             }
00208         }


Property Documentation

InfoMessageAlignment NewGamePhysics.GraphicalElements.InfoMessages.Alignment [get, set]

Gets or sets the alignment of the rows in the text block.

Definition at line 177 of file InfoMessages.cs.

Color NewGamePhysics.GraphicalElements.InfoMessages.Color [get, set]

Gets or sets the text color.

Definition at line 159 of file InfoMessages.cs.

SpriteFont NewGamePhysics.GraphicalElements.InfoMessages.Font [get, set]

Gets or sets the text font.

Definition at line 150 of file InfoMessages.cs.

Vector2 NewGamePhysics.GraphicalElements.InfoMessages.MessagesOrigin [get, set]

Gets or sets the origin of the messages.

Definition at line 168 of file InfoMessages.cs.

float NewGamePhysics.GraphicalElements.InfoMessages.Scale [get, set]

Gets or sets the text scale.

Definition at line 186 of file InfoMessages.cs.


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

Generated by  doxygen 1.6.2