using System;
using ComponentFramework;
using ComponentFramework.Modules;

namespace FullScreenShaders.Components.Hosts
{
    [AutoLoad]
    class TextHost : Component
    {
        int segoe;
        TimeSpan totalElapsed;
        int totalLoops, lastLoops;

        public TextHost(ICore provider) : base(provider) { }

        public override int Order
        {
            get { return 1000; }
        }

        public override void Initialize()
        {
            Core.Engine.DisplayFPS(false);

            segoe = Screen2DText.TextureFont_Create("Segoe UI", "Segoe UI", 10, false, false, false, false, true);

            base.Initialize();
        }

        public override void Update(TimeSpan elapsedTime)
        {
            totalElapsed += elapsedTime;

            if (totalElapsed.TotalSeconds >= 1)
            {
                totalElapsed -= TimeSpan.FromSeconds(1);
                lastLoops = totalLoops;
                totalLoops = 0;
            }

            totalLoops++;
        }

        public override void PostDraw()
        {
            const int lineHeight = 15;

            int y = 5;
            int white = Globals.RGBA(1, 1, 1, 1);

            Screen2DText.TextureFont_DrawText(string.Format("Framerate : {0} FPS", lastLoops), 10, y, white, segoe); y += lineHeight;
            Screen2DText.TextureFont_DrawText(string.Format("Used texture memory : {0:# ###.##} MB", TextureFactory.GetUsedTextureMemory() / 1024.0f / 1024.0f), 10, y, white, segoe); y += lineHeight;
            //y += lineHeight;

            //if (Core.Settings.Fullscreen)
            //    Screen2DText.TextureFont_DrawText("F2 : Switch to Windowed", 10, y, white, segoe);
            //else
            //    Screen2DText.TextureFont_DrawText("F1 : Switch to Fullscreen", 10, y, white, segoe);
        }
    }
}
