| 9146 | } |
| 9147 | |
| 9148 | static void ImGui::UpdateKeyboardInputs() |
| 9149 | { |
| 9150 | ImGuiContext& g = *GImGui; |
| 9151 | ImGuiIO& io = g.IO; |
| 9152 | |
| 9153 | if (io.ConfigFlags & ImGuiConfigFlags_NoKeyboard) |
| 9154 | io.ClearInputKeys(); |
| 9155 | |
| 9156 | // Import legacy keys or verify they are not used |
| 9157 | #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO |
| 9158 | if (io.BackendUsingLegacyKeyArrays == 0) |
| 9159 | { |
| 9160 | // Backend used new io.AddKeyEvent() API: Good! Verify that old arrays are never written to externally. |
| 9161 | for (int n = 0; n < ImGuiKey_LegacyNativeKey_END; n++) |
| 9162 | IM_ASSERT((io.KeysDown[n] == false || IsKeyDown((ImGuiKey)n)) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); |
| 9163 | } |
| 9164 | else |
| 9165 | { |
| 9166 | if (g.FrameCount == 0) |
| 9167 | for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++) |
| 9168 | IM_ASSERT(g.IO.KeyMap[n] == -1 && "Backend is not allowed to write to io.KeyMap[0..511]!"); |
| 9169 | |
| 9170 | // Build reverse KeyMap (Named -> Legacy) |
| 9171 | for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) |
| 9172 | if (io.KeyMap[n] != -1) |
| 9173 | { |
| 9174 | IM_ASSERT(IsLegacyKey((ImGuiKey)io.KeyMap[n])); |
| 9175 | io.KeyMap[io.KeyMap[n]] = n; |
| 9176 | } |
| 9177 | |
| 9178 | // Import legacy keys into new ones |
| 9179 | for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++) |
| 9180 | if (io.KeysDown[n] || io.BackendUsingLegacyKeyArrays == 1) |
| 9181 | { |
| 9182 | const ImGuiKey key = (ImGuiKey)(io.KeyMap[n] != -1 ? io.KeyMap[n] : n); |
| 9183 | IM_ASSERT(io.KeyMap[n] == -1 || IsNamedKey(key)); |
| 9184 | io.KeysData[key].Down = io.KeysDown[n]; |
| 9185 | if (key != n) |
| 9186 | io.KeysDown[key] = io.KeysDown[n]; // Allow legacy code using io.KeysDown[GetKeyIndex()] with old backends |
| 9187 | io.BackendUsingLegacyKeyArrays = 1; |
| 9188 | } |
| 9189 | if (io.BackendUsingLegacyKeyArrays == 1) |
| 9190 | { |
| 9191 | GetKeyData(ImGuiMod_Ctrl)->Down = io.KeyCtrl; |
| 9192 | GetKeyData(ImGuiMod_Shift)->Down = io.KeyShift; |
| 9193 | GetKeyData(ImGuiMod_Alt)->Down = io.KeyAlt; |
| 9194 | GetKeyData(ImGuiMod_Super)->Down = io.KeySuper; |
| 9195 | } |
| 9196 | } |
| 9197 | #endif |
| 9198 | |
| 9199 | // Import legacy ImGuiNavInput_ io inputs and convert to gamepad keys |
| 9200 | #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO |
| 9201 | const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; |
| 9202 | if (io.BackendUsingLegacyNavInputArray && nav_gamepad_active) |
| 9203 | { |
| 9204 | #define MAP_LEGACY_NAV_INPUT_TO_KEY1(_KEY, _NAV1) do { io.KeysData[_KEY].Down = (io.NavInputs[_NAV1] > 0.0f); io.KeysData[_KEY].AnalogValue = io.NavInputs[_NAV1]; } while (0) |
| 9205 | #define MAP_LEGACY_NAV_INPUT_TO_KEY2(_KEY, _NAV1, _NAV2) do { io.KeysData[_KEY].Down = (io.NavInputs[_NAV1] > 0.0f) || (io.NavInputs[_NAV2] > 0.0f); io.KeysData[_KEY].AnalogValue = ImMax(io.NavInputs[_NAV1], io.NavInputs[_NAV2]); } while (0) |
nothing calls this directly
no test coverage detected