From 7adad7104207c4958cda2503e1ef3d67bc705bf9 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 28 Aug 2014 14:53:41 +0100 Subject: [PATCH] Moved IMGUI_FONT_TEX_UV_FOR_WHITE define to a variable so font can be changed at runtime --- imgui.cpp | 5 +++-- imgui.h | 5 +---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a634dd3b..da69ba37 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -105,7 +105,7 @@ - if you want to use a different font than the default - create bitmap font data using BMFont. allocate ImGui::GetIO().Font and use ->LoadFromFile()/LoadFromMemory(), set ImGui::GetIO().FontHeight - - load your texture yourself. texture *MUST* have white pixel at UV coordinate 'IMGUI_FONT_TEX_UV_FOR_WHITE' (you can #define it in imconfig.h), this is used by solid objects. + - load your texture yourself. texture *MUST* have white pixel at UV coordinate Imgui::GetIO().FontTexUvForWhite. This is used to draw all solid shapes. - tip: the construct 'if (IMGUI_ONCE_UPON_A_FRAME)' will evaluate to true only once a frame, you can use it to 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. @@ -279,6 +279,7 @@ ImGuiIO::ImGuiIO() IniFilename = "imgui.ini"; LogFilename = "imgui_log.txt"; Font = NULL; + FontTexUvForWhite = ImVec2(0.0f,0.0f); FontAllowScaling = false; PixelCenterOffset = 0.0f; MousePos = ImVec2(-1,-1); @@ -4812,7 +4813,7 @@ void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col) { vtx_write->pos = pos; vtx_write->col = col; - vtx_write->uv = IMGUI_FONT_TEX_UV_FOR_WHITE; + vtx_write->uv = GImGui.IO.FontTexUvForWhite; vtx_write++; } diff --git a/imgui.h b/imgui.h index 7ca519ad..5e3ff74b 100644 --- a/imgui.h +++ b/imgui.h @@ -390,6 +390,7 @@ struct ImGuiIO int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array ImFont Font; // // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font). float FontHeight; // // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y + ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture. bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel. float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry @@ -524,10 +525,6 @@ struct ImDrawCmd ImVec4 clip_rect; }; -#ifndef IMGUI_FONT_TEX_UV_FOR_WHITE -#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f,0.f) -#endif - // sizeof() == 20 struct ImDrawVert {