Interfaces/ITexturable.cs

Interface ITexturable for crosshair UI elements, extends IBarCrosshair and declares methods to get/set a Texture by object or path. It also provides a protected static helper RenderTextured that computes an origin and rect then draws the texture with HudPainter.

Native Interop
using Sandbox;
using Sandbox.Rendering;
using static Sandbox.CameraComponent;
using System;
using System.Text;

namespace CrosshairMaker.Interfaces
{
	public interface ITexturable : IBarCrosshair
	{
		public Texture GetTexture();
		public void SetTexture(Texture texture);
		public void SetTexture(string path);
		protected static void RenderTextured( ITexturable self, HudPainter hud, Vector2? origin = null, Rect? rect = null )
		{
			origin ??= GetOriginPx(self);
			rect ??= _MakeRect( self, origin.Value );

			
			hud.DrawTexture( self.GetTexture(), rect.Value );

			
		}
	}
}