/** * Creates a button device from a joystick button * @param params contains parameters for creating the device: * - "joystick": the index of the joystick to bind * - "button"(optional): the index of the button to bind * - "hat"(optional): the index of the hat to bind as direction buttons * - "axis"(optional): the index of the axis to bind * - "direction"(only used for hat): the direction name of the hat to bind. Can be "up", * "down", "left" or "right" * - "threshold"(only used for axis): a float value in (-1.0, 1.0) which the button is * triggered if the axis value crosses * - "direction"(only used for axis): "+" means the button is triggered when the axis value * is greater than the threshold; "-" means the button is triggered when the axis value * is smaller than the threshold */ std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override { const int joystick_index = params.Get("joystick", 0); if (params.Has("hat")) { const int hat = params.Get("hat", 0); const std::string direction_name = params.Get("direction", ""); Uint8 direction; if (direction_name == "up") { direction = SDL_HAT_UP; } else if (direction_name == "down") { direction = SDL_HAT_DOWN; } else if (direction_name == "left") { direction = SDL_HAT_LEFT; } else if (direction_name == "right") { direction = SDL_HAT_RIGHT; } else { direction = 0; } return std::make_unique<SDLDirectionButton>(GetJoystick(joystick_index), hat, direction); } if (params.Has("axis")) { const int axis = params.Get("axis", 0); const float threshold = params.Get("threshold", 0.5f); const std::string direction_name = params.Get("direction", ""); bool trigger_if_greater; if (direction_name == "+") { trigger_if_greater = true; } else if (direction_name == "-") { trigger_if_greater = false; } else { trigger_if_greater = true; LOG_ERROR(Input, "Unknown direction %s", direction_name.c_str()); } return std::make_unique<SDLAxisButton>(GetJoystick(joystick_index), axis, threshold, trigger_if_greater); } const int button = params.Get("button", 0); return std::make_unique<SDLButton>(GetJoystick(joystick_index), button); }
ConfigureInput::ConfigureInput(QWidget* parent) : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()), timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) { ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); button_map = { ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR, ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome, }; analog_map_buttons = {{ { ui->buttonCircleUp, ui->buttonCircleDown, ui->buttonCircleLeft, ui->buttonCircleRight, ui->buttonCircleMod, }, { ui->buttonCStickUp, ui->buttonCStickDown, ui->buttonCStickLeft, ui->buttonCStickRight, nullptr, }, }}; analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog}; for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { if (button_map[button_id]) connect(button_map[button_id], &QPushButton::released, [=]() { handleClick( button_map[button_id], [=](const Common::ParamPackage& params) { buttons_param[button_id] = params; }, InputCommon::Polling::DeviceType::Button); }); } for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { if (analog_map_buttons[analog_id][sub_button_id] != nullptr) { connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { handleClick(analog_map_buttons[analog_id][sub_button_id], [=](const Common::ParamPackage& params) { SetAnalogButton(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]); }, InputCommon::Polling::DeviceType::Button); }); } } connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { QMessageBox::information( this, "Information", "After pressing OK, first move your joystick horizontally, and then vertically."); handleClick( analog_map_stick[analog_id], [=](const Common::ParamPackage& params) { analogs_param[analog_id] = params; }, InputCommon::Polling::DeviceType::Analog); }); } connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); timeout_timer->setSingleShot(true); connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); }); connect(poll_timer.get(), &QTimer::timeout, [this]() { Common::ParamPackage params; for (auto& poller : device_pollers) { params = poller->GetNextInput(); if (params.Has("engine")) { setPollingResult(params, false); return; } } }); this->loadConfiguration(); // TODO(wwylele): enable this when we actually emulate it ui->buttonHome->setEnabled(false); }