aboutsummaryrefslogtreecommitdiff
path: root/source/ui/elements/Element.cs
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/ui/elements/Element.cs
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/ui/elements/Element.cs')
-rw-r--r--source/ui/elements/Element.cs53
1 files changed, 53 insertions, 0 deletions
diff --git a/source/ui/elements/Element.cs b/source/ui/elements/Element.cs
new file mode 100644
index 0000000..b95a693
--- /dev/null
+++ b/source/ui/elements/Element.cs
@@ -0,0 +1,53 @@
+using System;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace Celesteia.UI.Elements {
+ public class Element : IElement
+ {
+ private bool _enabled = true;
+ private Rect _rect;
+ private bool _isMouseOver;
+ private IContainer _parent;
+ private Vector2 _pivot;
+
+ public virtual bool GetEnabled() => _enabled && (_parent == null || _parent.GetEnabled());
+ public virtual IContainer GetParent() => _parent;
+ public virtual Vector2 GetPivot() => _pivot;
+ public virtual Rect GetRect() => _rect;
+ public virtual void MoveTo(Point point) {
+ _rect.SetX(AbsoluteUnit.WithValue(point.X));
+ _rect.SetY(AbsoluteUnit.WithValue(point.Y));
+ }
+
+ // Get element rectangle with pivot.
+ public virtual Rectangle GetRectangle() {
+ Rectangle r = GetRect().ResolveRectangle();
+
+ if (GetParent() != null) {
+ r.X += GetParent().GetRectangle().X;
+ r.Y += GetParent().GetRectangle().Y;
+ }
+
+ r.X -= (int)MathF.Round(_pivot.X * r.Width);
+ r.Y -= (int)MathF.Round(_pivot.Y * r.Height);
+
+ return r;
+ }
+
+ // Interface setters.
+ public virtual bool SetEnabled(bool value) => _enabled = value;
+ public virtual void SetParent(IContainer container) => _parent = container;
+ public virtual void SetPivot(Vector2 pivot) => _pivot = pivot;
+ public virtual void SetRect(Rect rect) => _rect = rect;
+
+ // Mouse functions
+ public virtual void OnMouseIn() => _isMouseOver = true;
+ public virtual void OnMouseOut() => _isMouseOver = false;
+ public virtual bool GetMouseOver() => _isMouseOver;
+
+ // Engine functions.
+ public virtual void Update(GameTime gameTime, out bool clickedAnything) { clickedAnything = false; }
+ public virtual void Draw(SpriteBatch spriteBatch) { }
+ }
+} \ No newline at end of file