Files
RobustToolbox/Robust.Client/UserInterface/Controls/SpriteView.cs
PJB3005 ee330d0ae9 Make DOOM work
I think I lost this work originally
2025-01-15 23:08:44 +01:00

55 lines
1.4 KiB
C#

using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Maths;
namespace Robust.Client.UserInterface.Controls
{
public class SpriteView : Control
{
private Vector2 _scale = (1, 1);
public Vector2 Scale
{
get => _scale;
set
{
_scale = value;
InvalidateMeasure();
}
}
public ISpriteComponent? Sprite { get; set; }
/// <summary>
/// Overrides the direction used to render the sprite.
/// </summary>
/// <remarks>
/// If null, the world space orientation of the entity will be used.
/// Otherwise the specified direction will be used.
/// </remarks>
public Direction? OverrideDirection { get; set; }
public SpriteView()
{
RectClipContent = true;
}
protected override Vector2 MeasureOverride(Vector2 availableSize)
{
// TODO: make this not hardcoded.
// It'll break on larger things.
return (32, 32) * Scale;
}
public override void DrawInternal(IRenderHandle renderHandle)
{
if (Sprite == null || Sprite.Deleted)
{
return;
}
renderHandle.DrawEntity(Sprite.Owner, GlobalPixelPosition + PixelSize / 2, Scale, OverrideDirection);
}
}
}