Viewport, Platform: Added a way to register monitor bounds to imgui so they can be used to clamp individual-viewport tooltips/popups so they don't straddle monitors. (#1542)

This commit is contained in:
omar
2018-04-10 22:32:08 +02:00
parent 7ddc22b326
commit 32ee0a3947
5 changed files with 79 additions and 6 deletions

View File

@ -519,6 +519,23 @@ static int ImGui_ImplGlfw_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_inst
}
#endif // GLFW_HAS_VULKAN
// FIXME-PLATFORM: Update when changed (using glfwSetMonitorCallback?)
static void ImGui_ImplGlfw_UpdateMonitors()
{
ImGuiPlatformData* platform_data = ImGui::GetPlatformData();
int monitors_count = 0;
GLFWmonitor** glfw_monitors = glfwGetMonitors(&monitors_count);
platform_data->Monitors.resize(monitors_count);
for (int n = 0; n < monitors_count; n++)
{
int x, y;
glfwGetMonitorPos(glfw_monitors[n], &x, &y);
const GLFWvidmode* vid_mode = glfwGetVideoMode(glfw_monitors[n]);
platform_data->Monitors[n].Pos = ImVec2((float)x, (float)y);
platform_data->Monitors[n].Size = ImVec2((float)vid_mode->width, (float)vid_mode->height);
}
}
static void ImGui_ImplGlfw_InitPlatformInterface()
{
// Register platform interface (will be coupled with a renderer interface)
@ -540,6 +557,8 @@ static void ImGui_ImplGlfw_InitPlatformInterface()
platform_io.Platform_CreateVkSurface = ImGui_ImplGlfw_CreateVkSurface;
#endif
ImGui_ImplGlfw_UpdateMonitors();
// Register main window handle (which is owned by the main application, not by us)
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
ImGuiViewportDataGlfw* data = IM_NEW(ImGuiViewportDataGlfw)();

View File

@ -437,6 +437,21 @@ static int ImGui_ImplSDL2_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_inst
}
#endif // SDL_HAS_VULKAN
// FIXME-PLATFORM: Update when changed?
static void ImGui_ImplSDL2_UpdateMonitors()
{
ImGuiPlatformData* platform_data = ImGui::GetPlatformData();
int display_count = SDL_GetNumVideoDisplays();
platform_data->Monitors.resize(display_count);
for (int n = 0; n < display_count; n++)
{
SDL_Rect r;
SDL_GetDisplayBounds(n, &r);
platform_data->Monitors[n].Pos = ImVec2((float)r.x, (float)r.y);
platform_data->Monitors[n].Size = ImVec2((float)r.w, (float)r.h);
}
}
static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context)
{
// Register platform interface (will be coupled with a renderer interface)
@ -455,6 +470,8 @@ static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_g
platform_io.Platform_CreateVkSurface = ImGui_ImplSDL2_CreateVkSurface;
#endif
ImGui_ImplSDL2_UpdateMonitors();
// Register main window handle (which is owned by the main application, not by us)
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
ImGuiViewportDataSDL2* data = IM_NEW(ImGuiViewportDataSDL2)();

View File

@ -535,6 +535,22 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd,
return DefWindowProc(hWnd, msg, wParam, lParam);
}
static BOOL CALLBACK ImGui_ImplWin32_UpdateMonitors_EnumFunc(HMONITOR, HDC, LPRECT rect, LPARAM)
{
ImGuiPlatformMonitor imgui_monitor;
imgui_monitor.Pos = ImVec2((float)rect->left, (float)rect->top);
imgui_monitor.Size = ImVec2((float)(rect->right - rect->left), (float)(rect->bottom - rect->top));
ImGui::GetPlatformData()->Monitors.push_back(imgui_monitor);
return TRUE;
}
// FIXME-PLATFORM: Update list when changed (WM_DISPLAYCHANGE?)
static void ImGui_ImplWin32_UpdateMonitors()
{
ImGui::GetPlatformData()->Monitors.resize(0);
::EnumDisplayMonitors(NULL, NULL, ImGui_ImplWin32_UpdateMonitors_EnumFunc, NULL);
}
static void ImGui_ImplWin32_InitPlatformInterface()
{
WNDCLASSEX wcex;
@ -552,6 +568,8 @@ static void ImGui_ImplWin32_InitPlatformInterface()
wcex.hIconSm = NULL;
::RegisterClassEx(&wcex);
ImGui_ImplWin32_UpdateMonitors();
// Register platform interface (will be coupled with a renderer interface)
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
platform_io.Platform_CreateWindow = ImGui_ImplWin32_CreateWindow;