using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using DI=Microsoft.DirectX.DirectInput;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;
namespace win
{
    #region user input class
    class user_input
    {
        private DI.Device device_input_m;
        private DI.Device device_input_k;
        DI.MouseState mouse;
        float s = 100f;
        float sp = 1;
        Form1 hwnd;
        private Microsoft.DirectX.Direct3D.Font text_fog;
        private Microsoft.DirectX.Direct3D.Font text_see_as_among;
        private Microsoft.DirectX.Direct3D.Font text_position;
        private Microsoft.DirectX.Direct3D.Font exit;
        private string fog_status = "Enable";
        private string among_status ="Enable";
        #region initialize mouse
        #region initialize input device
        public void initialize_input_device()
        {
            hwnd = new Form1();
            device_input_k = new DI.Device(DI.SystemGuid.Keyboard);
            device_input_k.SetCooperativeLevel(hwnd, DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
            device_input_k.Acquire();
            device_input_m = new DI.Device(DI.SystemGuid.Mouse);
            device_input_m.SetCooperativeLevel(hwnd, DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
            device_input_m.Acquire();
        }
        #endregion
       
        #region get input x,y key
        /// <summary>
        /// get input x key
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public  float input_parametersx(float x)
        {
            mouse = device_input_m.CurrentMouseState;
            x -= mouse.Y * 0.005f;
            return (x);
            
        }
        /// <summary>
        /// get input x key
        /// </summary>
        /// <param name="y"></param>
        /// <returns></returns>
        public float input_parametersy(float y)
        {
            y -= mouse.X * 0.005f;
            return (y);

        }
        #endregion

        #region move
        public Vector3 move(Vector3 addvector,Device device,float x,float y)
        {
            DI.KeyboardState keybord = device_input_k.GetCurrentKeyboardState();
            if (keybord[DI.Key.Down])
            {
                 s++;
                 addvector = new Vector3();
                 addvector.Z += s;
                 addvector.X += sp;
            }
            if (keybord[DI.Key.Up])
            {
                s--;
                 addvector = new Vector3();
                 addvector.Z += s;
                 addvector.X += sp;
            }
            if (keybord[DI.Key.Left])
            {
                sp++;
                addvector = new Vector3();
                addvector.Z += s;
                addvector.X += sp;
            }
            if (keybord[DI.Key.Right])
            {
                sp--;
                addvector = new Vector3();
                addvector.Z += s;
                addvector.X += sp;
            }
            if (keybord[DI.Key.Space])
            {
                addvector = new Vector3();
                addvector.Z += s;
                addvector.X += sp;
                addvector.Y = -90;
            }
            //creating fog
            if (keybord[DI.Key.F])
            {
                if (!device.RenderState.FogEnable == true)
                {
                    fog_status = "Disable";
                device.RenderState.FogEnable = true;
                device.RenderState.FogColor = System.Drawing.Color.White;
                device.RenderState.FogDensity = 0.1f;
                device.RenderState.FogStart = 0;
                device.RenderState.FogEnd = 1000;
                device.RenderState.FogVertexMode = FogMode.Linear;
                }
                else
                {
                    fog_status = "Enable";
                    device.RenderState.FogEnable= false;
                }
            }
            //see as among
            if (keybord[DI.Key.V])
            {
                if (!device.RenderState.AlphaBlendEnable == true)
                {
                    among_status = "Disable";
                    device.RenderState.SourceBlend = Blend.One;
                    device.RenderState.DestinationBlend = Blend.One;
                    device.RenderState.AlphaBlendEnable = true;
                }
                else
                {
                    among_status = "Enable";
                    device.RenderState.AlphaBlendEnable = false;
                }
            }
            return addvector;
        }
        #endregion
        
        #region text
       /// <summary>
       /// initialize tex
       /// </summary>
       /// <param name="device"></param>
        public void initialize_text(Device device)
        {
            //initialize system font
            System.Drawing.Font systemfont = new System.Drawing.Font("Arial", 12f, System.Drawing.FontStyle.Italic);
            //initialize text fog
            text_fog = new Microsoft.DirectX.Direct3D.Font(device, systemfont);
            //initialize text among
            text_see_as_among = new Microsoft.DirectX.Direct3D.Font(device, systemfont);
            //initialize text position
            text_position = new Microsoft.DirectX.Direct3D.Font(device, systemfont);
            //initialize text position
            exit = new Microsoft.DirectX.Direct3D.Font(device, systemfont);

        }
        /// <summary>
        /// draw text
        /// </summary>
        /// <param name="device"></param>
        public void draw_text(Device device, Vector3 position,float x,float y)
        {
            //drawing text fog
            text_fog.DrawText(null, "Press 'F' To "+fog_status+" Fogging", new Point(10, 10), Color.Red);
            //drawing text among
            text_see_as_among.DrawText(null, "Press 'V' To " + among_status + " Seeing As Among", new Point(10, 30), Color.Red);
            //drawing text position
            text_position.DrawText(null,"position::" + position.X.ToString() + ","+position.Y.ToString()+","+position.Z.ToString()+"\n"+"mouse Position::"+x.ToString()+","+y.ToString(), new Point(10, 50), Color.Red);
            //drawing text exit
            exit.DrawText(null, "Press Escape To Exit", new Point(10, 90), Color.Red);
        }
#endregion
        #endregion
    }
    #endregion
}
