Esempio n. 1
0
        public Window1()
        {
            InitializeComponent();

            _wizard = new JoystickWizardController();
//            _wizard.StepCompleted += WizardStepCompleted;
//            _wizard.ConfigurationComplete += WizardConfigurationComplete;
//
//            UpdateLabel(_wizard.CurrentAction);

            IntPtr windowHandle = new WindowInteropHelper(
                Application.Current.MainWindow).Handle;

            string[] joystickNames = Joystick.FindJoysticks();
            if (joystickNames == null || joystickNames.Length == 0)
            {
                MessageBox.Show("No joysticks connected! Plug in a joystick and restart the application.");
                return;
            }

            _joysticks = new List <Joystick>();
            foreach (var joystickName in joystickNames)
            {
                var js = new Joystick(windowHandle);
                js.AcquireJoystick(joystickName);
                _wizard.AddJoystick(js);
                _joysticks.Add(js);
            }

            _vm         = new JoysticksVM();
            DataContext = _vm;

            for (int i = 0; i < _joysticks.Count; i++)
            {
                var joystickVM = new JoystickAxesVM {
                    JoystickName = joystickNames[i]
                };
                _vm.Devices.Add(joystickVM);
            }


            _wizardUpdateTimer          = new Timer(0.1);
            _wizardUpdateTimer.Elapsed += JoystickUpdateTimerElapsed;
            _wizardUpdateTimer.Start();

            Closing += Window1_Closing;
        }
        public Window1()
        {
            InitializeComponent();

            _wizard = new JoystickWizardController();
//            _wizard.StepCompleted += WizardStepCompleted;
//            _wizard.ConfigurationComplete += WizardConfigurationComplete;
//
//            UpdateLabel(_wizard.CurrentAction);

            IntPtr windowHandle = new WindowInteropHelper(
                Application.Current.MainWindow).Handle;

            string[] joystickNames = Joystick.FindJoysticks();
            if (joystickNames == null || joystickNames.Length == 0)
            {
                MessageBox.Show("No joysticks connected! Plug in a joystick and restart the application.");
                return;
            }

            _joysticks = new List<Joystick>();
            foreach (var joystickName in joystickNames)
            {
                var js = new Joystick(windowHandle);
                js.AcquireJoystick(joystickName);
                _wizard.AddJoystick(js);
                _joysticks.Add(js);
            }

            _vm = new JoysticksVM();
            DataContext = _vm;

            for (int i = 0; i < _joysticks.Count; i++)
            {
                var joystickVM = new JoystickAxesVM { JoystickName = joystickNames[i] };
                _vm.Devices.Add(joystickVM);
            }


            _wizardUpdateTimer = new Timer(0.1);
            _wizardUpdateTimer.Elapsed += JoystickUpdateTimerElapsed;
            _wizardUpdateTimer.Start();

            Closing += Window1_Closing;
        }