mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-30 20:51:06 +01:00 
			
		
		
		
	Merge branch 'master' into viewport + specific changes for GLFW callbacks
# Conflicts: # examples/example_glfw_opengl3/main.cpp # examples/example_win32_directx11/main.cpp # examples/example_win32_directx9/main.cpp # examples/imgui_impl_glfw.cpp
This commit is contained in:
		| @@ -78,7 +78,9 @@ Other Changes: | ||||
|   in particular, points_count==0 could lead to a memory stomp if the draw list was previously empty. | ||||
| - Examples: DirectX10, DirectX11: Removed seemingly unnecessary calls to invalidate and recreate device objects | ||||
|   in the WM_SIZE handler. (#2088) [@ice1000] | ||||
| - Examples: GLFW: User previously installed GLFW callbacks are now saved and chain-called by the default callbacks. (#1759) | ||||
| - Examples: OpenGL3+GLFW: Fixed error condition when using the GLAD loader. (#2157) [@blackball] | ||||
| - Examples: OpenGL3+GLFW/SDL: Made main.cpp compile with IMGUI_IMPL_OPENGL_LOADER_CUSTOM (may be missing init). (#2178) [@doug-moen] | ||||
|  | ||||
|  | ||||
| ----------------------------------------------------------------------- | ||||
|   | ||||
| @@ -22,14 +22,16 @@ int main(int, char**) | ||||
|     al_register_event_source(queue, al_get_keyboard_event_source()); | ||||
|     al_register_event_source(queue, al_get_mouse_event_source()); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable Keyboard Controls | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplAllegro5_Init(display); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -237,16 +237,17 @@ | ||||
|     if ([view openGLContext] == nil) | ||||
|         NSLog(@"No OpenGL Context!"); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable Keyboard Controls | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplOSX_Init(); | ||||
|     ImGui_ImplOpenGL2_Init(); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -95,16 +95,17 @@ int main(int argc, char** argv) | ||||
|     // otherwise it is possible to install our own functions and call the imgui_impl_freeglut.h functions ourselves. | ||||
|     glutDisplayFunc(glut_display_func); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable Keyboard Controls | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplFreeGLUT_Init(); | ||||
|     ImGui_ImplFreeGLUT_InstallFuncs(); | ||||
|     ImGui_ImplOpenGL2_Init(); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -36,7 +36,7 @@ int main(int, char**) | ||||
|     glfwMakeContextCurrent(window); | ||||
|     glfwSwapInterval(1); // Enable vsync | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -46,10 +46,11 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplGlfw_InitForOpenGL(window, true); | ||||
|     ImGui_ImplOpenGL2_Init(); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -73,6 +73,8 @@ int main(int, char**) | ||||
|     bool err = glewInit() != GLEW_OK; | ||||
| #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) | ||||
|     bool err = gladLoadGL() == 0; | ||||
| #else | ||||
|     bool err = false; // If you use IMGUI_IMPL_OPENGL_LOADER_CUSTOM, your loader is likely to requires some form of initialization. | ||||
| #endif | ||||
|     if (err) | ||||
|     { | ||||
| @@ -80,7 +82,7 @@ int main(int, char**) | ||||
|         return 1; | ||||
|     } | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -90,10 +92,11 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplGlfw_InitForOpenGL(window, true); | ||||
|     ImGui_ImplOpenGL3_Init(glsl_version); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::GetStyle().WindowRounding = 0.0f; | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|   | ||||
| @@ -350,7 +350,7 @@ int main(int, char**) | ||||
|     ImGui_ImplVulkanH_WindowData* wd = &g_WindowData; | ||||
|     SetupVulkanWindowData(wd, surface, w, h); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -360,10 +360,8 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup GLFW binding | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplGlfw_InitForVulkan(window, true); | ||||
|  | ||||
|     // Setup Vulkan binding | ||||
|     ImGui_ImplVulkan_InitInfo init_info = {}; | ||||
|     init_info.Instance = g_Instance; | ||||
|     init_info.PhysicalDevice = g_PhysicalDevice; | ||||
| @@ -376,7 +374,7 @@ int main(int, char**) | ||||
|     init_info.CheckVkResultFn = check_vk_result; | ||||
|     ImGui_ImplVulkan_Init(&init_info, wd->RenderPass); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -16,14 +16,16 @@ int main(int, char**) | ||||
| { | ||||
|     IwGxInit(); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable Keyboard Controls | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_Marmalade_Init(true); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -34,7 +34,7 @@ int main(int, char**) | ||||
|     SDL_GLContext gl_context = SDL_GL_CreateContext(window); | ||||
|     SDL_GL_SetSwapInterval(1); // Enable vsync | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -43,10 +43,11 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplSDL2_InitForOpenGL(window, gl_context); | ||||
|     ImGui_ImplOpenGL2_Init(); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -65,6 +65,8 @@ int main(int, char**) | ||||
|     bool err = glewInit() != GLEW_OK; | ||||
| #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) | ||||
|     bool err = gladLoadGL() == 0; | ||||
| #else | ||||
|     bool err = false; // If you use IMGUI_IMPL_OPENGL_LOADER_CUSTOM, your loader is likely to requires some form of initialization. | ||||
| #endif | ||||
|     if (err) | ||||
|     { | ||||
| @@ -72,7 +74,7 @@ int main(int, char**) | ||||
|         return 1; | ||||
|     } | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -81,10 +83,11 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplSDL2_InitForOpenGL(window, gl_context); | ||||
|     ImGui_ImplOpenGL3_Init(glsl_version); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -333,7 +333,7 @@ int main(int, char**) | ||||
|     ImGui_ImplVulkanH_WindowData* wd = &g_WindowData; | ||||
|     SetupVulkanWindowData(wd, surface, w, h); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
|     io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;       // Enable Keyboard Controls | ||||
| @@ -341,10 +341,8 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup SDL binding | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplSDL2_InitForVulkan(window); | ||||
|  | ||||
|     // Setup Vulkan binding | ||||
|     ImGui_ImplVulkan_InitInfo init_info = {}; | ||||
|     init_info.Instance = g_Instance; | ||||
|     init_info.PhysicalDevice = g_PhysicalDevice; | ||||
| @@ -357,7 +355,7 @@ int main(int, char**) | ||||
|     init_info.CheckVkResultFn = check_vk_result; | ||||
|     ImGui_ImplVulkan_Init(&init_info, wd->RenderPass); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -112,7 +112,7 @@ int main(int, char**) | ||||
|     ShowWindow(hwnd, SW_SHOWDEFAULT); | ||||
|     UpdateWindow(hwnd); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -121,10 +121,11 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplWin32_Init(hwnd); | ||||
|     ImGui_ImplDX10_Init(g_pd3dDevice); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -128,7 +128,7 @@ int main(int, char**) | ||||
|     ShowWindow(hwnd, SW_SHOWDEFAULT); | ||||
|     UpdateWindow(hwnd); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -140,10 +140,11 @@ int main(int, char**) | ||||
|     io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts;     // FIXME-DPI: THIS CURRENTLY DOESN'T WORK AS EXPECTED. DON'T USE IN USER APP! | ||||
|     io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplWin32_Init(hwnd); | ||||
|     ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::GetStyle().WindowRounding = 0.0f; | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|   | ||||
| @@ -286,7 +286,7 @@ int main(int, char**) | ||||
|     ShowWindow(hwnd, SW_SHOWDEFAULT); | ||||
|     UpdateWindow(hwnd); | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -295,13 +295,14 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplWin32_Init(hwnd); | ||||
|     ImGui_ImplDX12_Init(g_pd3dDevice, NUM_FRAMES_IN_FLIGHT,  | ||||
|         DXGI_FORMAT_R8G8B8A8_UNORM, | ||||
|         g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(),  | ||||
|         g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -75,7 +75,7 @@ int main(int, char**) | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     // Setup Dear ImGui binding | ||||
|     // Setup Dear ImGui context | ||||
|     IMGUI_CHECKVERSION(); | ||||
|     ImGui::CreateContext(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); (void)io; | ||||
| @@ -84,10 +84,11 @@ int main(int, char**) | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; | ||||
|     //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; | ||||
|  | ||||
|     // Setup Platform/Renderer bindings | ||||
|     ImGui_ImplWin32_Init(hwnd); | ||||
|     ImGui_ImplDX9_Init(g_pd3dDevice); | ||||
|  | ||||
|     // Setup style | ||||
|     // Setup Style | ||||
|     ImGui::StyleColorsDark(); | ||||
|     //ImGui::StyleColorsClassic(); | ||||
|  | ||||
|   | ||||
| @@ -16,6 +16,7 @@ | ||||
| // CHANGELOG | ||||
| // (minor and older changes stripped away, please see git history for details) | ||||
| //  2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. | ||||
| //  2018-11-07: Inputs: When installing our GLFW callbacks, we save user's previously installed ones - if any - and chain call them. | ||||
| //  2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls. | ||||
| //  2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor. | ||||
| //  2018-06-08: Misc: Extracted imgui_impl_glfw.cpp/.h away from the old combined GLFW+OpenGL/Vulkan examples. | ||||
| @@ -54,12 +55,18 @@ enum GlfwClientApi | ||||
|     GlfwClientApi_OpenGL, | ||||
|     GlfwClientApi_Vulkan | ||||
| }; | ||||
| static GLFWwindow*      g_Window = NULL; | ||||
| static GlfwClientApi    g_ClientApi = GlfwClientApi_Unknown; | ||||
| static double           g_Time = 0.0; | ||||
| static bool             g_MouseJustPressed[5] = { false, false, false, false, false }; | ||||
| static GLFWcursor*      g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; | ||||
| static bool             g_WantUpdateMonitors = true; | ||||
| static GLFWwindow*          g_Window = NULL;    // Main window | ||||
| static GlfwClientApi        g_ClientApi = GlfwClientApi_Unknown; | ||||
| static double               g_Time = 0.0; | ||||
| static bool                 g_MouseJustPressed[5] = { false, false, false, false, false }; | ||||
| static GLFWcursor*          g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; | ||||
| static bool                 g_WantUpdateMonitors = true; | ||||
|  | ||||
| // Chain GLFW callbacks for main viewport: our callbacks will call the user's previously installed callbacks, if any. | ||||
| static GLFWmousebuttonfun   g_PrevUserCallbackMousebutton = NULL; | ||||
| static GLFWscrollfun        g_PrevUserCallbackScroll = NULL; | ||||
| static GLFWkeyfun           g_PrevUserCallbackKey = NULL; | ||||
| static GLFWcharfun          g_PrevUserCallbackChar = NULL; | ||||
|  | ||||
| // Forward Declarations | ||||
| static void ImGui_ImplGlfw_InitPlatformInterface(); | ||||
| @@ -76,49 +83,53 @@ static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text) | ||||
|     glfwSetClipboardString((GLFWwindow*)user_data, text); | ||||
| } | ||||
|  | ||||
| void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/) | ||||
| void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) | ||||
| { | ||||
|     if (g_PrevUserCallbackMousebutton != NULL && window == g_Window) | ||||
|         g_PrevUserCallbackMousebutton(window, button, action, mods); | ||||
|  | ||||
|     if (action == GLFW_PRESS && button >= 0 && button < IM_ARRAYSIZE(g_MouseJustPressed)) | ||||
|         g_MouseJustPressed[button] = true; | ||||
| } | ||||
|  | ||||
| void ImGui_ImplGlfw_ScrollCallback(GLFWwindow*, double xoffset, double yoffset) | ||||
| void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) | ||||
| { | ||||
|     if (g_PrevUserCallbackScroll != NULL && window == g_Window) | ||||
|         g_PrevUserCallbackScroll(window, xoffset, yoffset); | ||||
|  | ||||
|     ImGuiIO& io = ImGui::GetIO(); | ||||
|     io.MouseWheelH += (float)xoffset; | ||||
|     io.MouseWheel += (float)yoffset; | ||||
| } | ||||
|  | ||||
| void ImGui_ImplGlfw_KeyCallback(GLFWwindow*, int key, int, int action, int mods) | ||||
| void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) | ||||
| { | ||||
|     if (g_PrevUserCallbackKey != NULL && window == g_Window) | ||||
|         g_PrevUserCallbackKey(window, key, scancode, action, mods); | ||||
|  | ||||
|     ImGuiIO& io = ImGui::GetIO(); | ||||
|     if (action == GLFW_PRESS) | ||||
|         io.KeysDown[key] = true; | ||||
|     if (action == GLFW_RELEASE) | ||||
|         io.KeysDown[key] = false; | ||||
|  | ||||
|     (void)mods; // Modifiers are not reliable across systems | ||||
|     // Modifiers are not reliable across systems | ||||
|     io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL]; | ||||
|     io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT]; | ||||
|     io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT]; | ||||
|     io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER]; | ||||
| } | ||||
|  | ||||
| void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c) | ||||
| void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c) | ||||
| { | ||||
|     if (g_PrevUserCallbackChar != NULL && window == g_Window) | ||||
|         g_PrevUserCallbackChar(window, c); | ||||
|  | ||||
|     ImGuiIO& io = ImGui::GetIO(); | ||||
|     if (c > 0 && c < 0x10000) | ||||
|         io.AddInputCharacter((unsigned short)c); | ||||
| } | ||||
|  | ||||
| void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window) | ||||
| { | ||||
|     glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback); | ||||
|     glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback); | ||||
|     glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback); | ||||
|     glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback); | ||||
| } | ||||
|  | ||||
| static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api) | ||||
| { | ||||
|     g_Window = window; | ||||
| @@ -169,8 +180,18 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw | ||||
|     g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);  // FIXME: GLFW doesn't have this. | ||||
|     g_MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR); | ||||
|      | ||||
|     // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. | ||||
|     g_PrevUserCallbackMousebutton = NULL; | ||||
|     g_PrevUserCallbackScroll = NULL; | ||||
|     g_PrevUserCallbackKey = NULL; | ||||
|     g_PrevUserCallbackChar = NULL; | ||||
|     if (install_callbacks) | ||||
|         ImGui_ImplGlfw_InstallCallbacks(window); | ||||
|     { | ||||
|         g_PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback); | ||||
|         g_PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback); | ||||
|         g_PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback); | ||||
|         g_PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback); | ||||
|     } | ||||
|  | ||||
|     // Our mouse update function expect PlatformHandle to be filled for the main viewport | ||||
|     ImGuiViewport* main_viewport = ImGui::GetMainViewport(); | ||||
| @@ -388,7 +409,12 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport) | ||||
|     data->Window = glfwCreateWindow((int)viewport->Size.x, (int)viewport->Size.y, "No Title Yet", NULL, share_window); | ||||
|     data->WindowOwned = true; | ||||
|     viewport->PlatformHandle = (void*)data->Window; | ||||
|     ImGui_ImplGlfw_InstallCallbacks(data->Window); | ||||
|  | ||||
|     // Install callbacks for secondary viewports | ||||
|     glfwSetMouseButtonCallback(data->Window, ImGui_ImplGlfw_MouseButtonCallback); | ||||
|     glfwSetScrollCallback(data->Window, ImGui_ImplGlfw_ScrollCallback); | ||||
|     glfwSetKeyCallback(data->Window, ImGui_ImplGlfw_KeyCallback); | ||||
|     glfwSetCharCallback(data->Window, ImGui_ImplGlfw_CharCallback); | ||||
|     glfwSetWindowCloseCallback(data->Window, ImGui_ImplGlfw_WindowCloseCallback); | ||||
|     glfwSetWindowPosCallback(data->Window, ImGui_ImplGlfw_WindowPosCallback); | ||||
|     glfwSetWindowSizeCallback(data->Window, ImGui_ImplGlfw_WindowSizeCallback); | ||||
|   | ||||
| @@ -26,9 +26,8 @@ IMGUI_IMPL_API bool     ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool in | ||||
| IMGUI_IMPL_API void     ImGui_ImplGlfw_Shutdown(); | ||||
| IMGUI_IMPL_API void     ImGui_ImplGlfw_NewFrame(); | ||||
|  | ||||
| // GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization) | ||||
| // Provided here if you want to chain callbacks. | ||||
| // You can also handle inputs yourself and use those as a reference. | ||||
| // InitXXX function with 'install_callbacks=true': install GLFW callbacks. They will call user's previously installed callbacks, if any. | ||||
| // InitXXX function with 'install_callbacks=false': do not install GLFW callbacks. You will need to call them yourself from your own GLFW callbacks. | ||||
| IMGUI_IMPL_API void     ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); | ||||
| IMGUI_IMPL_API void     ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); | ||||
| IMGUI_IMPL_API void     ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user