From ba9317b9247462da08449cbad136608d9453fb2b Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 13 Jul 2015 16:08:49 -0600 Subject: [PATCH] ImFont: storing offsets as X0/Y0/X1/Y1 analoguous to examples for stb_truetype --- imgui.cpp | 20 ++++++++++---------- imgui.h | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a91c256c3..551dbbf90 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9968,15 +9968,15 @@ bool ImFontAtlas::Build() data.OutFont->Glyphs.resize(data.OutFont->Glyphs.Size + 1); ImFont::Glyph& glyph = data.OutFont->Glyphs.back(); glyph.Codepoint = (ImWchar)(range.first_unicode_char_in_range + char_idx); - glyph.Width = (signed short)pc.x1 - pc.x0 + 1; - glyph.Height = (signed short)pc.y1 - pc.y0 + 1; - glyph.XOffset = (signed short)(pc.xoff); - glyph.YOffset = (signed short)(pc.yoff + (int)(font_ascent * font_scale)); + glyph.X0 = (signed short)(pc.xoff); + glyph.Y0 = (signed short)(pc.yoff + (int)(font_ascent * font_scale)); + glyph.X1 = glyph.X0 + ((signed short)pc.x1 - pc.x0 + 1); + glyph.Y1 = glyph.Y0 + ((signed short)pc.y1 - pc.y0 + 1); glyph.XAdvance = (signed short)(pc.xadvance + character_spacing_x); // Bake spacing into XAdvance glyph.U0 = ((float)pc.x0 - 0.5f) * uv_scale_x; glyph.V0 = ((float)pc.y0 - 0.5f) * uv_scale_y; - glyph.U1 = ((float)pc.x0 - 0.5f + glyph.Width) * uv_scale_x; - glyph.V1 = ((float)pc.y0 - 0.5f + glyph.Height) * uv_scale_y; + glyph.U1 = ((float)pc.x0 - 0.5f + (glyph.X1 - glyph.X0)) * uv_scale_x; + glyph.V1 = ((float)pc.y0 - 0.5f + (glyph.Y1 - glyph.Y0)) * uv_scale_y; } } @@ -10735,11 +10735,11 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re if (c != ' ' && c != '\t') { // We don't do a second finer clipping test on the Y axis (todo: do some measurement see if it is worth it, probably not) - float y1 = (float)(y + glyph->YOffset * scale); - float y2 = (float)(y1 + glyph->Height * scale); + float y1 = (float)(y + glyph->Y0 * scale); + float y2 = (float)(y + glyph->Y1 * scale); - float x1 = (float)(x + glyph->XOffset * scale); - float x2 = (float)(x1 + glyph->Width * scale); + float x1 = (float)(x + glyph->X0 * scale); + float x2 = (float)(x + glyph->X1 * scale); if (x1 <= clip_rect.z && x2 >= clip_rect.x) { // Render a character diff --git a/imgui.h b/imgui.h index 09df6bf7a..7870b3b91 100644 --- a/imgui.h +++ b/imgui.h @@ -1185,8 +1185,7 @@ struct ImFont { ImWchar Codepoint; signed short XAdvance; - signed short Width, Height; - signed short XOffset, YOffset; + signed short X0, Y0, X1, Y1; float U0, V0, U1, V1; // Texture coordinates }; float Ascent; // Distance from top to bottom of e.g. 'A' [0..FontSize]