1
0
Fork 0
This repository has been archived on 2019-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Galactic_Colors_Control/Galactic Colors Control GUI/GUI/Label.cs

76 lines
2.3 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Galactic_Colors_Control_GUI.GUI
{
class Label : Element
{
protected string _text;
protected SpriteFont _font;
protected Color _color, _colorHover, _colorFocus;
protected Vector _vector;
protected bool _center;
public Label() { }
public Label(Vector vector, string text, SpriteFont font, Color color, bool center = false)
{
_vector = vector;
_text = text;
_font = font;
_color = color;
_colorHover = color;
_colorFocus = color;
_center = center;
OnTextChange(text);
}
public Label(Vector vector, string text, SpriteFont font, Color color, Color colorHover, bool center = false)
{
_vector = vector;
_text = text;
_font = font;
_color = color;
_colorHover = colorHover;
_colorFocus = colorHover;
_center = center;
OnTextChange(text);
}
public Label(Vector vector, string text, SpriteFont font, Color color, Color colorHover, Color colorFocus, bool center = false)
{
_vector = vector;
_text = text;
_font = font;
_color = color;
_colorHover = colorHover;
_colorFocus = colorFocus;
_center = center;
OnTextChange(text);
}
protected void OnTextChange(string text)
{
if (_center)
{
_pos = new Rectangle(_vector.X - (int)_font.MeasureString(text).X / 2, _vector.Y - (int)_font.MeasureString(text).Y / 2, (int)_font.MeasureString(text).X, (int)_font.MeasureString(text).Y);
}
else
{
_pos = new Rectangle(_vector.X, _vector.Y, (int)_font.MeasureString(text).X, (int)_font.MeasureString(text).Y);
}
}
public override void Draw(SpriteBatch spriteBatch)
{
Color color = _isFocus ? _colorFocus : (_isHover ? _colorHover : _color);
spriteBatch.DrawString(_font, _text, new Vector2(_pos.X, _pos.Y), color);
}
}
}