fix text zoom

This commit is contained in:
2019-09-19 10:14:05 +02:00
parent 4f9383aba7
commit 814fd76292
2 changed files with 12 additions and 13 deletions

View File

@@ -15,7 +15,7 @@ bool Font::load(const std::string& ttf, int font_size, float font_scale)
LOG("Font::load %s", ttf.c_str());
if (file.open(ttf.c_str()) && file.read_all())
{
w = h = 512 * ceilf(font_scale);
w = h = 512 * (int)ceilf(font_scale);
path = ttf;
scale = font_scale;
LOG("Font::load loaded");
@@ -162,27 +162,27 @@ void TextMesh::update(kFont id, const std::string& text)
for (auto p : parts)
{
if (max_width > 0 && (x + p.w) * f.scale > max_width)
if (max_width > 0 && (x + p.w) > max_width * f.scale)
{
x = 0;
y += spacing;
y += spacing * f.scale;
}
for (char c : p.s)
{
if (c == '\n')
{
x = 0;
y += spacing;
cur_box = glm::vec4(x, y + f.bounds.y, 5, avg_width);
y += spacing * f.scale;
cur_box = glm::vec4(x, y / f.scale + f.bounds.y, 5, avg_width);
continue;
}
if (max_width > 0 && x > max_width * f.scale /*font scale factor*/)
{
x = 0;
y += spacing * f.scale;
}
stbtt_aligned_quad q;
stbtt_GetBakedQuad((stbtt_bakedchar*)f.chars.data(), f.w, f.h, c - f.start_char, &x, &y, &q, true);
if (max_width > 0 && x * f.scale > max_width /*font scale factor*/)
{
x = 0;
y += spacing;
}
auto n = (int)v.size();
v.emplace_back(q.x0 / f.scale, q.y1 / f.scale, q.s0, q.t1);
v.emplace_back(q.x0 / f.scale, q.y0 / f.scale, q.s0, q.t0);
@@ -196,7 +196,7 @@ void TextMesh::update(kFont id, const std::string& text)
idx.push_back(n + 3);
bbmin = glm::min(bbmin, xy(f.bounds));
bbmax = glm::max(bbmax, { q.x1 / f.scale, y + f.bounds.w });
cur_box = glm::vec4(q.x1 / f.scale + 2, y + f.bounds.y, 5, avg_width);
cur_box = glm::vec4(q.x1 / f.scale + 2, y / f.scale + f.bounds.y, 5, avg_width);
}
}
for (auto& vi : v)

View File

@@ -116,6 +116,5 @@ void NodeText::draw()
void NodeText::handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoom)
{
if (old_size != new_size)
m_text_mesh.update(font_id, m_text);
m_text_mesh.update(font_id, m_text);
}