From f3ddb9d5c788dbd98670116f16ada9a4764bc974 Mon Sep 17 00:00:00 2001 From: Bryant Date: Fri, 14 Jun 2013 16:54:40 -0700 Subject: [PATCH] The UI now updates properly for when a detected joystick is lacking either buttons or axes (as in the case of an in-built accelerometer). --- src/ui/JoystickWidget.cc | 42 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/ui/JoystickWidget.cc b/src/ui/JoystickWidget.cc index 0ecb484b9..efaa82197 100644 --- a/src/ui/JoystickWidget.cc +++ b/src/ui/JoystickWidget.cc @@ -119,24 +119,40 @@ void JoystickWidget::updateUIForJoystick(int id) // And add the necessary button displays for this joystick. int newButtons = joystick->getJoystickNumButtons(); - for (int i = 0; i < newButtons; i++) + if (newButtons) { - JoystickButton* button = new JoystickButton(i, m_ui->buttonBox); - // And make sure we insert BEFORE the vertical spacer. - m_ui->buttonLayout->insertWidget(i, button); - buttons.append(button); + m_ui->buttonBox->show(); + for (int i = 0; i < newButtons; i++) + { + JoystickButton* button = new JoystickButton(i, m_ui->buttonBox); + // And make sure we insert BEFORE the vertical spacer. + m_ui->buttonLayout->insertWidget(i, button); + buttons.append(button); + } + } + else + { + m_ui->buttonBox->hide(); } // Do the same for the axes supported by this joystick. - for (int i = 0; i < joystick->getJoystickNumAxes(); i++) + int newAxes = joystick->getJoystickNumAxes(); + if (newAxes) + { + for (int i = 0; i < newAxes; i++) + { + JoystickAxis* axis = new JoystickAxis(i, m_ui->axesBox); + axis->setValue(joystick->getCurrentValueForAxis(i)); + connect(axis, SIGNAL(mappingChanged(int,JoystickInput::JOYSTICK_INPUT_MAPPING)), this->joystick, SLOT(setAxisMapping(int,JoystickInput::JOYSTICK_INPUT_MAPPING))); + connect(axis, SIGNAL(inversionChanged(int,bool)), this->joystick, SLOT(setAxisInversion(int,bool))); + // And make sure we insert BEFORE the vertical spacer. + m_ui->axesLayout->insertWidget(i, axis); + axes.append(axis); + } + } + else { - JoystickAxis* axis = new JoystickAxis(i, m_ui->axesBox); - axis->setValue(joystick->getCurrentValueForAxis(i)); - connect(axis, SIGNAL(mappingChanged(int,JoystickInput::JOYSTICK_INPUT_MAPPING)), this->joystick, SLOT(setAxisMapping(int,JoystickInput::JOYSTICK_INPUT_MAPPING))); - connect(axis, SIGNAL(inversionChanged(int,bool)), this->joystick, SLOT(setAxisInversion(int,bool))); - // And make sure we insert BEFORE the vertical spacer. - m_ui->axesLayout->insertWidget(i, axis); - axes.append(axis); + m_ui->buttonBox->hide(); } } -- 2.22.0