diff --git a/Basalt.Raylib/Components/Label.cs b/Basalt.Raylib/Components/Label.cs index bff2832..6070672 100644 --- a/Basalt.Raylib/Components/Label.cs +++ b/Basalt.Raylib/Components/Label.cs @@ -9,7 +9,6 @@ public class Label : UIComponent public string Text { get; set; } = string.Empty; public float FontSize { get; set; } = 20; public float Spacing { get; set; } = 1; - public float Rotation { get; set; } = 0; public Label(Entity entity) : base(entity) { } @@ -36,7 +35,6 @@ public override void OnUIRender() FontSize, Spacing, Raylib_cs.Color.White); - Engine.Instance.Logger?.LogDebug($"Drawing label at {position}"); } } } diff --git a/Basalt.Raylib/Components/Panel.cs b/Basalt.Raylib/Components/Panel.cs new file mode 100644 index 0000000..a8cc122 --- /dev/null +++ b/Basalt.Raylib/Components/Panel.cs @@ -0,0 +1,30 @@ +using Basalt.Common.Components; +using Basalt.Common.Entities; +using Raylib_cs; +using System.Numerics; +using static Raylib_cs.Raylib; +namespace Basalt.Raylib.Components +{ + public class Panel : UIComponent + { + public Vector2 Size { get; set; } = Vector2.One; + public Color Color { get; set; } = Color.White; + public Panel(Entity entity) : base(entity) + { + } + + public override void OnStart() + { + } + + public override void OnUpdate() + { + } + + public override void OnUIRender() + { + var position = GetPivotedPosition(new(GetScreenWidth(), GetScreenHeight())) + Offset; + DrawRectanglePro(new Rectangle(position.X - Size.X / 2, position.Y - Size.Y / 2, Size.X, Size.Y), Size / 2, Rotation, Color); + } + } +} diff --git a/Basalt.TestField/Program.cs b/Basalt.TestField/Program.cs index 4ef29e7..945b718 100644 --- a/Basalt.TestField/Program.cs +++ b/Basalt.TestField/Program.cs @@ -58,7 +58,8 @@ player.AddComponent(new Basalt.TestField.Components.PlayerController(player)); player.AddComponent(new LightSource(player, "lighting") { Color = Color.Red, Type = LightType.Point }); //player.AddComponent(new TrailRenderer(player) { StartRadius = 0.5f, EndRadius = 0.1f, Color = Color.Red, TrailSegmentCount = 25, Offset = offset, TrailRefreshRate = 0.025f }); -player.AddComponent(new Label(player) { Text = "This is a test label ", Pivot = UIPivot.MiddleLeft, Offset = new(100, 25)}); +player.AddComponent(new Label(player) { Text = "This is a test label ", Pivot = UIPivot.TopCenter, Offset = new(100, 25)}); +player.AddComponent(new Panel(player) { Size = new(100, 200), Color = Color.Blue, Pivot = UIPivot.TopRight, Offset = new(-100, 200), Rotation = 45f }); Engine.CreateEntity(player); diff --git a/Basalt/Common/Components/UIComponent.cs b/Basalt/Common/Components/UIComponent.cs index 0ff760e..4e927e5 100644 --- a/Basalt/Common/Components/UIComponent.cs +++ b/Basalt/Common/Components/UIComponent.cs @@ -11,6 +11,7 @@ public abstract class UIComponent : Component public UIPivot Pivot { get; set; } = UIPivot.TopLeft; public Vector2 Offset { get; set; } public float ZIndex { get; set; } + public float Rotation { get; set; } protected UIComponent(Entity entity) : base(entity) { }