|
@@ -2114,8 +2114,9 @@ void ImGui::NewFrame()
|
|
|
g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]));
|
|
|
}
|
|
|
}
|
|
|
+ memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
|
|
|
for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
|
|
|
- g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f;
|
|
|
+ g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f;
|
|
|
|
|
|
// Calculate frame-rate for the user, as a purely luxurious feature
|
|
|
g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
|
|
@@ -2871,7 +2872,7 @@ bool ImGui::IsKeyPressed(int key_index, bool repeat)
|
|
|
{
|
|
|
ImGuiState& g = *GImGui;
|
|
|
IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
|
|
|
- const float t = g.IO.KeysDownTime[key_index];
|
|
|
+ const float t = g.IO.KeysDownDuration[key_index];
|
|
|
if (t == 0.0f)
|
|
|
return true;
|
|
|
|
|
@@ -2881,6 +2882,15 @@ bool ImGui::IsKeyPressed(int key_index, bool repeat)
|
|
|
if ((fmodf(t - delay, rate) > rate*0.5f) != (fmodf(t - delay - g.IO.DeltaTime, rate) > rate*0.5f))
|
|
|
return true;
|
|
|
}
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool ImGui::IsKeyReleased(int key_index)
|
|
|
+{
|
|
|
+ ImGuiState& g = *GImGui;
|
|
|
+ IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
|
|
|
+ if (g.IO.KeysDownDurationPrev[key_index] >= 0.0f && !g.IO.KeysDown[key_index])
|
|
|
+ return true;
|
|
|
|
|
|
return false;
|
|
|
}
|
|
@@ -10569,12 +10579,6 @@ void ImGui::ShowTestWindow(bool* opened)
|
|
|
ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels
|
|
|
|
|
|
ImGui::Text("ImGui says hello.");
|
|
|
- //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
|
|
|
- //ImGui::Text("MouseClicked (%d, %d) MouseReleased (%d, %d)", ImGui::GetIO().MouseClicked[0], ImGui::GetIO().MouseClicked[1], ImGui::GetIO().MouseReleased[0], ImGui::GetIO().MouseReleased[1]);
|
|
|
- //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
|
|
|
- //ImGui::Text("KeyMods %s%s%s", ImGui::GetIO().KeyCtrl ? "CTRL" : "", ImGui::GetIO().KeyShift ? "SHIFT" : "", ImGui::GetIO().KeyAlt? "ALT" : "");
|
|
|
- //ImGui::Text("WantCaptureMouse: %d", ImGui::GetIO().WantCaptureMouse);
|
|
|
- //ImGui::Text("WantCaptureKeyboard: %d", ImGui::GetIO().WantCaptureKeyboard);
|
|
|
|
|
|
// Menu
|
|
|
if (ImGui::BeginMenuBar())
|
|
@@ -11607,6 +11611,27 @@ void ImGui::ShowTestWindow(bool* opened)
|
|
|
ImGui::TreePop();
|
|
|
}
|
|
|
|
|
|
+ if (ImGui::TreeNode("Keyboard & Mouse State"))
|
|
|
+ {
|
|
|
+ ImGuiIO& io = ImGui::GetIO();
|
|
|
+
|
|
|
+ ImGui::Text("MousePos: (%g, %g)", io.MousePos.x, io.MousePos.y);
|
|
|
+ ImGui::Text("Mouse down:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (io.MouseDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (%.02f secs)", i, io.MouseDownDuration[i]); }
|
|
|
+ ImGui::Text("Mouse clicked:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseClicked(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
|
|
|
+ ImGui::Text("Mouse released:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseReleased(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
|
|
|
+ ImGui::Text("MouseWheel: %.1f", io.MouseWheel);
|
|
|
+
|
|
|
+ ImGui::Text("Keys down:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (io.KeysDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (%.02f secs)", i, io.KeysDownDuration[i]); }
|
|
|
+ ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
|
|
|
+ ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
|
|
|
+ ImGui::Text("KeyMods: %s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "");
|
|
|
+
|
|
|
+ ImGui::Text("WantCaptureMouse: %s", io.WantCaptureMouse ? "true" : "false");
|
|
|
+ ImGui::Text("WantCaptureKeyboard: %s", io.WantCaptureKeyboard ? "true" : "false");
|
|
|
+
|
|
|
+ ImGui::TreePop();
|
|
|
+ }
|
|
|
+
|
|
|
if (ImGui::TreeNode("Mouse cursors"))
|
|
|
{
|
|
|
ImGui::TextWrapped("Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. You can also set io.MouseDrawCursor to ask ImGui to render the cursor for you in software.");
|