68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace MrAG {
|
|
public partial class Gui {
|
|
public class Button : Base {
|
|
public string Text {
|
|
get {
|
|
return this._text;
|
|
}
|
|
|
|
set{
|
|
this._text = value;
|
|
|
|
if (this.AutoResize) {
|
|
this.Width = (int)this.Font.MeasureString(this._text).X;
|
|
this.Height = (int)this.Font.MeasureString(this._text).Y;
|
|
}
|
|
}
|
|
}
|
|
|
|
public SpriteFont Font = MrAG.Draw.Font;
|
|
|
|
public Color TextColor = Color.White;
|
|
|
|
public Color BorderColor = Color.LightGray;
|
|
|
|
public Color Color = Color.Black;
|
|
public Color HoverColor = Color.DarkGray;
|
|
public Color ActiveColor = Color.Gray;
|
|
|
|
public int BorderSize = 2;
|
|
|
|
public MrAG.Draw.TextAlignmentX AlignmentX = MrAG.Draw.TextAlignmentX.Center;
|
|
public MrAG.Draw.TextAlignmentY AlignmentY = MrAG.Draw.TextAlignmentY.Center;
|
|
|
|
public float Rotation = 0;
|
|
public bool AutoResize = false;
|
|
|
|
private bool hover;
|
|
private bool active;
|
|
|
|
private string _text = "";
|
|
|
|
public override void Update() {
|
|
this.hover = this.Hovering();
|
|
this.active = this.IsActive();
|
|
|
|
base.Update();
|
|
}
|
|
|
|
public override void Draw() {
|
|
MrAG.Draw.Box(this.X + this.BorderSize, this.Y + this.BorderSize, this.Width - (this.BorderSize * 2), this.Height - (this.BorderSize * 2), this.hover ? (this.active ? this.ActiveColor : this.HoverColor) : this.Color);
|
|
MrAG.Draw.OutlinedBox(this.X, this.Y, this.Width, this.Height, this.BorderSize, this.BorderColor);
|
|
|
|
MrAG.Draw.SetFont(this.Font);
|
|
MrAG.Draw.Text(this.Text, this.X + (this.Width / 2), this.Y + (this.Height / 2), this.TextColor, this.AlignmentX, this.AlignmentY, this.Rotation);
|
|
|
|
base.Draw();
|
|
}
|
|
}
|
|
}
|
|
}
|