diff --git a/NodeEditor/Source/imgui_node_editor.cpp b/NodeEditor/Source/imgui_node_editor.cpp index 45318105d..ac1429c50 100644 --- a/NodeEditor/Source/imgui_node_editor.cpp +++ b/NodeEditor/Source/imgui_node_editor.cpp @@ -16,6 +16,61 @@ # include # include # include +# include + +// https://stackoverflow.com/a/8597498 +# define DECLARE_HAS_NESTED(Name, Member) \ + \ + template \ + struct has_nested_ ## Name \ + { \ + typedef char yes; \ + typedef yes(&no)[2]; \ + \ + template static yes test(decltype(U::Member)*); \ + template static no test(...); \ + \ + static bool const value = sizeof(test(0)) == sizeof(yes); \ + }; + + +namespace ax { +namespace NodeEditor { +namespace Detail { + +# define DECLARE_KEY_TESTER(Key) \ + DECLARE_HAS_NESTED(Key, Key) \ + struct KeyTester_ ## Key \ + { \ + template \ + static int Get(typename std::enable_if::value, T>::type*) \ + { \ + return ImGui::GetKeyIndex(T::Key); \ + } \ + \ + template \ + static int Get(typename std::enable_if::value, T>::type*) \ + { \ + return -1; \ + } \ + } + +DECLARE_KEY_TESTER(ImGuiKey_F); +DECLARE_KEY_TESTER(ImGuiKey_D); + +static inline int GetKeyIndexForF() +{ + return KeyTester_ImGuiKey_F::Get(nullptr); +} + +static inline int GetKeyIndexForD() +{ + return KeyTester_ImGuiKey_D::Get(nullptr); +} + +} // namespace Detail +} // namespace NodeEditor +} // namespace ax //------------------------------------------------------------------------------ @@ -2791,7 +2846,7 @@ ed::EditorAction::AcceptResult ed::NavigateAction::Accept(const Control& control auto& io = ImGui::GetIO(); - if (ImGui::IsWindowFocused() && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_F)) && Editor->AreShortcutsEnabled()) + if (ImGui::IsWindowFocused() && ImGui::IsKeyPressed(GetKeyIndexForF()) && Editor->AreShortcutsEnabled()) { const auto allowZoomIn = io.KeyShift; @@ -3791,7 +3846,7 @@ ed::EditorAction::AcceptResult ed::ShortcutAction::Accept(const Control& control candidateAction = Copy; if (io.KeyCtrl && !io.KeyShift && !io.KeyAlt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_V))) candidateAction = Paste; - if (io.KeyCtrl && !io.KeyShift && !io.KeyAlt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_D))) + if (io.KeyCtrl && !io.KeyShift && !io.KeyAlt && ImGui::IsKeyPressed(GetKeyIndexForD())) candidateAction = Duplicate; if (!io.KeyCtrl && !io.KeyShift && !io.KeyAlt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Space))) candidateAction = CreateNode;