Skip to content

Commit

Permalink
Add Image UI component
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagomvas committed May 24, 2024
1 parent 0cc8f73 commit b482269
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Basalt.Raylib/Components/Image.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Basalt.Common.Components;
using Basalt.Common.Entities;
using Basalt.Common.Utils;
using Basalt.Raylib.Graphics;
using Raylib_cs;

namespace Basalt.Raylib.Components
{
public class Image : UIComponent
{
private string _textureKey = string.Empty;
public string TextureKey
{
get => _textureKey;
set
{
_textureKey = value;
_texture = null;
}
}
public float Scale { get; set; } = 1f;
public Color Tint { get; set; } = Color.White;

private Texture2D? _texture;
public Image(Entity entity) : base(entity)
{
}

public override void OnStart()
{

}

public override void OnUpdate()
{

}

public override void OnUIRender()
{
if (_texture == null)
_texture = ResourceCache.Instance.GetTexture(TextureKey);
var position = GetPivotedPosition(new(Raylib_cs.Raylib.GetScreenWidth(), Raylib_cs.Raylib.GetScreenHeight())) + Offset;
Raylib_cs.Raylib.DrawTextureEx(_texture.Value, position, Rotation, Scale, Tint);
}
}
}

0 comments on commit b482269

Please sign in to comment.