From 8fbb42cc6f0d3a3b0f475902409676c663f9c3f8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 28 Apr 2015 18:12:24 +0200 Subject: [PATCH] Added IsKeyDown() IsMouseDown() as convenience instead of reading into IO structures Also their existence serves as implicit documentation of what IsKeyPressed(), IsMouseClicked() does --- imgui.cpp | 14 ++++++++++++++ imgui.h | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 8435f98da..9ce9ec52b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2657,6 +2657,13 @@ static bool IsKeyPressedMap(ImGuiKey key, bool repeat) return ImGui::IsKeyPressed(key_index, repeat); } +bool ImGui::IsKeyDown(int key_index) +{ + ImGuiState& g = *GImGui; + IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown)); + return g.IO.KeysDown[key_index]; +} + bool ImGui::IsKeyPressed(int key_index, bool repeat) { ImGuiState& g = *GImGui; @@ -2675,6 +2682,13 @@ bool ImGui::IsKeyPressed(int key_index, bool repeat) return false; } +bool ImGui::IsMouseDown(int button) +{ + ImGuiState& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseDown[button]; +} + bool ImGui::IsMouseClicked(int button, bool repeat) { ImGuiState& g = *GImGui; diff --git a/imgui.h b/imgui.h index bb9af931b..5d358f00e 100644 --- a/imgui.h +++ b/imgui.h @@ -386,7 +386,9 @@ namespace ImGui IMGUI_API bool IsRootWindowFocused(); // is current root window focused IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused IMGUI_API bool IsRectClipped(const ImVec2& size); // test if rectangle of given size starting from cursor pos is out of clipping region. to perform coarse clipping on user's side (as an optimization) - IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry + IMGUI_API bool IsKeyDown(int key_index); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry + IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // " + IMGUI_API bool IsMouseDown(int button); IMGUI_API bool IsMouseClicked(int button, bool repeat = false); IMGUI_API bool IsMouseDoubleClicked(int button); IMGUI_API bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window)