using RecrownedGTK.Graphics.Render;
using OpenTK.Graphics;
using RecrownedGTK.Graphics.UI.SkinSystem;
using RecrownedGTK.Graphics.UI.SkinSystem.Definitions;
namespace RecrownedGTK.Graphics.UI.Modular.Modules.Interactive
{
///
/// Button that holds a string.
///
public class TextButton : Button
{
///
/// The text that is used to display the string.
///
public readonly Text text;
///
/// The color the font should be rendered in.
///
public Color4 FontColor { get { return text.color; } set { text.color = value; } }
///
/// Constructs text button with the positions represented by
///
/// The string representing the text to be displayed.
/// The font to be used to display the text.
/// What to draw as button is pushed down.
/// What to draw as button is not pushed.
/// What to draw as button is disabled.
/// What to draw as button is selected.
public TextButton(string text, SpriteFont font, ISpecialDrawable down, ISpecialDrawable up, ISpecialDrawable disabled = null, ISpecialDrawable selected = null) : base(down, up, disabled, selected)
{
this.text = new Text(font, text);
this.text.autoScale = true;
this.text.centered = true;
}
///
/// Constructs a text button using a skin and definition.
///
/// The text to display.
/// The font to be used.
/// The skin to use.
/// Name of the definition for this type in the skin given.
public TextButton(string text, SpriteFont font, ISkin skin, string definitionName = null) : base(skin, skin.ObtainDefinition(definitionName))
{
TextButtonSkinDefinition skinDefinition = skin.ObtainDefinition(definitionName);
this.text = new Text(font, text);
this.text.autoScale = true;
this.text.centered = true;
FontColor = skin.GetColor(skinDefinition.fontColor);
}
///
/// Creates a text button with a given definition.
///
/// The text to be displayed on this button.
/// The font to use for this button.
/// The skin the definition is from.
/// The definition to use.
public TextButton(string text, SpriteFont font, ISkin skin, TextButtonSkinDefinition skinDefinition) :
this(text,
font,
skin.GetTextureAtlasRegion(skinDefinition.downRegion, true),
skin.GetTextureAtlasRegion(skinDefinition.upRegion, true),
skin.GetTextureAtlasRegion(skinDefinition.disabledRegion),
skin.GetTextureAtlasRegion(skinDefinition.selectedRegion))
{ }
///
/// Updates the text button.
///
/// Snapshot of information about time for game.
public override void Update(GameTime gameTime)
{
text.SetPositionAndDimensions(Boundaries);
text.Update(gameTime);
base.Update(gameTime);
}
///
/// Called whenever game wants to render this button.
///
/// Batch to use. Batch should already be started.
public override void Draw(ConsistentSpriteBatch batch)
{
base.Draw(batch);
text.Draw(batch);
}
}
}