From 3b339efeb2ac8e1f8299213def138c197366079e Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 30 Aug 2014 20:02:10 +0100 Subject: [PATCH] Added IO.FontYOffset. Added asserts. --- imgui.cpp | 10 ++++++++-- imgui.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a1115188..632e278a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -279,6 +279,7 @@ ImGuiIO::ImGuiIO() IniFilename = "imgui.ini"; LogFilename = "imgui_log.txt"; Font = NULL; + FontYOffset = 0.0f; FontTexUvForWhite = ImVec2(0.0f,0.0f); FontAllowScaling = false; PixelCenterOffset = 0.0f; @@ -1199,6 +1200,7 @@ void NewFrame() ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL); g.IO.Font = new ImBitmapFont(); g.IO.Font->LoadFromMemory(fnt_data, fnt_size); + g.IO.FontYOffset = +1; } g.Initialized = true; } @@ -5093,6 +5095,8 @@ void ImBitmapFont::Clear() bool ImBitmapFont::LoadFromFile(const char* filename) { + IM_ASSERT(!IsLoaded()); // Call Clear() + // Load file FILE* f; if ((f = fopen(filename, "rb")) == NULL) @@ -5123,7 +5127,9 @@ bool ImBitmapFont::LoadFromFile(const char* filename) bool ImBitmapFont::LoadFromMemory(const void* data, size_t data_size) { - Data = (unsigned char*)data; + IM_ASSERT(!IsLoaded()); // Call Clear() + + Data = (unsigned char*)data; DataSize = data_size; // Parse data @@ -5262,7 +5268,7 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c // Align to be pixel perfect pos.x = (float)(int)pos.x; - pos.y = (float)(int)pos.y; + pos.y = (float)(int)pos.y + GImGui.IO.FontYOffset; const ImVec4 clip_rect = clip_rect_ref; diff --git a/imgui.h b/imgui.h index f75a68e7..c8ffeedb 100644 --- a/imgui.h +++ b/imgui.h @@ -391,6 +391,7 @@ struct ImGuiIO float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. 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 FontYOffset; // = 0.0f // Offset font rendering by xx pixels in Y axis. 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