From 7a41e0b1ea575ba72949a09b2fea3e2a1f76a71d Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 25 Apr 2018 15:15:14 +0200 Subject: [PATCH] Platform: Added platform_io.Platform_SetWindowFocus, Platform_GetWindowFocus function wrappers (unused yet). Exact specs tbd because our simplified concept of focus doesn't necessary match the more complex OS native concepts. (#1542) --- examples/directx11_example/main.cpp | 3 +-- examples/imgui_impl_glfw.cpp | 14 ++++++++++++++ examples/imgui_impl_sdl2.cpp | 15 +++++++++++++++ examples/imgui_impl_win32.cpp | 18 ++++++++++++++++++ examples/opengl3_example/main.cpp | 4 +++- imgui.h | 2 ++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 6a39d143..7fa16e98 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -144,10 +144,9 @@ int main(int, char**) ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); // Setup style + ImGui::GetStyle().WindowRounding = 0.0f; ImGui::StyleColorsDark(); //ImGui::StyleColorsClassic(); - ImGuiStyle& style = ImGui::GetStyle(); - style.WindowRounding = 0.0f; // Load Fonts // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index cd04bc48..0d00b3aa 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -477,6 +477,18 @@ static void ImGui_ImplGlfw_SetWindowTitle(ImGuiViewport* viewport, const char* t glfwSetWindowTitle(data->Window, title); } +static void ImGui_ImplGlfw_SetWindowFocus(ImGuiViewport* viewport) +{ + ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData; + glfwFocusWindow(data->Window); +} + +static bool ImGui_ImplGlfw_GetWindowFocus(ImGuiViewport* viewport) +{ + ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData; + return glfwGetWindowAttrib(data->Window, GLFW_FOCUSED) != 0; +} + #if GLFW_HAS_WINDOW_ALPHA static void ImGui_ImplGlfw_SetWindowAlpha(ImGuiViewport* viewport, float alpha) { @@ -587,6 +599,8 @@ static void ImGui_ImplGlfw_InitPlatformInterface() platform_io.Platform_GetWindowPos = ImGui_ImplGlfw_GetWindowPos; platform_io.Platform_SetWindowSize = ImGui_ImplGlfw_SetWindowSize; platform_io.Platform_GetWindowSize = ImGui_ImplGlfw_GetWindowSize; + platform_io.Platform_SetWindowFocus = ImGui_ImplGlfw_SetWindowFocus; + platform_io.Platform_GetWindowFocus = ImGui_ImplGlfw_GetWindowFocus; platform_io.Platform_SetWindowTitle = ImGui_ImplGlfw_SetWindowTitle; platform_io.Platform_RenderWindow = ImGui_ImplGlfw_RenderWindow; platform_io.Platform_SwapBuffers = ImGui_ImplGlfw_SwapBuffers; diff --git a/examples/imgui_impl_sdl2.cpp b/examples/imgui_impl_sdl2.cpp index 089761bb..e58f28cc 100644 --- a/examples/imgui_impl_sdl2.cpp +++ b/examples/imgui_impl_sdl2.cpp @@ -409,6 +409,19 @@ static void ImGui_ImplSDL2_SetWindowTitle(ImGuiViewport* viewport, const char* t SDL_SetWindowTitle(data->Window, title); } +static void ImGui_ImplSDL2_SetWindowFocus(ImGuiViewport* viewport) +{ + ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData; + SDL_RaiseWindow(data->Window); +} + +static bool ImGui_ImplSDL2_GetWindowFocus(ImGuiViewport* viewport) +{ + ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData; + bool focus = (SDL_GetWindowFlags(data->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; + return focus; +} + static void ImGui_ImplSDL2_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData; @@ -478,6 +491,8 @@ static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_g platform_io.Platform_GetWindowPos = ImGui_ImplSDL2_GetWindowPos; platform_io.Platform_SetWindowSize = ImGui_ImplSDL2_SetWindowSize; platform_io.Platform_GetWindowSize = ImGui_ImplSDL2_GetWindowSize; + platform_io.Platform_SetWindowFocus = ImGui_ImplSDL2_SetWindowFocus; + platform_io.Platform_GetWindowFocus = ImGui_ImplSDL2_GetWindowFocus; platform_io.Platform_SetWindowTitle = ImGui_ImplSDL2_SetWindowTitle; platform_io.Platform_RenderWindow = ImGui_ImplSDL2_RenderWindow; platform_io.Platform_SwapBuffers = ImGui_ImplSDL2_SwapBuffers; diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index b4412d0e..6f440600 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -502,6 +502,22 @@ static void ImGui_ImplWin32_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) ::SetWindowPos(data->Hwnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); } +static void ImGui_ImplWin32_SetWindowFocus(ImGuiViewport* viewport) +{ + ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData; + IM_ASSERT(data->Hwnd != 0); + ::BringWindowToTop(data->Hwnd); + ::SetForegroundWindow(data->Hwnd); + ::SetFocus(data->Hwnd); +} + +static bool ImGui_ImplWin32_GetWindowFocus(ImGuiViewport* viewport) +{ + ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData; + IM_ASSERT(data->Hwnd != 0); + return ::GetActiveWindow() == data->Hwnd; +} + static void ImGui_ImplWin32_SetWindowTitle(ImGuiViewport* viewport, const char* title) { ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData; @@ -642,6 +658,8 @@ static void ImGui_ImplWin32_InitPlatformInterface() platform_io.Platform_GetWindowPos = ImGui_ImplWin32_GetWindowPos; platform_io.Platform_SetWindowSize = ImGui_ImplWin32_SetWindowSize; platform_io.Platform_GetWindowSize = ImGui_ImplWin32_GetWindowSize; + platform_io.Platform_SetWindowFocus = ImGui_ImplWin32_SetWindowFocus; + platform_io.Platform_GetWindowFocus = ImGui_ImplWin32_GetWindowFocus; platform_io.Platform_SetWindowTitle = ImGui_ImplWin32_SetWindowTitle; platform_io.Platform_SetWindowAlpha = ImGui_ImplWin32_SetWindowAlpha; platform_io.Platform_GetWindowDpiScale = ImGui_ImplWin32_GetWindowDpiScale; diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 6ae71d4f..50b364c6 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -37,13 +37,15 @@ int main(int, char**) ImGuiIO& io = ImGui::GetIO(); (void)io; io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; - //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init(); // Setup style + ImGui::GetStyle().WindowRounding = 0.0f; ImGui::StyleColorsDark(); //ImGui::StyleColorsClassic(); diff --git a/imgui.h b/imgui.h index 3396d048..dbb59aa3 100644 --- a/imgui.h +++ b/imgui.h @@ -1899,6 +1899,8 @@ struct ImGuiPlatformIO ImVec2 (*Platform_GetWindowPos)(ImGuiViewport* vp); void (*Platform_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); ImVec2 (*Platform_GetWindowSize)(ImGuiViewport* vp); + void (*Platform_SetWindowFocus)(ImGuiViewport* vp); // Move window to front and set input focus + bool (*Platform_GetWindowFocus)(ImGuiViewport* vp); void (*Platform_SetWindowTitle)(ImGuiViewport* vp, const char* title); void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // (Optional) Setup window transparency void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // (Optional) Setup for render (platform side)