Esempio n. 1
0
        private InputVariable FindAxis(Controller controller, Guid axisType, string axisName, int number)
        {
            InputVariable result = null;
            AxisType      axis   = AxisTypeUtils.ObjectGuidTypeToAxisType(axisType, number);

            if (controller.Variables != null)
            {
                for (int i = 0; i < controller.Variables.Length; i++)
                {
                    if (controller.Variables[i].InputType == InputType.Axis)
                    {
                        if (((IAxis)controller.Variables[i]).SliderType == axis)
                        {
                            result = controller.Variables[i];
                            break;
                        }
                    }
                }
            }
            if (result == null)
            {
                result = new SimpleAxisInput()
                {
                    Controller  = controller,
                    Description = "",
                    ID          = string.Format("axis_{0}", axis.ToString()),
                    AxisName    = axisName,
                    Max         = 100,
                    Min         = 0,
                    Reverse     = false,
                    SliderType  = axis
                };
            }
            return(result);
        }
Esempio n. 2
0
        private void ShowSelected()
        {
            StopListening();

            if (!SaveCurrent())
            {
                _ingoreSelecting        = true;
                comboBox1.SelectedIndex = _lastIndex;
                _ingoreSelecting        = false;
                //return;
            }

            // wyczyszczenie
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            dataGridView1.Rows.Clear();
            dataGridView2.Rows.Clear();
            radioButton1.Checked = true;
            radioButton2.Checked = false;
            numericUpDown1.Value = 20;

            _lastIndex = comboBox1.SelectedIndex;

            Ctrl c = comboBox1.SelectedItem as Ctrl;

            if (c != null)
            {
                // poszukanie odpowiednika w konfiguracji
                _controller = FindController(c);

                textBox1.Text = _controller.Alias;
                textBox2.Text = _controller.Id.ToString();
                textBox3.Text = _controller.Index.ToString();
                if (_controller.UpdateType == UpdateStateType.ByChecking)
                {
                    radioButton2.Checked = true;
                }
                numericUpDown1.Value = _controller.ReadingStateInterval;

                // odczytanie systemowych informacji o kontrolerze
                if (_device != null)
                {
                    _device.Dispose();
                    _device = null;
                }
                if (c.Connected)
                {
                    _device        = new Device(c.ID);
                    _buttonsStates = new bool?[_device.Caps.NumberButtons];
                    _hatsStates    = new int[_device.Caps.NumberPointOfViews];
                    for (int i = 0; i < _hatsStates.Length; i++)
                    {
                        _hatsStates[i] = -2;
                    }
                    _axes = new int[8];
                }
                else
                {
                    _buttonsStates = new bool?[_controller.NumberOfObjects(InputType.Button)];
                    _hatsStates    = new int[_controller.NumberOfObjects(InputType.HATSwitch)];
                    for (int i = 0; i < _hatsStates.Length; i++)
                    {
                        _hatsStates[i] = -2;
                    }
                    _axes = new int[8];
                }

                textBox4.Text = c.Connected ? "podłączony" : "niepodłączony";

                // pokazanie konfiguracji przycisków

                // zwykłe przyciski
                for (int i = 0; i < _buttonsStates.Length; i++)
                {
                    int           index = 0;
                    InputVariable iv    = FindButton(_controller, i);
                    if (iv is IRepeatable)
                    {
                        index = dataGridView1.Rows.Add(string.Format("przycisk_{0}", i.ToString("000")), "False", iv.InternalID, iv.Description, iv.InputType, iv.Type, true, ((IRepeatable)iv).RepeatAfter, ((IRepeatable)iv).RepeatInterval);
                    }
                    else
                    {
                        index = dataGridView1.Rows.Add(string.Format("przycisk_{0}", i.ToString("000")), "False", iv.InternalID, iv.Description, iv.InputType, iv.Type, false, 250, 100);
                        dataGridView1.Rows[index].Cells[_powtarzajPo.Index].ReadOnly = true;
                        dataGridView1.Rows[index].Cells[_powtarzajCo.Index].ReadOnly = true;
                    }
                    dataGridView1.Rows[index].Tag = iv;
                }
                // przyciski HAT
                for (int i = 0; i < _hatsStates.Length; i++)
                {
                    int           index = 0;
                    InputVariable iv    = FindHAT(_controller, i);
                    if (iv is IRepeatable)
                    {
                        index = dataGridView1.Rows.Add(string.Format("hat_{0}", i.ToString("000")), "-1", iv.InternalID, iv.Description, iv.InputType, iv.Type, true, ((IRepeatable)iv).RepeatAfter, ((IRepeatable)iv).RepeatInterval);
                    }
                    else
                    {
                        index = dataGridView1.Rows.Add(string.Format("hat_{0}", i.ToString("000")), "-1", iv.InternalID, iv.Description, iv.InputType, iv.Type, false, 250, 100);
                        dataGridView1.Rows[index].Cells[_powtarzajPo.Index].ReadOnly = true;
                        dataGridView1.Rows[index].Cells[_powtarzajCo.Index].ReadOnly = true;
                    }
                    dataGridView1.Rows[index].Tag = iv;
                }

                dataGridView1.PerformLayout();

                // pokazanie konfiguracji osi
                if (_device != null)
                {
                    List <Guid> axes     = new List <Guid>();
                    int         extCount = 0;
                    Microsoft.DirectX.DirectInput.DeviceObjectList list = _device.GetObjects(Microsoft.DirectX.DirectInput.DeviceObjectTypeFlags.Axis);
                    foreach (Microsoft.DirectX.DirectInput.DeviceObjectInstance o in list)
                    {
                        if (AxisTypeUtils.IsProperGuidForAxis(o.ObjectType))
                        {
                            if (axes.Contains(o.ObjectType))
                            {
                                continue;
                            }
                            _device.Properties.SetRange(Microsoft.DirectX.DirectInput.ParameterHow.ById, o.ObjectId, new Microsoft.DirectX.DirectInput.InputRange(0, iAXIS_MAX));
                            InputVariable iv    = FindAxis(_controller, o.ObjectType, o.Name, extCount);
                            int           index = dataGridView2.Rows.Add(o.Name, iv.InternalID, iv.Description, ((IAxis)iv).Reverse, ((IAxis)iv).Min, ((IAxis)iv).Max, 0);
                            dataGridView2.Rows[index].Tag = iv;
                            if (o.ObjectType == Microsoft.DirectX.DirectInput.ObjectTypeGuid.Slider)
                            {
                                extCount++;
                            }
                        }
                    }
                }
                else
                {
                    // kontroler nie jest podłączony
                    for (int i = 0; i < _controller.Variables.Length; i++)
                    {
                        if (_controller.Variables[i].InputType == InputType.Axis)
                        {
                            InputVariable iv    = _controller.Variables[i];
                            int           index = dataGridView2.Rows.Add(((IAxis)iv).AxisName, iv.InternalID, iv.Description, ((IAxis)iv).Reverse, ((IAxis)iv).Min, ((IAxis)iv).Max, 0);
                            dataGridView2.Rows[index].Tag = iv;
                        }
                    }
                }

                dataGridView2.PerformLayout();

                StartListening();
            }
        }