40 lines
No EOL
1.2 KiB
C#
40 lines
No EOL
1.2 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using MonoGameLibrary.Graphics;
|
|
using MonoGameLibrary.Input;
|
|
|
|
namespace FNAF_Clone.GUI;
|
|
|
|
public class UIElement {
|
|
public bool Active { get; set; } = false;
|
|
public bool Pressable { get; set; } = false;
|
|
|
|
private (Point, Point) bounds; // TODO: Change this to support non-rectangular hitboxes
|
|
private TextureRegion texture;
|
|
|
|
public UIElement(TextureRegion texture, Point position) {
|
|
this.texture = texture;
|
|
bounds = (position, position + new Point(texture.Width, texture.Height));
|
|
}
|
|
public void Update() {
|
|
|
|
}
|
|
|
|
public bool IsWithinBounds(Point pos) {
|
|
return pos.X >= Math.Min(bounds.Item1.X, bounds.Item2.X) && pos.X <= Math.Max(bounds.Item1.X, bounds.Item2.X) &&
|
|
pos.Y >= Math.Min(bounds.Item1.Y, bounds.Item2.Y) && pos.Y <= Math.Max(bounds.Item1.Y, bounds.Item2.Y);
|
|
}
|
|
|
|
public Action OnMousePress{ get; set; }
|
|
|
|
// public virtual void OnMousePress() { }
|
|
|
|
public virtual void OnMouseRelease() { }
|
|
|
|
public virtual void OnMouseHold() { }
|
|
|
|
public void Draw(SpriteBatch spriteBatch) {
|
|
texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
|
}
|
|
} |