Commit MetaInfo

Revisão93a27092163b02e4498fe4d84bcd50cbc7ca289f (tree)
Hora2020-03-01 07:52:40
AutorDavid Ludwig <dludwig@pobo...>
CommiterDavid Ludwig

Mensagem de Log

allow building against SDL without Virtual Joystick support

Mudança Sumário

Diff

diff -r 2e785b10556b -r 93a27092163b main.cpp
--- a/main.cpp Sat Feb 29 17:44:40 2020 -0500
+++ b/main.cpp Sat Feb 29 17:52:40 2020 -0500
@@ -101,7 +101,9 @@
101101 { SDL_CONTROLLER_TYPE_PS3, "PS3" },
102102 { SDL_CONTROLLER_TYPE_PS4, "PS4" },
103103 { SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO, "Nintendo Switch Pro" },
104- { SDL_CONTROLLER_TYPE_VIRTUAL, "Virtual" },
104+#if SDL_JOYSTICK_VIRTUAL
105+ // { SDL_CONTROLLER_TYPE_VIRTUAL, "Virtual" },
106+#endif
105107 };
106108
107109 constexpr const char * ControllerTypeName(SDL_GameControllerType type)
@@ -207,6 +209,7 @@
207209 ImGui::SetNextWindowSize(ImVec2(total_width, main_window_height), ImGuiCond_Once);
208210 ImGui::Begin("Joysticks", NULL, 0);
209211
212+#if SDL_JOYSTICK_VIRTUAL
210213 static struct VJoyParams {
211214 int type_index = 1; // index into 'joystick_type_infos'
212215 int naxes = 2;
@@ -265,6 +268,8 @@
265268 ImGui::SameLine();
266269 ImGui::Dummy(ImVec2(32,0));
267270 ImGui::SameLine();
271+#endif // SDL_JOYSTICK_VIRTUAL
272+
268273 const int num_joysticks = SDL_NumJoysticks();
269274 ImGui::Text("Joysticks, Total-Count: %d", num_joysticks);
270275 // ImGui::SameLine();
@@ -341,7 +346,11 @@
341346 ImGui::Text("%d", (int)SDL_JoystickGetDeviceInstanceID(device_index));
342347 ImGui::NextColumn();
343348
349+#if SDL_JOYSTICK_VIRTUAL
344350 const SDL_bool is_joystick_virtual = SDL_JoystickIsVirtual(device_index);
351+#else
352+ const SDL_bool is_joystick_virtual = SDL_FALSE;
353+#endif
345354 ImGui::Text("%s", (is_joystick_virtual == SDL_TRUE ? "YES" : "NO"));
346355 ImGui::NextColumn();
347356
@@ -385,7 +394,11 @@
385394 if (!joystick) {
386395 return;
387396 }
397+#if SDL_JOYSTICK_VIRTUAL
388398 const SDL_bool is_joystick_virtual = SDL_JoystickIsVirtual(device_index);
399+#else
400+ const SDL_bool is_joystick_virtual = SDL_FALSE;
401+#endif
389402
390403 char window_name[64];
391404 SDL_snprintf(window_name, SDL_arraysize(window_name), "Joystick #%d", device_index);
@@ -480,7 +493,9 @@
480493 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(hue, 0.7f, std::clamp(lightness_base + 0.1f, 0.f, 1.f)));
481494 ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(hue, 0.8f, std::clamp(lightness_base + 0.2f, 0.f, 1.f)));
482495 if (ImGui::Button("Toggle")) {
496+#if SDL_JOYSTICK_VIRTUAL
483497 SDL_JoystickSetVirtualButton(joystick, col, !current);
498+#endif
484499 }
485500 ImGui::PopStyleColor(4);
486501 ImGui::PopStyleVar(3);
@@ -548,14 +563,18 @@
548563 const Sint16 s16_min = std::numeric_limits<Sint16>::min();
549564 const Sint16 s16_max = std::numeric_limits<Sint16>::max();
550565 if (ImGui::SliderScalar("", ImGuiDataType_S16, &axis, &s16_min, &s16_max, "")) {
566+#if SDL_JOYSTICK_VIRTUAL
551567 if (is_joystick_virtual) {
552568 SDL_JoystickSetVirtualAxis(joystick, i, axis);
553569 }
570+#endif
554571 }
555572 if (is_joystick_virtual) {
556573 ImGui::SameLine();
557574 if (ImGui::Button("Reset")) {
575+#if SDL_JOYSTICK_VIRTUAL
558576 SDL_JoystickSetVirtualAxis(joystick, i, (axis_has_initial_state ? axis_initial_state : 0));
577+#endif
559578 }
560579 }
561580 ImGui::NextColumn();
@@ -1157,7 +1176,7 @@
11571176 SDL_RenderClear(renderer);
11581177 SDL_SetRenderTarget(renderer, nullptr);
11591178
1160-#if DEV_DAVIDL
1179+#if DEV_DAVIDL && SDL_JOYSTICK_VIRTUAL
11611180 // DEBUG: add a virtual joystick
11621181 if (0) {
11631182 const int vjoy_device_index = SDL_JoystickAttachVirtual(SDL_JOYSTICK_TYPE_GAMECONTROLLER, 2, 0, 4, 0);
Show on old repository browser