using System;
using Microsoft.Xna.Framework.Graphics;
using GraphiXNA.Effect2D;
using Microsoft.Xna.Framework;

namespace GraphiXNA
{
    public class Logo
    {
        GraphicsDevice GraphicsDevice = null;

        private VertexBuffer VertexBuffer = null;
        private VertexDeclaration Declaration = null;
        private Effect NoPostProcess = null;
        private Texture2D LogoTexture = null;

        public Logo(GraphicsDevice graphicsDevice)
        {
            GraphicsDevice = graphicsDevice;

            VertexPositionTexture[] Vertices = new VertexPositionTexture[4];

            NoPostProcess = ResourceManager.GetNoPostProcessEffect(GraphicsDevice, false);
            LogoTexture = ResourceManager.GetLogoTexture(graphicsDevice);

            Declaration = new VertexDeclaration(GraphicsDevice, VertexPositionTexture.VertexElements);
            VertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionTexture.SizeInBytes * 4, BufferUsage.WriteOnly);
            Vertices[0].Position = new Vector3(0.45f, -0.7f, 0);
            Vertices[1].Position = new Vector3(0.99f, -0.7f, 0);
            Vertices[2].Position = new Vector3(0.45f, -0.99f, 0);
            Vertices[3].Position = new Vector3(0.99f, -0.99f, 0);

            Vertices[0].TextureCoordinate = new Vector2(0, 0);
            Vertices[1].TextureCoordinate = new Vector2(1, 0);
            Vertices[2].TextureCoordinate = new Vector2(0, 1);
            Vertices[3].TextureCoordinate = new Vector2(1, 1);
            VertexBuffer.SetData<VertexPositionTexture>(Vertices);
        }

        public void Draw()
        {
            GraphicsDevice.VertexDeclaration = Declaration;
            GraphicsDevice.Vertices[0].SetSource(VertexBuffer, 0, VertexPositionTexture.SizeInBytes);
            GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
            GraphicsDevice.Textures[0] = LogoTexture;
            NoPostProcess.Begin();

            EffectPass pass = NoPostProcess.CurrentTechnique.Passes[0];
            pass.Begin();
            GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            pass.End();

            NoPostProcess.End();
        }
    }
}
