using System ;
using System.Collections.Generic ;
using System.Runtime.InteropServices ;
using System.Text ;


namespace DxLibDLL
{


	public static partial class DX
	{


		/// <summary> キーボードの入力状態取得 </summary>
		public static bool CheckHitKey( KEY_INPUT KeyCode )
		{
			lock( locker )
			{
				int result = dx_CheckHitKey( KeyCode ) ;
				if( result == 0 ) { return false ; }
				else if( result == 1 ) { return true ; }
				else { throw new DX.Exception() ; }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_CheckHitKey( KEY_INPUT KeyCode ) ;


		/// <summary> 全キーの押下状態を取得 </summary>
		public static bool CheckHitKeyAll()
		{
			return CheckHitKeyAll( DX_CHECKINPUT.ALL ) ;
		}

		/// <summary> 全キーの押下状態を取得 </summary>
		public static bool CheckHitKeyAll( DX_CHECKINPUT CheckType )
		{
			lock( locker )
			{
				int result = dx_CheckHitKeyAll( CheckType ) ;
				if( result == 0 ) { return false ; }
				else if( result == 1 ) { return true ; }
				else { throw new DX.Exception() ; }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_CheckHitKeyAll( DX_CHECKINPUT CheckType ) ;


		/// <summary> すべてのキーの押下状態を取得する </summary>
		public static void GetHitKeyStateAll( out HitKeyStateAll KeyStateBuf )
		{
			lock( locker )
			{
				byte[] KeyStateBuf_ = new byte[0x100];
				int result = dx_GetHitKeyStateAll( KeyStateBuf_ ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
				KeyStateBuf = new HitKeyStateAll( KeyStateBuf_ ) ;
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_GetHitKeyStateAll( [ Out ] byte[] KeyStateBuf ) ;


		/// <summary> キーボードの協調レベルを排他レベルにするかどうかのフラグをセットする </summary>
		public static void SetKeyExclusiveCooperativeLevelFlag( bool Flag )
		{
			lock( locker )
			{
				int result = dx_SetKeyExclusiveCooperativeLevelFlag( Flag ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_SetKeyExclusiveCooperativeLevelFlag( bool Flag ) ;


		/// <summary> ジョイパッドが接続されている数を取得する </summary>
		public static int GetJoypadNum()
		{
			lock( locker )
			{
				int result = dx_GetJoypadNum() ;
				if( !( result >= 0 ) ) { throw new DX.Exception(); }
				return result ;
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_GetJoypadNum() ;


		/// <summary> ジョイバッドの入力状態取得 </summary>
		public static PAD_INPUT GetJoypadInputState( DX_INPUT InputType )
		{
			lock( locker )
			{
				PAD_INPUT result = dx_GetJoypadInputState( InputType ) ;
				return result ;
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern PAD_INPUT dx_GetJoypadInputState( DX_INPUT InputType ) ;


		/// <summary> ジョイパッドのアナログ的なスティック入力情報を得る </summary>
		public static void GetJoypadAnalogInput( out int XBuf , out int YBuf , DX_INPUT InputType )
		{
			lock( locker )
			{
				int result = dx_GetJoypadAnalogInput( out XBuf , out YBuf , InputType ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_GetJoypadAnalogInput( out int XBuf , out int YBuf , DX_INPUT InputType ) ;


		/// <summary> ジョイパッドのアナログ的なスティック入力情報を得る(右スティック用) </summary>
		public static void GetJoypadAnalogInputRight( out int XBuf , out int YBuf , DX_INPUT InputType )
		{
			lock( locker )
			{
				int result = dx_GetJoypadAnalogInputRight( out XBuf , out YBuf , InputType ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_GetJoypadAnalogInputRight( out int XBuf , out int YBuf , DX_INPUT InputType ) ;


		/// <summary> キーボードのバッファからデータを取得する処理 </summary>
		public static void KeyboradBufferProcess()
		{
			lock( locker )
			{
				int result = dx_KeyboradBufferProcess() ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_KeyboradBufferProcess() ;


		/// <summary> ジョイパッドのＧＵIＤを得る </summary>
		public static void GetJoypadGUID( int PadIndex , out Guid GuidBuffer )
		{
			lock( locker )
			{
				GUID GuidBuffer_ ;
				int result = dx_GetJoypadGUID( PadIndex , out GuidBuffer_ ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
				GuidBuffer = new Guid( GuidBuffer_.Data ) ;
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_GetJoypadGUID( int PadIndex , out GUID GuidBuffer ) ;


		/// <summary> ＤＸライブラリのキーコードから Windows の仮想キーコードを取得する </summary>
		public static int ConvertKeyCodeToVirtualKey( KEY_INPUT KeyCode )
		{
			lock( locker )
			{
				int result = dx_ConvertKeyCodeToVirtualKey( KeyCode ) ;
				if( !( result >= 0 ) ) { throw new DX.Exception(); }
				return result ;
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_ConvertKeyCodeToVirtualKey( KEY_INPUT KeyCode ) ;


		/// <summary> ジョイパッドの入力に対応したキーボードの入力を設定する </summary>
		public static void SetJoypadInputToKeyInput( DX_INPUT InputType , PAD_INPUT PadInput , KEY_INPUT KeyInput1 )
		{
			SetJoypadInputToKeyInput( InputType , PadInput , KeyInput1 , ( KEY_INPUT )( -1 ) ) ;
		}

		/// <summary> ジョイパッドの入力に対応したキーボードの入力を設定する </summary>
		public static void SetJoypadInputToKeyInput( DX_INPUT InputType , PAD_INPUT PadInput , KEY_INPUT KeyInput1 , KEY_INPUT KeyInput2 )
		{
			SetJoypadInputToKeyInput( InputType , PadInput , KeyInput1 , KeyInput2 , ( KEY_INPUT )( -1 ) ) ;
		}

		/// <summary> ジョイパッドの入力に対応したキーボードの入力を設定する </summary>
		public static void SetJoypadInputToKeyInput( DX_INPUT InputType , PAD_INPUT PadInput , KEY_INPUT KeyInput1 , KEY_INPUT KeyInput2 , KEY_INPUT KeyInput3 )
		{
			SetJoypadInputToKeyInput( InputType , PadInput , KeyInput1 , KeyInput2 , KeyInput3 , ( KEY_INPUT )( -1 ) ) ;
		}

		/// <summary> ジョイパッドの入力に対応したキーボードの入力を設定する </summary>
		public static void SetJoypadInputToKeyInput( DX_INPUT InputType , PAD_INPUT PadInput , KEY_INPUT KeyInput1 , KEY_INPUT KeyInput2 , KEY_INPUT KeyInput3 , KEY_INPUT KeyInput4 )
		{
			lock( locker )
			{
				int result = dx_SetJoypadInputToKeyInput( InputType , PadInput , KeyInput1 , KeyInput2 , KeyInput3 , KeyInput4 ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_SetJoypadInputToKeyInput( DX_INPUT InputType , PAD_INPUT PadInput , KEY_INPUT KeyInput1 , KEY_INPUT KeyInput2 , KEY_INPUT KeyInput3 , KEY_INPUT KeyInput4 ) ;


		/// <summary> ジョイパッドの無効ゾーンの設定を行う </summary>
		public static void SetJoypadDeadZone( DX_INPUT InputType , double Zone )
		{
			lock( locker )
			{
				int result = dx_SetJoypadDeadZone( InputType , Zone ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_SetJoypadDeadZone( DX_INPUT InputType , double Zone ) ;


		/// <summary> ジョイパッドの振動を開始する </summary>
		public static void StartJoypadVibration( DX_INPUT InputType , int Power , int Time )
		{
			lock( locker )
			{
				int result = dx_StartJoypadVibration( InputType , Power , Time ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_StartJoypadVibration( DX_INPUT InputType , int Power , int Time ) ;


		/// <summary> ジョイパッドの振動を停止する </summary>
		public static void StopJoypadVibration( DX_INPUT InputType )
		{
			lock( locker )
			{
				int result = dx_StopJoypadVibration( InputType ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_StopJoypadVibration( DX_INPUT InputType ) ;


		/// <summary> ジョイパッドのＰＯＶ入力の状態を得る( 単位は角度の１００倍  中心位置にある場合は -1 が返る ) </summary>
		public static int GetJoypadPOVState( DX_INPUT InputType , int POVNumber )
		{
			lock( locker )
			{
				int result = dx_GetJoypadPOVState( InputType , POVNumber ) ;
				if( !( result >= 0 ) ) { throw new DX.Exception(); }
				return result ;
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_GetJoypadPOVState( DX_INPUT InputType , int POVNumber ) ;


		/// <summary> ジョイパッドのデバイス登録名と製品登録名を取得する </summary>
		public static void GetJoypadName( DX_INPUT InputType , out string InstanceNameBuffer , out string ProductNameBuffer )
		{
			lock( locker )
			{
				StringBuilder InstanceNameBuffer_ = new StringBuilder( 0x200 ) ;
				StringBuilder ProductNameBuffer_ = new StringBuilder( 0x200 );
				int result = dx_GetJoypadName( InputType , InstanceNameBuffer_ , ProductNameBuffer_ ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
				InstanceNameBuffer = InstanceNameBuffer_.ToString() ;
				ProductNameBuffer = ProductNameBuffer_.ToString() ;
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_GetJoypadName( DX_INPUT InputType , [ Out ] StringBuilder InstanceNameBuffer , [ Out ] StringBuilder ProductNameBuffer ) ;


		/// <summary> ジョイパッドの再セットアップを行う( 新たに接続されたジョイパッドがある場合に検出される ) </summary>
		public static void ReSetupJoypad()
		{
			lock( locker )
			{
				int result = dx_ReSetupJoypad() ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_ReSetupJoypad() ;


		/// <summary> キーボードの入力処理に DirectInput を使わないか、フラグをセットする </summary>
		public static void SetKeyboardNotDirectInputFlag( bool Flag )
		{
			lock( locker )
			{
				int result = dx_SetKeyboardNotDirectInputFlag( Flag ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_SetKeyboardNotDirectInputFlag( bool Flag ) ;


		/// <summary> 入力処理に DirectInput を使用するかどうかのフラグをセットする </summary>
		public static void SetUseDirectInputFlag( bool Flag )
		{
			lock( locker )
			{
				int result = dx_SetUseDirectInputFlag( Flag ) ;
				if( !( result == 0 ) ) { throw new DX.Exception(); }
			}
		}

	#if UNICODE
		[ DllImport( "DxLibW.dll" , CharSet = CharSet.Unicode , ExactSpelling = true ) ]
	#else
		[ DllImport( "DxLib.dll" , CharSet = CharSet.Ansi , ExactSpelling = true ) ]
	#endif
		private static extern int dx_SetUseDirectInputFlag( bool Flag ) ;
	}
}
