Commit MetaInfo

Revisão3aea0937c20785da028aa5fafc8f281777cff5cc (tree)
Hora2020-03-04 05:23:51
AutorDavid Ludwig <dludwig@pobo...>
CommiterDavid Ludwig

Mensagem de Log

add UI for vjoy detachment

Mudança Sumário

Diff

diff -r 6a5b9a3de325 -r 3aea0937c207 main.cpp
--- a/main.cpp Tue Mar 03 13:35:38 2020 -0500
+++ b/main.cpp Tue Mar 03 15:23:51 2020 -0500
@@ -58,12 +58,12 @@
5858
5959 // TODO: persist these on-disk
6060 #if DEV_DAVIDL
61-static bool autoCreateVirtualJoystick = true;
61+static bool autoCreateVirtualJoystick = false;
6262 #else
6363 static bool autoCreateVirtualJoystick = false;
6464 #endif
6565 static bool autoOpenJoysticks = false;
66-static bool autoOpenGameControllers = true;
66+static bool autoOpenGameControllers = false;
6767 static bool showGameControllerMappingUnformatted = false;
6868 static bool showWindowImGuiDemo = false;
6969 static bool showWindowJoysticks = true;
@@ -109,7 +109,7 @@
109109
110110 const NamedColumn joystickWindowColumns[] = {
111111 { 35.f, "" },
112- { 60.f, "Actions" },
112+ { 115.f, "Actions" },
113113 { 55.f, "Device\nIndex" },
114114 { 250.f, "Name" },
115115 { 60.f, "Player\nIndex" },
@@ -394,6 +394,7 @@
394394 ImGui::PushID(device_index);
395395 SDL_JoystickID device_instance_id = SDL_JoystickGetDeviceInstanceID(device_index);
396396 SDL_Joystick * joystick = SDL_JoystickFromInstanceID(device_instance_id);
397+ SDL_GameController * controller = SDL_GameControllerFromInstanceID(device_instance_id);
397398
398399 ImGuiTreeNodeFlags tree_node_flags = 0;
399400 if (joystick) {
@@ -419,12 +420,32 @@
419420 }
420421 } else {
421422 if (ImGui::Button("Close")) {
423+ if (controller) {
424+ SDL_GameControllerClose(controller);
425+ controller = nullptr;
426+ }
422427 SDL_JoystickClose(joystick);
423428 joystick = nullptr;
424429 device_instance_id = SDL_JoystickGetDeviceInstanceID(device_index);
425430 }
426431 }
427432 #endif
433+#if SDL_JOYSTICK_VIRTUAL
434+ SDL_bool isVirtual = SDL_JoystickIsVirtual(device_index);
435+#else
436+ SDL_bool isVirtual = SDL_FALSE;
437+#endif
438+ if (isVirtual) {
439+ ImGui::SameLine();
440+ if (ImGui::Button("Detach")) {
441+#if SDL_JOYSTICK_VIRTUAL
442+ if (SDL_JoystickDetachVirtual(device_index) != 0) {
443+ printf("Detach failed: %s\n", SDL_GetError());
444+ }
445+#endif
446+ }
447+ }
448+
428449 ImGui::NextColumn();
429450
430451 ImGui::Text("%d", device_index);
@@ -445,11 +466,6 @@
445466 ImGui::Text("%d", (int)SDL_JoystickGetDeviceInstanceID(device_index));
446467 ImGui::NextColumn();
447468
448-#if SDL_JOYSTICK_VIRTUAL
449- const SDL_bool isVirtual = SDL_JoystickIsVirtual(device_index);
450-#else
451- const SDL_bool isVirtual = SDL_FALSE;
452-#endif
453469 ImGui::Text("%s", (isVirtual == SDL_TRUE ? "YES" : "NO"));
454470 ImGui::NextColumn();
455471
Show on old repository browser