diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 8835bc134b..03a95e82eb 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -316,26 +316,32 @@ bool KeyMappingNewKeyDialog::key(const KeyInput &key) { return true; } -bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) { - if (mapped_) - return false; - switch (axis.axisId) { - // Ignore the accelerometer for mapping for now. +static bool IgnoreAxisForMapping(int axis) { + switch (axis) { + // Ignore the accelerometer for mapping for now. case JOYSTICK_AXIS_ACCELEROMETER_X: case JOYSTICK_AXIS_ACCELEROMETER_Y: case JOYSTICK_AXIS_ACCELEROMETER_Z: - return false; + return true; - // Also ignore some weird axis events we get on Ouya. + // Also ignore some weird axis events we get on Ouya. case JOYSTICK_AXIS_OUYA_UNKNOWN1: case JOYSTICK_AXIS_OUYA_UNKNOWN2: case JOYSTICK_AXIS_OUYA_UNKNOWN3: case JOYSTICK_AXIS_OUYA_UNKNOWN4: - return false; + return true; default: - ; + return false; } +} + + +bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) { + if (mapped_) + return false; + if (IgnoreAxisForMapping(axis.axisId)) + return false; if (axis.value > AXIS_BIND_THRESHOLD) { mapped_ = true; @@ -437,8 +443,10 @@ bool AnalogTestScreen::key(const KeyInput &key) { (key.flags & KEY_UP) ? "UP" : "", (key.flags & KEY_DOWN) ? "DOWN" : "", (key.flags & KEY_CHAR) ? "CHAR" : ""); - lastLastKeyEvent_->SetText(lastKeyEvent_->GetText()); - lastKeyEvent_->SetText(buf); + if (lastLastKeyEvent_ && lastKeyEvent_) { + lastLastKeyEvent_->SetText(lastKeyEvent_->GetText()); + lastKeyEvent_->SetText(buf); + } return retval; } @@ -448,11 +456,18 @@ bool AnalogTestScreen::axis(const AxisInput &axis) { // into arrow keys, since seeing keyboard arrow key events appear when using // a controller would be confusing for the user. char buf[512]; + + if (IgnoreAxisForMapping(axis.axisId)) + return false; + if (axis.value > AXIS_BIND_THRESHOLD || axis.value < -AXIS_BIND_THRESHOLD) { snprintf(buf, sizeof(buf), "Axis: %d (value %1.3f) Device ID: %d", axis.axisId, axis.value, axis.deviceId); - lastLastKeyEvent_->SetText(lastKeyEvent_->GetText()); - lastKeyEvent_->SetText(buf); + // Null-check just in case they weren't created yet. + if (lastLastKeyEvent_ && lastKeyEvent_) { + lastLastKeyEvent_->SetText(lastKeyEvent_->GetText()); + lastKeyEvent_->SetText(buf); + } return true; } return false;