/* * Util.MenuButtonHover.cs * Authors: Adam Nabinger * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace Util { /// /// A simple button for use in a menu. /// public class MenuButtonHover : MenuButton { #region Fields // The file path name of the texture to load private readonly string mHoverTextureName; // The texture to render the button with when the mouse is hovering over it. private Texture2D mHoverTexture; // If the mouse is over this button private bool mHovering; #endregion #region Creation /// /// Constructor /// /// The file path name for the texture to render with /// /// The location of the button and its dimensions /// Code to execute for when the button is pressed public MenuButtonHover(string textureName, string hoverTextureName, Rectangle location, Code exe) : base(textureName, location, exe) { mHoverTextureName = hoverTextureName; } #endregion #region Management /// /// Loads in all the necessary information for content dependent objects /// /// Reference to the current content manager for loading internal override void LoadContent(ContentManager content) { mHoverTexture = content.Load(mHoverTextureName); base.LoadContent(content); } public void Update(bool hovering) { mHovering = hovering; } #endregion #region Render /// /// Renders the menu button /// /// The current sprite batch object to render with internal override void Draw(SpriteBatch sb) { if (mHovering) { sb.Draw(mHoverTexture, Location, Color.White); } else { sb.Draw(mTexture, Location, Color.White); } } #endregion } }