diff --git a/examples/directx9_example/directx9_example.vcxproj b/examples/directx9_example/directx9_example.vcxproj index 0aba1116..df288311 100644 --- a/examples/directx9_example/directx9_example.vcxproj +++ b/examples/directx9_example/directx9_example.vcxproj @@ -46,7 +46,7 @@ true $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories) - d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;gdi32.lib;user32.lib + d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;gdi32.lib;imm32.lib;user32.lib @@ -64,7 +64,7 @@ true true $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories) - d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;gdi32.lib;user32.lib + d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;gdi32.lib;imm32.lib;user32.lib diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 28630ab5..4bbcbcbd 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #define DIRECTINPUT_VERSION 0x0800 @@ -163,8 +164,8 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) return true; case WM_CHAR: // You can also use ToAscii()+GetKeyboardState() to retrieve characters. - if (wParam > 1 && wParam < 256) - io.AddInputCharacter((char)wParam); + if (wParam > 0 && wParam < 0x10000) + io.AddInputCharacter((unsigned short)wParam); return true; case WM_DESTROY: { @@ -176,6 +177,19 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) return DefWindowProc(hWnd, msg, wParam, lParam); } +// Notify OS Input Method Editor of text input position (e.g. when using Japanese/Chinese inputs, otherwise this isn't needed) +static void ImImpl_ImeSetInputScreenPosFn(int x, int y) +{ + if (HIMC himc = ImmGetContext(hWnd)) + { + COMPOSITIONFORM cf; + cf.ptCurrentPos.x = x; + cf.ptCurrentPos.y = y; + cf.dwStyle = CFS_FORCE_POSITION; + ImmSetCompositionWindow(himc, &cf); + } +} + void InitImGui() { RECT rect; @@ -204,6 +218,7 @@ void InitImGui() io.KeyMap[ImGuiKey_Z] = 'Z'; io.RenderDrawListsFn = ImImpl_RenderDrawLists; + io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; // Create the vertex buffer if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0) diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 17b8a938..6fc374a8 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -1,11 +1,20 @@ -#define GLEW_STATIC -#include -#include +#ifdef _MSC_VER +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#include +#include +#endif #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" // for .png loading #include "../../imgui.h" + +// glew & glfw +#define GLEW_STATIC +#include +#include #ifdef _MSC_VER -#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#define GLFW_EXPOSE_NATIVE_WIN32 +#define GLFW_EXPOSE_NATIVE_WGL +#include #endif static GLFWwindow* window; @@ -70,32 +79,32 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c glDisableClientState(GL_VERTEX_ARRAY); } +// NB: ImGui already provide OS clipboard support for Windows so this isn't needed if you are using Windows only. static const char* ImImpl_GetClipboardTextFn() { return glfwGetClipboardString(window); } -static void ImImpl_SetClipboardTextFn(const char* text, const char* text_end) +static void ImImpl_SetClipboardTextFn(const char* text) { - if (!text_end) - text_end = text + strlen(text); - - if (*text_end == 0) - { - // Already got a zero-terminator at 'text_end', we don't need to add one - glfwSetClipboardString(window, text); - } - else - { - // Add a zero-terminator because glfw function doesn't take a size - char* buf = (char*)malloc(text_end - text + 1); - memcpy(buf, text, text_end-text); - buf[text_end-text] = '\0'; - glfwSetClipboardString(window, buf); - free(buf); - } + glfwSetClipboardString(window, text); } +#ifdef _MSC_VER +// Notify OS Input Method Editor of text input position (e.g. when using Japanese/Chinese inputs, otherwise this isn't needed) +static void ImImpl_ImeSetInputScreenPosFn(int x, int y) +{ + HWND hwnd = glfwGetWin32Window(window); + if (HIMC himc = ImmGetContext(hwnd)) + { + COMPOSITIONFORM cf; + cf.ptCurrentPos.x = x; + cf.ptCurrentPos.y = y; + cf.dwStyle = CFS_FORCE_POSITION; + ImmSetCompositionWindow(himc, &cf); + } +} +#endif // GLFW callbacks to get events static void glfw_error_callback(int error, const char* description) @@ -122,8 +131,8 @@ static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int act static void glfw_char_callback(GLFWwindow* window, unsigned int c) { - if (c > 0 && c <= 255) - ImGui::GetIO().AddInputCharacter((char)c); + if (c > 0 && c < 0x10000) + ImGui::GetIO().AddInputCharacter((unsigned short)c); } // OpenGL code based on http://open.gl tutorials @@ -178,6 +187,9 @@ void InitImGui() io.RenderDrawListsFn = ImImpl_RenderDrawLists; io.SetClipboardTextFn = ImImpl_SetClipboardTextFn; io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; +#ifdef _MSC_VER + io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; +#endif // Load font texture glGenTextures(1, &fontTex); diff --git a/examples/opengl_example/opengl_example.vcxproj b/examples/opengl_example/opengl_example.vcxproj index b12c917f..0ff40ca9 100644 --- a/examples/opengl_example/opengl_example.vcxproj +++ b/examples/opengl_example/opengl_example.vcxproj @@ -46,7 +46,7 @@ true $(SolutionDir)\glfw\lib-msvc100;$(SolutionDir)\glew\lib\Release\Win32;%(AdditionalLibraryDirectories) - opengl32.lib;glfw3.lib;glew32s.lib;%(AdditionalDependencies) + opengl32.lib;imm32.lib;glfw3.lib;glew32s.lib;%(AdditionalDependencies) NotSet @@ -63,7 +63,7 @@ true true $(SolutionDir)\glfw\lib-msvc100;$(SolutionDir)\glew\lib\Release\Win32;%(AdditionalLibraryDirectories) - opengl32.lib;glfw3.lib;glew32s.lib;%(AdditionalDependencies) + opengl32.lib;imm32.lib;glfw3.lib;glew32s.lib;%(AdditionalDependencies) NotSet