mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Viewport, Platform: Fixed IME positioning for multi-viewport. Moved API from ImGuiIO to ImGuiPlatformIO. Because it is extremely unlikely to people redefined this API manually the moving-forward-breakage is ok. (#1542)
SDL2 ime support under Win32 never worked properly because of SDL interferences.
This commit is contained in:
@ -199,10 +199,6 @@ bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display)
|
||||
io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y;
|
||||
io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z;
|
||||
|
||||
#ifdef _WIN32
|
||||
io.ImeWindowHandle = al_get_win_window_handle(g_Display);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -150,9 +150,6 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
|
||||
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
|
||||
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
|
||||
io.ClipboardUserData = g_Window;
|
||||
#ifdef _WIN32
|
||||
io.ImeWindowHandle = glfwGetWin32Window(g_Window);
|
||||
#endif
|
||||
|
||||
g_MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||
g_MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
|
||||
@ -500,7 +497,33 @@ static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||
glfwSwapBuffers(data->Window);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// IME (Input Method Editor) basic support for e.g. Asian language users
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
// We provide a Win32 implementation because this is such a common issue for IME users
|
||||
#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) && !defined(__GNUC__)
|
||||
#define HAS_WIN32_IME 1
|
||||
#include <imm.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "imm32")
|
||||
#endif
|
||||
static void ImGui_ImplWin32_SetImeInputPos(ImGuiViewport* viewport, ImVec2 pos)
|
||||
{
|
||||
COMPOSITIONFORM cf = { CFS_FORCE_POSITION, { (LONG)(pos.x - viewport->Pos.x), (LONG)(pos.y - viewport->Pos.y) }, { 0, 0, 0, 0 } };
|
||||
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
|
||||
if (HWND hwnd = glfwGetWin32Window(data->Window))
|
||||
if (HIMC himc = ImmGetContext(hwnd))
|
||||
ImmSetCompositionWindow(himc, &cf);
|
||||
}
|
||||
#else
|
||||
#define HAS_WIN32_IME 0
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// Vulkan support (the Vulkan renderer needs to call a platform-side support function to create the surface)
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Avoid including <vulkan.h> so we can build without it
|
||||
#if GLFW_HAS_VULKAN
|
||||
#ifndef VULKAN_H_
|
||||
@ -571,6 +594,9 @@ static void ImGui_ImplGlfw_InitPlatformInterface()
|
||||
#if GLFW_HAS_VULKAN
|
||||
platform_io.Platform_CreateVkSurface = ImGui_ImplGlfw_CreateVkSurface;
|
||||
#endif
|
||||
#if HAS_WIN32_IME
|
||||
platform_io.Platform_SetImeInputPos = ImGui_ImplWin32_SetImeInputPos;
|
||||
#endif
|
||||
|
||||
ImGui_ImplGlfw_UpdateMonitors();
|
||||
|
||||
|
@ -170,13 +170,6 @@ bool ImGui_ImplSDL2_Init(SDL_Window* window, void* sdl_gl_context)
|
||||
g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
|
||||
g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
|
||||
|
||||
#ifdef _WIN32
|
||||
SDL_SysWMinfo wmInfo;
|
||||
SDL_VERSION(&wmInfo.version);
|
||||
SDL_GetWindowWMInfo(window, &wmInfo);
|
||||
io.ImeWindowHandle = wmInfo.info.win.window;
|
||||
#endif
|
||||
|
||||
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
main_viewport->PlatformHandle = (void*)window;
|
||||
|
@ -76,8 +76,6 @@ bool ImGui_ImplWin32_Init(void* hwnd)
|
||||
io.KeyMap[ImGuiKey_Y] = 'Y';
|
||||
io.KeyMap[ImGuiKey_Z] = 'Z';
|
||||
|
||||
io.ImeWindowHandle = g_hWnd;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -279,7 +277,7 @@ IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPa
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// DPI handling
|
||||
// Those in theory should be simple calls but Windows has multiple ways to handle DPI, and most of them
|
||||
// require recent Windows versions at runtime or recent Windows SDK at compile-time. Neither we want to depend on.
|
||||
@ -370,9 +368,30 @@ float ImGui_ImplWin32_GetDpiScaleForRect(int x1, int y1, int x2, int y2)
|
||||
return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// IME (Input Method Editor) basic support for e.g. Asian language users
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) && !defined(__GNUC__)
|
||||
#define HAS_WIN32_IME 1
|
||||
#include <imm.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "imm32")
|
||||
#endif
|
||||
static void ImGui_ImplWin32_SetImeInputPos(ImGuiViewport* viewport, ImVec2 pos)
|
||||
{
|
||||
COMPOSITIONFORM cf = { CFS_FORCE_POSITION,{ (LONG)(pos.x - viewport->Pos.x), (LONG)(pos.y - viewport->Pos.y) },{ 0, 0, 0, 0 } };
|
||||
if (HWND hwnd = (HWND)viewport->PlatformHandle)
|
||||
if (HIMC himc = ImmGetContext(hwnd))
|
||||
ImmSetCompositionWindow(himc, &cf);
|
||||
}
|
||||
#else
|
||||
#define HAS_WIN32_IME 0
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// Platform Windows
|
||||
// --------------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
struct ImGuiViewportDataWin32
|
||||
{
|
||||
@ -625,6 +644,9 @@ static void ImGui_ImplWin32_InitPlatformInterface()
|
||||
platform_io.Platform_SetWindowAlpha = ImGui_ImplWin32_SetWindowAlpha;
|
||||
platform_io.Platform_GetWindowDpiScale = ImGui_ImplWin32_GetWindowDpiScale;
|
||||
platform_io.Platform_OnChangedViewport = ImGui_ImplWin32_OnChangedViewport; // FIXME-DPI
|
||||
#if HAS_WIN32_IME
|
||||
platform_io.Platform_SetImeInputPos = ImGui_ImplWin32_SetImeInputPos;
|
||||
#endif
|
||||
|
||||
// Register main window handle (which is owned by the main application, not by us)
|
||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
|
Reference in New Issue
Block a user