Viewport, Platforms: SDL: Fixed initial focus click being ignored as a mouse button. GLFW: Fixed mouse cursor support for multi-viewport with GLFW 3.3 (current master) - somehow doesn't appear to work with GLFW 3.2 but I'm not too fussed about it. (#1542)

This commit is contained in:
omar 2018-04-23 15:54:38 +02:00
parent f1c31ebc67
commit 423577e14e
5 changed files with 32 additions and 23 deletions

View File

@ -521,7 +521,6 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport)
ImGuiViewportDataDx10* data = IM_NEW(ImGuiViewportDataDx10)(); ImGuiViewportDataDx10* data = IM_NEW(ImGuiViewportDataDx10)();
viewport->RendererUserData = data; viewport->RendererUserData = data;
// FIXME-PLATFORM
HWND hwnd = (HWND)viewport->PlatformHandle; HWND hwnd = (HWND)viewport->PlatformHandle;
IM_ASSERT(hwnd != 0); IM_ASSERT(hwnd != 0);

View File

@ -605,7 +605,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
} }
// Setup back-end capabilities flags // Setup back-end capabilities flags
// FIXME-VIEWPORT: Actually unfinshed.. // FIXME-VIEWPORT: Actually unfinished..
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)

View File

@ -242,17 +242,22 @@ static void ImGui_ImplGlfw_UpdateMouse()
} }
// Update OS/hardware mouse cursor if imgui isn't drawing a software cursor // Update OS/hardware mouse cursor if imgui isn't drawing a software cursor
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) == 0 && glfwGetInputMode(g_Window, GLFW_CURSOR) != GLFW_CURSOR_DISABLED) if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) == 0 && glfwGetInputMode(g_Window, GLFW_CURSOR) != GLFW_CURSOR_DISABLED)
{ {
ImGuiMouseCursor cursor = ImGui::GetMouseCursor(); ImGuiMouseCursor cursor = ImGui::GetMouseCursor();
if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None) for (int n = 0; n < platform_io.Viewports.Size; n++)
{ {
glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); GLFWwindow* window = (GLFWwindow*)platform_io.Viewports[n]->PlatformHandle;
} if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None)
else {
{ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
glfwSetCursor(g_Window, g_MouseCursors[cursor] ? g_MouseCursors[cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]); }
glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); else
{
glfwSetCursor(window, g_MouseCursors[cursor] ? g_MouseCursors[cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
} }
} }
} }
@ -520,8 +525,8 @@ static int ImGui_ImplGlfw_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_inst
} }
#endif // GLFW_HAS_VULKAN #endif // GLFW_HAS_VULKAN
// FIXME-PLATFORM: Update when changed (using glfwSetMonitorCallback?) // FIXME-PLATFORM: Update monitor list when changed (using glfwSetMonitorCallback?)
// FIXME-PLATFORM: GLFW doesn't export work area (see https://github.com/glfw/glfw/pull/989) // FIXME-PLATFORM: GLFW doesn't export monitor work area (see https://github.com/glfw/glfw/pull/989)
static void ImGui_ImplGlfw_UpdateMonitors() static void ImGui_ImplGlfw_UpdateMonitors()
{ {
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();

View File

@ -30,15 +30,16 @@
#include "imgui_impl_sdl2.h" #include "imgui_impl_sdl2.h"
// SDL // SDL
// (the multi-viewports feature requires SDL features suppoted from SDL 2.0.5+) // (the multi-viewports feature requires SDL features supported from SDL 2.0.5+)
#include <SDL.h> #include <SDL.h>
#include <SDL_syswm.h> #include <SDL_syswm.h>
#define SDL_HAS_CAPTURE_MOUSE SDL_VERSION_ATLEAST(2,0,4) #define SDL_HAS_CAPTURE_MOUSE SDL_VERSION_ATLEAST(2,0,4)
#define SDL_HAS_WINDOW_OPACITY SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_WINDOW_OPACITY SDL_VERSION_ATLEAST(2,0,5)
#define SDL_HAS_ALWAYS_ON_TOP SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_ALWAYS_ON_TOP SDL_VERSION_ATLEAST(2,0,5)
#define SDL_HAS_USABLE_DISPLAY_BOUNDS SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_USABLE_DISPLAY_BOUNDS SDL_VERSION_ATLEAST(2,0,5)
#define SDL_HAS_PER_MONITOR_DPI SDL_VERSION_ATLEAST(2,0,4) #define SDL_HAS_PER_MONITOR_DPI SDL_VERSION_ATLEAST(2,0,4)
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6) #define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
#define SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH SDL_VERSION_ATLEAST(2,0,5)
#if !SDL_HAS_VULKAN #if !SDL_HAS_VULKAN
static const Uint32 SDL_WINDOW_VULKAN = 0x10000000; static const Uint32 SDL_WINDOW_VULKAN = 0x10000000;
#endif #endif
@ -231,7 +232,7 @@ static void ImGui_ImplSDL2_UpdateMouse()
io.MousePosViewport = viewport->ID; io.MousePosViewport = viewport->ID;
} }
// We already retrieve global mouse position, SDL_CaptureMouse() also let the OS know our drag outside boundaries shouldn't trigger, e.g.: OS window resize cursor // We already retrieve global mouse position, SDL_CaptureMouse() also let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't trigger the OS window resize cursor
// The function is only supported from SDL 2.0.4 (released Jan 2016) // The function is only supported from SDL 2.0.4 (released Jan 2016)
bool any_mouse_button_down = ImGui::IsAnyMouseDown(); bool any_mouse_button_down = ImGui::IsAnyMouseDown();
SDL_CaptureMouse(any_mouse_button_down ? SDL_TRUE : SDL_FALSE); SDL_CaptureMouse(any_mouse_button_down ? SDL_TRUE : SDL_FALSE);
@ -301,11 +302,10 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
ImGuiViewportDataSDL2* data = IM_NEW(ImGuiViewportDataSDL2)(); ImGuiViewportDataSDL2* data = IM_NEW(ImGuiViewportDataSDL2)();
viewport->PlatformUserData = data; viewport->PlatformUserData = data;
// Share GL resources with main context
// FIXME-PLATFORM
ImGuiViewport* main_viewport = ImGui::GetMainViewport(); ImGuiViewport* main_viewport = ImGui::GetMainViewport();
ImGuiViewportDataSDL2* main_viewport_data = (ImGuiViewportDataSDL2*)main_viewport->PlatformUserData; ImGuiViewportDataSDL2* main_viewport_data = (ImGuiViewportDataSDL2*)main_viewport->PlatformUserData;
// Share GL resources with main context
bool use_opengl = (main_viewport_data->GLContext != NULL); bool use_opengl = (main_viewport_data->GLContext != NULL);
SDL_GLContext backup_context = NULL; SDL_GLContext backup_context = NULL;
if (use_opengl) if (use_opengl)
@ -444,7 +444,7 @@ static int ImGui_ImplSDL2_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_inst
} }
#endif // SDL_HAS_VULKAN #endif // SDL_HAS_VULKAN
// FIXME-PLATFORM: Update when changed? // FIXME-PLATFORM: Update monitor list when changed?
static void ImGui_ImplSDL2_UpdateMonitors() static void ImGui_ImplSDL2_UpdateMonitors()
{ {
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
@ -490,6 +490,11 @@ static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_g
platform_io.Platform_CreateVkSurface = ImGui_ImplSDL2_CreateVkSurface; platform_io.Platform_CreateVkSurface = ImGui_ImplSDL2_CreateVkSurface;
#endif #endif
// SDL2 by default doesn't pass mouse clicks to the application when the click focused a window. This is getting in the way of our interactions and we disable that behavior.
#if SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
#endif
ImGui_ImplSDL2_UpdateMonitors(); ImGui_ImplSDL2_UpdateMonitors();
// Register main window handle (which is owned by the main application, not by us) // Register main window handle (which is owned by the main application, not by us)

View File

@ -566,7 +566,7 @@ static BOOL CALLBACK ImGui_ImplWin32_UpdateMonitors_EnumFunc(HMONITOR monitor, H
return TRUE; return TRUE;
} }
// FIXME-PLATFORM: Update list when changed (WM_DISPLAYCHANGE?) // FIXME-PLATFORM: Update monitor list when changed (WM_DISPLAYCHANGE?)
static void ImGui_ImplWin32_UpdateMonitors() static void ImGui_ImplWin32_UpdateMonitors()
{ {
ImGui::GetPlatformIO().Monitors.resize(0); ImGui::GetPlatformIO().Monitors.resize(0);