using System.Runtime.InteropServices;
using Decal.Interop.Core;
using Decal.Interop.Render;

namespace Decal.DecalRender
{
    [ComVisible(true)]
    [Guid("EF810EF1-C843-4563-A3DE-19CE8BEEEEC0")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("DecalRender.HUDView")]
    public class HUDViewImpl : IHUDView
    {
        private static int _nextId;
        private readonly int _id;
        private object _surface;
        private tagRECT _region;
        private bool _enabled = true;
        private float _scaleFactor = 1.0f;
        private bool _scaling;
        private float _angle;
        private int _alpha = 255;

        public HUDViewImpl()
        {
            _id = System.Threading.Interlocked.Increment(ref _nextId);
        }

        // IRenderTarget
        public bool Lost => false;
        public void SetSurface(object pSurface) => _surface = pSurface;
        public object GetSurface() => _surface;
        public tagRECT Region { get => _region; set => _region = value; }
        public tagRECT Constraints => _region;
        public void Fill(ref tagRECT FillArea, int Color) { }
        public void Clear(ref tagRECT ClearArea) { }
        public void BeginRender(bool bFilterTexture) { }
        public void EndRender() { }
        public void BeginText(string FontName, int lHeight, int lWeight, bool bItalic) { }
        public void EndText() { }
        public void DrawPortalImage(int lPortalFile, ref tagRECT DestArea) { }
        public void DrawPortalImageEx(int lPortalFile, int lAlpha, ref tagRECT SrcArea, ref tagRECT DestArea) { }
        public void DrawImage(int pBuffer, int lSize, ref tagRECT DestRegion, int lColorKey) { }
        public void WriteText(ref tagRECT Region, int lColor, int lFormat, string Text) { }
        public void TilePortalImage(int lPortalFile, ref tagRECT DestArea) { }
        public void TilePortalImageEx(int lPortalFile, ref tagRECT SrcArea, ref tagRECT DestArea) { }

        public RenderTargetWrapper Constrain(ref tagRECT Region)
        {
            return (RenderTargetWrapper)(object)new RenderTargetWrapperImpl();
        }

        // IRenderScalable
        public void ScaleTo(ref tagRECT pArea) { _region = pArea; }
        public float ScaleFactor { get => _scaleFactor; set => _scaleFactor = value; }
        public bool Scaling { get => _scaling; set => _scaling = value; }
        public tagRECT ScaleRect => _region;

        // IHUDView
        public int ID => _id;
        public bool Enabled { get => _enabled; set => _enabled = value; }
        public void SetBackground(HUDBackground pBackground) { }
        public float Angle { get => _angle; set => _angle = value; }
        public int Alpha { get => _alpha; set => _alpha = value; }
        public void PushClipRegion(ref tagRECT Region) { }
        public void PopClipRegion() { }
        public void RemoveClipping() { }
        public bool IsClipped => false;

        public void MeasureText(string Text, out tagRECT pRet)
        {
            pRet = default;
        }
    }
}
