| 7908 | //----------------------------------------------------------------------------- |
| 7909 | |
| 7910 | static void DemoWindowInputs() |
| 7911 | { |
| 7912 | if (ImGui::CollapsingHeader("Inputs & Focus")) |
| 7913 | { |
| 7914 | ImGuiIO& io = ImGui::GetIO(); |
| 7915 | |
| 7916 | // Display inputs submitted to ImGuiIO |
| 7917 | ImGui::SetNextItemOpen(true, ImGuiCond_Once); |
| 7918 | bool inputs_opened = ImGui::TreeNode("Inputs"); |
| 7919 | ImGui::SameLine(); |
| 7920 | HelpMarker( |
| 7921 | "This is a simplified view. See more detailed input state:\n" |
| 7922 | "- in 'Tools->Metrics/Debugger->Inputs'.\n" |
| 7923 | "- in 'Tools->Debug Log->IO'."); |
| 7924 | if (inputs_opened) |
| 7925 | { |
| 7926 | IMGUI_DEMO_MARKER("Inputs & Focus/Inputs"); |
| 7927 | if (ImGui::IsMousePosValid()) |
| 7928 | ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); |
| 7929 | else |
| 7930 | ImGui::Text("Mouse pos: <INVALID>"); |
| 7931 | ImGui::Text("Mouse delta: (%g, %g)", io.MouseDelta.x, io.MouseDelta.y); |
| 7932 | ImGui::Text("Mouse down:"); |
| 7933 | for (int i = 0; i < IM_COUNTOF(io.MouseDown); i++) if (ImGui::IsMouseDown(i)) { ImGui::SameLine(); ImGui::Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); } |
| 7934 | ImGui::Text("Mouse wheel: %.1f", io.MouseWheel); |
| 7935 | ImGui::Text("Mouse clicked count:"); |
| 7936 | for (int i = 0; i < IM_COUNTOF(io.MouseDown); i++) if (io.MouseClickedCount[i] > 0) { ImGui::SameLine(); ImGui::Text("b%d: %d", i, io.MouseClickedCount[i]); } |
| 7937 | |
| 7938 | // We iterate both legacy native range and named ImGuiKey ranges. This is a little unusual/odd but this allows |
| 7939 | // displaying the data for old/new backends. |
| 7940 | // User code should never have to go through such hoops! |
| 7941 | // You can generally iterate between ImGuiKey_NamedKey_BEGIN and ImGuiKey_NamedKey_END. |
| 7942 | struct funcs { static bool IsLegacyNativeDupe(ImGuiKey) { return false; } }; |
| 7943 | ImGuiKey start_key = ImGuiKey_NamedKey_BEGIN; |
| 7944 | ImGui::Text("Keys down:"); for (ImGuiKey key = start_key; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key) || !ImGui::IsKeyDown(key)) continue; ImGui::SameLine(); ImGui::Text((key < ImGuiKey_NamedKey_BEGIN) ? "\"%s\"" : "\"%s\" %d", ImGui::GetKeyName(key), key); } |
| 7945 | ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : ""); |
| 7946 | ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; ImGui::SameLine(); ImGui::Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public. |
| 7947 | |
| 7948 | ImGui::TreePop(); |
| 7949 | } |
| 7950 | |
| 7951 | // Display ImGuiIO output flags |
| 7952 | ImGui::SetNextItemOpen(true, ImGuiCond_Once); |
| 7953 | bool outputs_opened = ImGui::TreeNode("Outputs"); |
| 7954 | ImGui::SameLine(); |
| 7955 | HelpMarker( |
| 7956 | "The value of io.WantCaptureMouse and io.WantCaptureKeyboard are normally set by Dear ImGui " |
| 7957 | "to instruct your application of how to route inputs. Typically, when a value is true, it means " |
| 7958 | "Dear ImGui wants the corresponding inputs and we expect the underlying application to ignore them.\n\n" |
| 7959 | "The most typical case is: when hovering a window, Dear ImGui set io.WantCaptureMouse to true, " |
| 7960 | "and underlying application should ignore mouse inputs (in practice there are many and more subtle " |
| 7961 | "rules leading to how those flags are set)."); |
| 7962 | if (outputs_opened) |
| 7963 | { |
| 7964 | IMGUI_DEMO_MARKER("Inputs & Focus/Outputs"); |
| 7965 | ImGui::Text("io.WantCaptureMouse: %d", io.WantCaptureMouse); |
| 7966 | ImGui::Text("io.WantCaptureMouseUnlessPopupClose: %d", io.WantCaptureMouseUnlessPopupClose); |
| 7967 | ImGui::Text("io.WantCaptureKeyboard: %d", io.WantCaptureKeyboard); |
no test coverage detected