3
3
SingleLineText::SingleLineText (core::smart_refctd_ptr<nbl::ext::TextRendering::FontFace>&& face, const std::string& text)
4
4
{
5
5
m_face = std::move (face);
6
- glyphBoxes.reserve (text.length ());
6
+ m_glyphBoxes.reserve (text.length ());
7
+
8
+ m_boundingBox.min = float64_t2 (0.0 , 0.0 );
9
+ m_boundingBox.max = float64_t2 (0.0 , 0.0 );
7
10
8
11
// Position transform
9
12
float64_t2 currentPos = float32_t2 (0.0 , 0.0 );
10
13
for (uint32_t i = 0 ; i < text.length (); i++)
11
14
{
12
15
const auto glyphIndex = m_face->getGlyphIndex (wchar_t (text.at (i)));
13
- const auto glyphMetrics = m_face->getGlyphMetricss (glyphIndex);
16
+ const auto glyphMetrics = m_face->getGlyphMetrics (glyphIndex);
14
17
const bool skipGenerateGlyph = (glyphIndex == 0 || (glyphMetrics.size .x == 0.0 && glyphMetrics.size .y == 0.0 ));
15
18
16
19
if (!skipGenerateGlyph)
@@ -25,7 +28,13 @@ SingleLineText::SingleLineText(core::smart_refctd_ptr<nbl::ext::TextRendering::F
25
28
.size = glyphMetrics.size ,
26
29
.glyphIdx = glyphIndex,
27
30
};
28
- glyphBoxes.push_back (glyphBbox);
31
+
32
+ m_boundingBox.min .x = nbl::core::min (m_boundingBox.min .x , glyphBbox.topLeft .x );
33
+ m_boundingBox.min .y = nbl::core::min (m_boundingBox.min .y , glyphBbox.topLeft .y - glyphBbox.size .y );
34
+ m_boundingBox.max .x = nbl::core::max (m_boundingBox.max .x , glyphBbox.topLeft .x + glyphBbox.size .x );
35
+ m_boundingBox.max .y = nbl::core::max (m_boundingBox.max .y , glyphBbox.topLeft .y );
36
+
37
+ m_glyphBoxes.push_back (glyphBbox);
29
38
}
30
39
currentPos += glyphMetrics.advance ;
31
40
}
@@ -36,7 +45,8 @@ void SingleLineText::Draw(
36
45
SIntendedSubmitInfo& intendedNextSubmit,
37
46
const float64_t2& baselineStart,
38
47
const float32_t2& scale,
39
- const float32_t & rotateAngle)
48
+ const float32_t & rotateAngle,
49
+ const float32_t4& color) const
40
50
{
41
51
float32_t2 vec (cos (rotateAngle), sin (rotateAngle));
42
52
float64_t3x3 rotationMulScaleMat =
@@ -54,11 +64,11 @@ void SingleLineText::Draw(
54
64
float64_t3x3 transformation = mul (translationMat, rotationMulScaleMat);
55
65
56
66
LineStyleInfo lineStyle = {};
57
- lineStyle.color = float32_t4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
67
+ lineStyle.color = color ;
58
68
const uint32_t styleIdx = drawResourcesFiller.addLineStyle_SubmitIfNeeded (lineStyle, intendedNextSubmit);
59
69
auto glyphObjectIdx = drawResourcesFiller.addMainObject_SubmitIfNeeded (styleIdx, intendedNextSubmit);
60
70
61
- for (const auto & glyphBox : glyphBoxes )
71
+ for (const auto & glyphBox : m_glyphBoxes )
62
72
{
63
73
const float64_t2 topLeft = mul (transformation, float64_t3 (glyphBox.topLeft , 1.0 )).xy ;
64
74
const float64_t2 dirU = mul (transformation, float64_t3 (glyphBox.size .x , 0.0 , 0.0 )).xy ;
@@ -70,5 +80,4 @@ void SingleLineText::Draw(
70
80
drawResourcesFiller.drawFontGlyph (m_face.get (), glyphBox.glyphIdx , topLeft, dirU, aspectRatio, minUV, glyphObjectIdx, intendedNextSubmit);
71
81
}
72
82
73
- }
74
-
83
+ }
0 commit comments