/// <summary> /// Draws the menu entry. This can be overridden to customize the appearance. /// </summary> public virtual void Draw(MenuScreen screen, Rectangle borders, bool isSelected, GameTime gameTime) { if(font == null) font = ScreenManager.Cartoon24; // Draw the selected entry in yellow, otherwise white. Color color = isSelected ? selectedColor : textColor; // Pulsate the size of the selected menu entry. double time = gameTime.TotalGameTime.TotalSeconds; float pulsate = (float)Math.Sin(time * 6) + 1; float scale = 1 + pulsate * 0.05f * selectionFade; // Modify the alpha to fade text out during transitions. color = new Color(color.R, color.G, color.B, screen.TransitionAlpha); // Draw text, centered on the middle of each line. Vector2 origin = font.MeasureString(text) / 2; Vector2 position; if (borders.Height <= 0) position = new Vector2(borders.X, borders.Y); else { float x = TextureManager.GetCenterX(borders.X, borders.Width, 0); position = new Vector2((int)x, borders.Y); } PoorEngine.SceneObject.Text.DrawText( font, Text, Color.Black, color, 1f, scale, 0f, position, origin, false); }
/// <summary> /// Updates the menu entry. /// </summary> public virtual void Update(MenuScreen screen, bool isSelected, GameTime gameTime) { // When the menu selection changes, entries gradually fade between // their selected and deselected appearance, rather than instantly // popping to the new state. float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4; if (isSelected) selectionFade = Math.Min(selectionFade + fadeSpeed, 1); else selectionFade = Math.Max(selectionFade - fadeSpeed, 0); }
public virtual void Draw(MenuScreen screen, Vector2 position, bool isSelected, GameTime gameTime) { Draw(screen, new Rectangle((int)position.X, (int)position.Y, 0, 0), isSelected, gameTime); }
/// <summary> /// Queries how much space this menu entry requires. /// </summary> public virtual int GetHeight(MenuScreen screen) { return font.LineSpacing; }