using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;

namespace ActionGame.UserInterface.Core
{
    public class Cursor : ICursor
    {
        private readonly Texture2D texture;
        private readonly IResolution resolution;
        private readonly Int32 width;
        private readonly Int32 height;


        public Cursor(Texture2D texture, IResolution resolution)
        {
            this.texture = texture;
            this.resolution = resolution;

            this.width = 16;
            this.height = 24;
        }


        public void Update(GameTime gameTime)
        {

        }


        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            Point location = GetLocation();

            spriteBatch.Draw(this.texture, new Rectangle(location.X, location.Y, this.width, this.height), Color.White);
        }


        public Point GetLocation()
        {
            MouseState state = Mouse.GetState();
            Vector2 vector = new Vector2(state.X - this.resolution.Viewport.X, state.Y - this.resolution.Viewport.Y);
            Point point = Vector2.Transform(vector, this.resolution.InvertMatrix).ToPoint();

            return point;
        }

    }
}
