NewGamePhysics.StateManager.MenuEntry Class Reference

Helper class represents a single entry in a MenuScreen. By default this just draws the entry text string, but it can be customized to display menu entries in different ways. This also provides an event that will be raised when the menu entry is selected. More...

List of all members.

Public Member Functions

 MenuEntry (string text)
 Constructs a new menu entry with the specified text.
virtual void Update (MenuScreen screen, bool isSelected, GameTime gameTime)
 Updates the menu entry.
virtual void Draw (MenuScreen screen, Vector2 position, bool isSelected, GameTime gameTime)
 Draws the menu entry. This can be overridden to customize the appearance.
virtual int GetHeight (MenuScreen screen)
 Queries how much space this menu entry requires.

Protected Member Functions

virtual internal void OnSelectEntry (PlayerIndex playerIndex)
 Method for raising the Selected event.

Properties

string Text [get, set]
 Gets or sets the text of this menu entry.

Events

EventHandler
< PlayerIndexEventArgs
Selected
 Event raised when the menu entry is selected.

Detailed Description

Helper class represents a single entry in a MenuScreen. By default this just draws the entry text string, but it can be customized to display menu entries in different ways. This also provides an event that will be raised when the menu entry is selected.

Definition at line 19 of file MenuEntry.cs.


Constructor & Destructor Documentation

NewGamePhysics.StateManager.MenuEntry.MenuEntry ( string  text  ) 

Constructs a new menu entry with the specified text.

Definition at line 83 of file MenuEntry.cs.

00084         {
00085             this.text = text;
00086         }


Member Function Documentation

virtual void NewGamePhysics.StateManager.MenuEntry.Draw ( MenuScreen  screen,
Vector2  position,
bool  isSelected,
GameTime  gameTime 
) [virtual]

Draws the menu entry. This can be overridden to customize the appearance.

Definition at line 119 of file MenuEntry.cs.

00121         {
00122             // Pulsate the size of the selected menu entry.
00123             double time = gameTime.TotalGameTime.TotalSeconds;
00124             
00125             float pulsate = (float)Math.Sin(time * 6) + 1;
00126             
00127             float scale = 1 + pulsate * 0.05f * selectionFade;
00128 
00129             // Draw the selected entry in yellow, otherwise white.
00130             Color textColor = isSelected ? Color.Yellow : Color.White;
00131             Color paneColor = isSelected ? Color.Yellow : Color.White;
00132 
00133             // Modify the alpha to fade text out during transitions.
00134             textColor = new Color(
00135                 textColor.R, 
00136                 textColor.G, 
00137                 textColor.B, 
00138                 screen.TransitionAlpha);
00139 
00140             // Modify pane color to be darker
00141             paneColor = new Color(
00142                 paneColor.R / 64,
00143                 paneColor.G / 64,
00144                 paneColor.B / 64);
00145 
00146             // Create shadow color
00147             Color color2 = new Color(
00148                 Color.DarkSlateBlue.R,
00149                 Color.DarkSlateBlue.G,
00150                 Color.DarkSlateBlue.B,
00151                 screen.TransitionAlpha);
00152 
00153             // Draw text, centered on the middle of each line.
00154             ScreenManager screenManager = screen.ScreenManager;
00155             SpriteBatch spriteBatch = screenManager.SpriteBatch;
00156             SpriteFont spriteFont = screenManager.Fonts["menu"];
00157 
00158             Vector2 origin = new Vector2(0, spriteFont.LineSpacing / 2);
00159 
00160             // Create translucent pane rectangle 
00161             if (this.paneTexture == null)
00162             {
00163                 // New background texture
00164                 this.paneTexture = TextureHelpers.Create(screenManager.GraphicsDevice, new Color(64, 64, 64));
00165             }
00166 
00167             Vector2 textSize = spriteFont.MeasureString(text);
00168             Viewport viewport = screenManager.GraphicsDevice.Viewport;
00169             Rectangle backgroundPane =
00170                 new Rectangle(
00171                     (int)position.X - 15, 
00172                     (int)(position.Y - origin.Y + 2), 
00173                     (int)((viewport.Width / 2) * 1.25f), 
00174                     screenManager.Fonts["menu"].LineSpacing - 2);
00175             spriteBatch.Draw(this.paneTexture, backgroundPane, new Color(paneColor, 128));
00176             if (isSelected)
00177             {
00178                 backgroundPane.X -= 20;
00179                 backgroundPane.Width = 20;
00180                 spriteBatch.Draw(this.paneTexture, backgroundPane, new Color(paneColor, 200));
00181             }
00182 
00183             Vector2 shadowPosition;
00184             Vector2 shadowOffset = new Vector2(2.0f, 2.0f);
00185             shadowPosition = position + shadowOffset;
00186 
00187             spriteBatch.DrawString(spriteFont, text, shadowPosition, color2, 0,
00188                        origin, scale, SpriteEffects.None, 0);
00189 
00190             spriteBatch.DrawString(spriteFont, text, position, textColor, 0,
00191                                    origin, scale, SpriteEffects.None, 0);
00192         }

virtual int NewGamePhysics.StateManager.MenuEntry.GetHeight ( MenuScreen  screen  )  [virtual]

Queries how much space this menu entry requires.

Definition at line 198 of file MenuEntry.cs.

00199         {
00200             return screen.ScreenManager.Fonts["menu"].LineSpacing;
00201         }

virtual internal void NewGamePhysics.StateManager.MenuEntry.OnSelectEntry ( PlayerIndex  playerIndex  )  [protected, virtual]

Method for raising the Selected event.

Definition at line 66 of file MenuEntry.cs.

00067         {
00068             if (Selected != null)
00069             {
00070                 Selected(this, new PlayerIndexEventArgs(playerIndex));
00071             }
00072         }

virtual void NewGamePhysics.StateManager.MenuEntry.Update ( MenuScreen  screen,
bool  isSelected,
GameTime  gameTime 
) [virtual]

Updates the menu entry.

Definition at line 97 of file MenuEntry.cs.

00099         {
00100             // When the menu selection changes, entries gradually fade between
00101             // their selected and deselected appearance, rather than instantly
00102             // popping to the new state.
00103             float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;
00104 
00105             if (isSelected)
00106             {
00107                 selectionFade = Math.Min(selectionFade + fadeSpeed, 1);
00108             }
00109             else
00110             {
00111                 selectionFade = Math.Max(selectionFade - fadeSpeed, 0);
00112             }
00113         }


Property Documentation

string NewGamePhysics.StateManager.MenuEntry.Text [get, set]

Gets or sets the text of this menu entry.

Definition at line 49 of file MenuEntry.cs.


Event Documentation

EventHandler<PlayerIndexEventArgs> NewGamePhysics.StateManager.MenuEntry.Selected

Event raised when the menu entry is selected.

Definition at line 61 of file MenuEntry.cs.


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

Generated by  doxygen 1.6.2