diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index bb5be23c..dd16f834 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -1,5 +1,4 @@ #include -#include #define STB_IMAGE_IMPLEMENTATION #include "../shared/stb_image.h" // for .png loading #include "../../imgui.h" @@ -344,19 +343,6 @@ 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; @@ -385,7 +371,6 @@ void InitImGui() io.KeyMap[ImGuiKey_Z] = 'Z'; io.RenderDrawListsFn = ImImpl_RenderDrawLists; - io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; // Create the vertex buffer { diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 94249de9..ac8c2105 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -1,5 +1,4 @@ #include -#include #include "../../imgui.h" // DirectX @@ -175,19 +174,6 @@ 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; @@ -216,7 +202,6 @@ 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 dbf29e26..2fce58f0 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -1,7 +1,6 @@ #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 "../shared/stb_image.h" // for .png loading @@ -100,22 +99,6 @@ static void ImImpl_SetClipboardTextFn(const char* text) 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) { @@ -204,9 +187,6 @@ 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/imgui.cpp b/imgui.cpp index 3a37af2a..059c36cf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -125,19 +125,11 @@ TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS ============================================ - - if text or lines are blurry when integrating ImGui in your engine: + If text or lines are blurry when integrating ImGui in your engine: - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f - - if you want to use a different font than the default: - - create bitmap font data using BMFont, make sure that BMFont is exporting the .fnt file in Binary mode. - io.Font = new ImBitmapFont(); - io.Font->LoadFromFile("path_to_your_fnt_file.fnt"); - - load your texture yourself. texture *MUST* have white pixel at UV coordinate io.Font->TexUvForWhite. This is used to draw all solid shapes. - - the extra_fonts/ folder provides examples of using external fonts. - - if you can only see text but no solid shapes or lines, make sure io.Font->TexUvForWhite is set to the texture coordinates of a pure white pixel in your texture! - - - if you are confused about the meaning or use of ID in ImGui: + If you are confused about the meaning or use of ID in ImGui: - some widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget). to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer. when you call Button("OK") the button shows "OK" and also use "OK" as an ID. @@ -155,6 +147,33 @@ e.g. "##Foobar" display an empty label and uses "##Foobar" as ID - read articles about the imgui principles (see web links) to understand the requirement and use of ID. + If you want to use a different font than the default: + - read extra_fonts/README.txt for instructions. Examples fonts are also provided. + - if you can only see text but no solid shapes or lines, make sure io.Font->TexUvForWhite is set to the texture coordinates of a pure white pixel in your texture! + + If you want to input Japanese/Chinese/Korean in the text input widget: + - make sure you are using a font that can display the glyphs you want (see above paragraph about fonts) + - to have the Microsoft IME cursor appears at the right location in the screen, setup a handler for the io.ImeSetInputScreenPosFn function: + + #include + #include + static void ImImpl_ImeSetInputScreenPosFn(int x, int y) + { + // Notify OS Input Method Editor of text input position + 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); + } + } + + // Set pointer to handler in ImGuiIO structure + io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; + - tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will evaluate to a block of code only once a frame. You can use it to quickly add custom UI in the middle of a deep nested inner loop in your code. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function. - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"