diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 28 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_poller.cpp | 25 | ||||
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 26 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 85 |
4 files changed, 99 insertions, 65 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 4d1052414..9670bdeb2 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -139,10 +139,10 @@ void GCButtonFactory::EndConfiguration() { | |||
| 139 | 139 | ||
| 140 | class GCAnalog final : public Input::AnalogDevice { | 140 | class GCAnalog final : public Input::AnalogDevice { |
| 141 | public: | 141 | public: |
| 142 | explicit GCAnalog(u32 port_, u32 axis_x_, u32 axis_y_, float deadzone_, | 142 | explicit GCAnalog(u32 port_, u32 axis_x_, u32 axis_y_, bool invert_x_, bool invert_y_, |
| 143 | const GCAdapter::Adapter* adapter, float range_) | 143 | float deadzone_, float range_, const GCAdapter::Adapter* adapter) |
| 144 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter), | 144 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), invert_x(invert_x_), invert_y(invert_y_), |
| 145 | range(range_) {} | 145 | deadzone(deadzone_), range(range_), gcadapter(adapter) {} |
| 146 | 146 | ||
| 147 | float GetAxis(u32 axis) const { | 147 | float GetAxis(u32 axis) const { |
| 148 | if (gcadapter->DeviceConnected(port)) { | 148 | if (gcadapter->DeviceConnected(port)) { |
| @@ -157,7 +157,12 @@ public: | |||
| 157 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { | 157 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { |
| 158 | float x = GetAxis(analog_axis_x); | 158 | float x = GetAxis(analog_axis_x); |
| 159 | float y = GetAxis(analog_axis_y); | 159 | float y = GetAxis(analog_axis_y); |
| 160 | 160 | if (invert_x) { | |
| 161 | x = -x; | ||
| 162 | } | ||
| 163 | if (invert_y) { | ||
| 164 | y = -y; | ||
| 165 | } | ||
| 161 | // Make sure the coordinates are in the unit circle, | 166 | // Make sure the coordinates are in the unit circle, |
| 162 | // otherwise normalize it. | 167 | // otherwise normalize it. |
| 163 | float r = x * x + y * y; | 168 | float r = x * x + y * y; |
| @@ -200,9 +205,11 @@ private: | |||
| 200 | const u32 port; | 205 | const u32 port; |
| 201 | const u32 axis_x; | 206 | const u32 axis_x; |
| 202 | const u32 axis_y; | 207 | const u32 axis_y; |
| 208 | const bool invert_x; | ||
| 209 | const bool invert_y; | ||
| 203 | const float deadzone; | 210 | const float deadzone; |
| 204 | const GCAdapter::Adapter* gcadapter; | ||
| 205 | const float range; | 211 | const float range; |
| 212 | const GCAdapter::Adapter* gcadapter; | ||
| 206 | mutable std::mutex mutex; | 213 | mutable std::mutex mutex; |
| 207 | }; | 214 | }; |
| 208 | 215 | ||
| @@ -223,8 +230,13 @@ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::Param | |||
| 223 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); | 230 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 224 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 231 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 225 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 232 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 233 | const std::string invert_x_value = params.Get("invert_x", "+"); | ||
| 234 | const std::string invert_y_value = params.Get("invert_y", "+"); | ||
| 235 | const bool invert_x = invert_x_value == "-"; | ||
| 236 | const bool invert_y = invert_y_value == "-"; | ||
| 226 | 237 | ||
| 227 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get(), range); | 238 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, invert_x, invert_y, deadzone, range, |
| 239 | adapter.get()); | ||
| 228 | } | 240 | } |
| 229 | 241 | ||
| 230 | void GCAnalogFactory::BeginConfiguration() { | 242 | void GCAnalogFactory::BeginConfiguration() { |
| @@ -282,6 +294,8 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 282 | params.Set("port", controller_number); | 294 | params.Set("port", controller_number); |
| 283 | params.Set("axis_x", analog_x_axis); | 295 | params.Set("axis_x", analog_x_axis); |
| 284 | params.Set("axis_y", analog_y_axis); | 296 | params.Set("axis_y", analog_y_axis); |
| 297 | params.Set("invert_x", "+"); | ||
| 298 | params.Set("invert_y", "+"); | ||
| 285 | analog_x_axis = -1; | 299 | analog_x_axis = -1; |
| 286 | analog_y_axis = -1; | 300 | analog_y_axis = -1; |
| 287 | controller_number = -1; | 301 | controller_number = -1; |
diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp index 7445ad3ad..508eb0c7d 100644 --- a/src/input_common/mouse/mouse_poller.cpp +++ b/src/input_common/mouse/mouse_poller.cpp | |||
| @@ -62,10 +62,10 @@ void MouseButtonFactory::EndConfiguration() { | |||
| 62 | 62 | ||
| 63 | class MouseAnalog final : public Input::AnalogDevice { | 63 | class MouseAnalog final : public Input::AnalogDevice { |
| 64 | public: | 64 | public: |
| 65 | explicit MouseAnalog(u32 port_, u32 axis_x_, u32 axis_y_, float deadzone_, float range_, | 65 | explicit MouseAnalog(u32 port_, u32 axis_x_, u32 axis_y_, bool invert_x_, bool invert_y_, |
| 66 | const MouseInput::Mouse* mouse_input_) | 66 | float deadzone_, float range_, const MouseInput::Mouse* mouse_input_) |
| 67 | : button(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), range(range_), | 67 | : button(port_), axis_x(axis_x_), axis_y(axis_y_), invert_x(invert_x_), invert_y(invert_y_), |
| 68 | mouse_input(mouse_input_) {} | 68 | deadzone(deadzone_), range(range_), mouse_input(mouse_input_) {} |
| 69 | 69 | ||
| 70 | float GetAxis(u32 axis) const { | 70 | float GetAxis(u32 axis) const { |
| 71 | std::lock_guard lock{mutex}; | 71 | std::lock_guard lock{mutex}; |
| @@ -77,6 +77,12 @@ public: | |||
| 77 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { | 77 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { |
| 78 | float x = GetAxis(analog_axis_x); | 78 | float x = GetAxis(analog_axis_x); |
| 79 | float y = GetAxis(analog_axis_y); | 79 | float y = GetAxis(analog_axis_y); |
| 80 | if (invert_x) { | ||
| 81 | x = -x; | ||
| 82 | } | ||
| 83 | if (invert_y) { | ||
| 84 | y = -y; | ||
| 85 | } | ||
| 80 | 86 | ||
| 81 | // Make sure the coordinates are in the unit circle, | 87 | // Make sure the coordinates are in the unit circle, |
| 82 | // otherwise normalize it. | 88 | // otherwise normalize it. |
| @@ -104,6 +110,8 @@ private: | |||
| 104 | const u32 button; | 110 | const u32 button; |
| 105 | const u32 axis_x; | 111 | const u32 axis_x; |
| 106 | const u32 axis_y; | 112 | const u32 axis_y; |
| 113 | const bool invert_x; | ||
| 114 | const bool invert_y; | ||
| 107 | const float deadzone; | 115 | const float deadzone; |
| 108 | const float range; | 116 | const float range; |
| 109 | const MouseInput::Mouse* mouse_input; | 117 | const MouseInput::Mouse* mouse_input; |
| @@ -128,8 +136,13 @@ std::unique_ptr<Input::AnalogDevice> MouseAnalogFactory::Create( | |||
| 128 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); | 136 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 129 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 137 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 130 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 138 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 139 | const std::string invert_x_value = params.Get("invert_x", "+"); | ||
| 140 | const std::string invert_y_value = params.Get("invert_y", "+"); | ||
| 141 | const bool invert_x = invert_x_value == "-"; | ||
| 142 | const bool invert_y = invert_y_value == "-"; | ||
| 131 | 143 | ||
| 132 | return std::make_unique<MouseAnalog>(port, axis_x, axis_y, deadzone, range, mouse_input.get()); | 144 | return std::make_unique<MouseAnalog>(port, axis_x, axis_y, invert_x, invert_y, deadzone, range, |
| 145 | mouse_input.get()); | ||
| 133 | } | 146 | } |
| 134 | 147 | ||
| 135 | void MouseAnalogFactory::BeginConfiguration() { | 148 | void MouseAnalogFactory::BeginConfiguration() { |
| @@ -153,6 +166,8 @@ Common::ParamPackage MouseAnalogFactory::GetNextInput() const { | |||
| 153 | params.Set("port", static_cast<u16>(pad.button)); | 166 | params.Set("port", static_cast<u16>(pad.button)); |
| 154 | params.Set("axis_x", 0); | 167 | params.Set("axis_x", 0); |
| 155 | params.Set("axis_y", 1); | 168 | params.Set("axis_y", 1); |
| 169 | params.Set("invert_x", "+"); | ||
| 170 | params.Set("invert_y", "+"); | ||
| 156 | return params; | 171 | return params; |
| 157 | } | 172 | } |
| 158 | } | 173 | } |
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 7827e324c..0b531f698 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -352,13 +352,20 @@ private: | |||
| 352 | class SDLAnalog final : public Input::AnalogDevice { | 352 | class SDLAnalog final : public Input::AnalogDevice { |
| 353 | public: | 353 | public: |
| 354 | explicit SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, | 354 | explicit SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, |
| 355 | float deadzone_, float range_) | 355 | bool invert_x_, bool invert_y_, float deadzone_, float range_) |
| 356 | : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), | 356 | : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), invert_x(invert_x_), |
| 357 | range(range_) {} | 357 | invert_y(invert_y_), deadzone(deadzone_), range(range_) {} |
| 358 | 358 | ||
| 359 | std::tuple<float, float> GetStatus() const override { | 359 | std::tuple<float, float> GetStatus() const override { |
| 360 | const auto [x, y] = joystick->GetAnalog(axis_x, axis_y, range); | 360 | auto [x, y] = joystick->GetAnalog(axis_x, axis_y, range); |
| 361 | const float r = std::sqrt((x * x) + (y * y)); | 361 | const float r = std::sqrt((x * x) + (y * y)); |
| 362 | if (invert_x) { | ||
| 363 | x = -x; | ||
| 364 | } | ||
| 365 | if (invert_y) { | ||
| 366 | y = -y; | ||
| 367 | } | ||
| 368 | |||
| 362 | if (r > deadzone) { | 369 | if (r > deadzone) { |
| 363 | return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), | 370 | return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), |
| 364 | y / r * (r - deadzone) / (1 - deadzone)); | 371 | y / r * (r - deadzone) / (1 - deadzone)); |
| @@ -386,6 +393,8 @@ private: | |||
| 386 | std::shared_ptr<SDLJoystick> joystick; | 393 | std::shared_ptr<SDLJoystick> joystick; |
| 387 | const int axis_x; | 394 | const int axis_x; |
| 388 | const int axis_y; | 395 | const int axis_y; |
| 396 | const bool invert_x; | ||
| 397 | const bool invert_y; | ||
| 389 | const float deadzone; | 398 | const float deadzone; |
| 390 | const float range; | 399 | const float range; |
| 391 | }; | 400 | }; |
| @@ -572,12 +581,17 @@ public: | |||
| 572 | const int axis_y = params.Get("axis_y", 1); | 581 | const int axis_y = params.Get("axis_y", 1); |
| 573 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 582 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 574 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 583 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 584 | const std::string invert_x_value = params.Get("invert_x", "+"); | ||
| 585 | const std::string invert_y_value = params.Get("invert_y", "+"); | ||
| 586 | const bool invert_x = invert_x_value == "-"; | ||
| 587 | const bool invert_y = invert_y_value == "-"; | ||
| 575 | auto joystick = state.GetSDLJoystickByGUID(guid, port); | 588 | auto joystick = state.GetSDLJoystickByGUID(guid, port); |
| 576 | 589 | ||
| 577 | // This is necessary so accessing GetAxis with axis_x and axis_y won't crash | 590 | // This is necessary so accessing GetAxis with axis_x and axis_y won't crash |
| 578 | joystick->SetAxis(axis_x, 0); | 591 | joystick->SetAxis(axis_x, 0); |
| 579 | joystick->SetAxis(axis_y, 0); | 592 | joystick->SetAxis(axis_y, 0); |
| 580 | return std::make_unique<SDLAnalog>(joystick, axis_x, axis_y, deadzone, range); | 593 | return std::make_unique<SDLAnalog>(joystick, axis_x, axis_y, invert_x, invert_y, deadzone, |
| 594 | range); | ||
| 581 | } | 595 | } |
| 582 | 596 | ||
| 583 | private: | 597 | private: |
| @@ -886,6 +900,8 @@ Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& gui | |||
| 886 | params.Set("guid", guid); | 900 | params.Set("guid", guid); |
| 887 | params.Set("axis_x", axis_x); | 901 | params.Set("axis_x", axis_x); |
| 888 | params.Set("axis_y", axis_y); | 902 | params.Set("axis_y", axis_y); |
| 903 | params.Set("invert_x", "+"); | ||
| 904 | params.Set("invert_y", "+"); | ||
| 889 | return params; | 905 | return params; |
| 890 | } | 906 | } |
| 891 | } // Anonymous namespace | 907 | } // Anonymous namespace |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index f9915fb7a..3c7500ee3 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -173,61 +173,31 @@ QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) | |||
| 173 | return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); | 173 | return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | if (param.Get("engine", "") == "sdl") { | 176 | const auto engine_str = param.Get("engine", ""); |
| 177 | const QString axis_x_str = QString::fromStdString(param.Get("axis_x", "")); | ||
| 178 | const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); | ||
| 179 | const bool invert_x = param.Get("invert_x", "+") == "-"; | ||
| 180 | const bool invert_y = param.Get("invert_y", "+") == "-"; | ||
| 181 | if (engine_str == "sdl" || engine_str == "gcpad" || engine_str == "mouse") { | ||
| 177 | if (dir == "modifier") { | 182 | if (dir == "modifier") { |
| 178 | return QObject::tr("[unused]"); | 183 | return QObject::tr("[unused]"); |
| 179 | } | 184 | } |
| 180 | 185 | ||
| 181 | if (dir == "left" || dir == "right") { | 186 | if (dir == "left") { |
| 182 | const QString axis_x_str = QString::fromStdString(param.Get("axis_x", "")); | 187 | const QString invert_x_str = QString::fromStdString(invert_x ? "+" : "-"); |
| 183 | 188 | return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str); | |
| 184 | return QObject::tr("Axis %1").arg(axis_x_str); | ||
| 185 | } | ||
| 186 | |||
| 187 | if (dir == "up" || dir == "down") { | ||
| 188 | const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); | ||
| 189 | |||
| 190 | return QObject::tr("Axis %1").arg(axis_y_str); | ||
| 191 | } | 189 | } |
| 192 | 190 | if (dir == "right") { | |
| 193 | return {}; | 191 | const QString invert_x_str = QString::fromStdString(invert_x ? "-" : "+"); |
| 194 | } | 192 | return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str); |
| 195 | |||
| 196 | if (param.Get("engine", "") == "gcpad") { | ||
| 197 | if (dir == "modifier") { | ||
| 198 | return QObject::tr("[unused]"); | ||
| 199 | } | 193 | } |
| 200 | 194 | if (dir == "up") { | |
| 201 | if (dir == "left" || dir == "right") { | 195 | const QString invert_y_str = QString::fromStdString(invert_y ? "-" : "+"); |
| 202 | const QString axis_x_str = QString::fromStdString(param.Get("axis_x", "")); | 196 | return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str); |
| 203 | |||
| 204 | return QObject::tr("GC Axis %1").arg(axis_x_str); | ||
| 205 | } | 197 | } |
| 206 | 198 | if (dir == "down") { | |
| 207 | if (dir == "up" || dir == "down") { | 199 | const QString invert_y_str = QString::fromStdString(invert_y ? "+" : "-"); |
| 208 | const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); | 200 | return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str); |
| 209 | |||
| 210 | return QObject::tr("GC Axis %1").arg(axis_y_str); | ||
| 211 | } | ||
| 212 | |||
| 213 | return {}; | ||
| 214 | } | ||
| 215 | |||
| 216 | if (param.Get("engine", "") == "mouse") { | ||
| 217 | if (dir == "modifier") { | ||
| 218 | return QObject::tr("[unused]"); | ||
| 219 | } | ||
| 220 | |||
| 221 | if (dir == "left" || dir == "right") { | ||
| 222 | const QString axis_x_str = QString::fromStdString(param.Get("axis_x", "")); | ||
| 223 | |||
| 224 | return QObject::tr("Mouse %1").arg(axis_x_str); | ||
| 225 | } | ||
| 226 | |||
| 227 | if (dir == "up" || dir == "down") { | ||
| 228 | const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); | ||
| 229 | |||
| 230 | return QObject::tr("Mouse %1").arg(axis_y_str); | ||
| 231 | } | 201 | } |
| 232 | 202 | ||
| 233 | return {}; | 203 | return {}; |
| @@ -396,6 +366,25 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 396 | analogs_param[analog_id].Clear(); | 366 | analogs_param[analog_id].Clear(); |
| 397 | analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); | 367 | analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); |
| 398 | }); | 368 | }); |
| 369 | context_menu.addAction(tr("Invert axis"), [&] { | ||
| 370 | if (sub_button_id == 2 || sub_button_id == 3) { | ||
| 371 | const bool invert_value = | ||
| 372 | analogs_param[analog_id].Get("invert_x", "+") == "-"; | ||
| 373 | const std::string invert_str = invert_value ? "+" : "-"; | ||
| 374 | analogs_param[analog_id].Set("invert_x", invert_str); | ||
| 375 | } | ||
| 376 | if (sub_button_id == 0 || sub_button_id == 1) { | ||
| 377 | const bool invert_value = | ||
| 378 | analogs_param[analog_id].Get("invert_y", "+") == "-"; | ||
| 379 | const std::string invert_str = invert_value ? "+" : "-"; | ||
| 380 | analogs_param[analog_id].Set("invert_y", invert_str); | ||
| 381 | } | ||
| 382 | for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; | ||
| 383 | ++sub_button_id) { | ||
| 384 | analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText( | ||
| 385 | analogs_param[analog_id], analog_sub_buttons[sub_button_id])); | ||
| 386 | } | ||
| 387 | }); | ||
| 399 | context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal( | 388 | context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal( |
| 400 | menu_location)); | 389 | menu_location)); |
| 401 | }); | 390 | }); |