| 313 | } |
| 314 | |
| 315 | void MutableLabel::Precache(PrecacheParams const & params, PrecacheResult & result, ref_ptr<dp::TextureManager> mng) |
| 316 | { |
| 317 | SetMaxLength(static_cast<uint16_t>(params.m_maxLength)); |
| 318 | |
| 319 | m_textRatio = params.m_font.m_size * static_cast<float>(df::VisualParams::Instance().GetVisualScale()) / |
| 320 | dp::kBaseFontSizePixels; |
| 321 | |
| 322 | // TODO(AB): Is this shaping/precaching really needed if the text changes every frame? |
| 323 | m_shapedText = mng->ShapeSingleTextLine(dp::kBaseFontSizePixels, params.m_alphabet, &m_glyphRegions); |
| 324 | |
| 325 | auto const firstTexture = m_glyphRegions.front().GetTexture(); |
| 326 | #ifdef DEBUG |
| 327 | for (auto const & region : m_glyphRegions) |
| 328 | ASSERT_EQUAL(firstTexture, region.GetTexture(), ()); |
| 329 | #endif |
| 330 | result.m_state.SetMaskTexture(firstTexture); |
| 331 | |
| 332 | dp::TextureManager::ColorRegion color; |
| 333 | dp::TextureManager::ColorRegion outlineColor; |
| 334 | |
| 335 | mng->GetColorRegion(params.m_font.m_color, color); |
| 336 | mng->GetColorRegion(params.m_font.m_outlineColor, outlineColor); |
| 337 | result.m_state.SetColorTexture(color.GetTexture()); |
| 338 | |
| 339 | glsl::vec2 colorTex = glsl::ToVec2(color.GetTexRect().Center()); |
| 340 | glsl::vec2 outlineTex = glsl::ToVec2(outlineColor.GetTexRect().Center()); |
| 341 | |
| 342 | auto const vertexCount = m_maxLength * dp::Batcher::VertexPerQuad; |
| 343 | result.m_buffer.resize(vertexCount, StaticVertex(glsl::vec3(0.0, 0.0, 0.0), colorTex, outlineTex)); |
| 344 | |
| 345 | float depth = 0.0f; |
| 346 | for (size_t i = 0; i < vertexCount; i += 4) |
| 347 | { |
| 348 | result.m_buffer[i + 0].m_position.z = depth; |
| 349 | result.m_buffer[i + 1].m_position.z = depth; |
| 350 | result.m_buffer[i + 2].m_position.z = depth; |
| 351 | result.m_buffer[i + 3].m_position.z = depth; |
| 352 | depth += 10.0f; |
| 353 | } |
| 354 | |
| 355 | result.m_maxPixelSize = m2::PointF(m_shapedText.m_lineWidthInPixels, m_shapedText.m_maxLineHeightInPixels); |
| 356 | } |
| 357 | |
| 358 | void MutableLabel::SetText(LabelResult & result, std::string text, ref_ptr<dp::TextureManager> mng) |
| 359 | { |
no test coverage detected