summaryrefslogtreecommitdiff
path: root/indra/newview/llhudnametag.cpp
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2020-09-28 22:39:06 +0300
committerAndrey Lihatskiy <alihatskiy@productengine.com>2020-09-28 22:39:06 +0300
commit83822fd1992140b85966ca613b026c4bc6c38005 (patch)
tree8dadfcd76a9c27193e8009d1d361e91e41cf7e71 /indra/newview/llhudnametag.cpp
parent652e8459001e052edd6eeef0b919d4d68c8daa58 (diff)
parentbac6652cdcd2d8333df04c3ebd3a6a7b752328b3 (diff)
Merge branch 'master' into DRTVWR-516-maint
# Conflicts: # indra/newview/llvocache.cpp
Diffstat (limited to 'indra/newview/llhudnametag.cpp')
-rw-r--r--indra/newview/llhudnametag.cpp61
1 files changed, 48 insertions, 13 deletions
diff --git a/indra/newview/llhudnametag.cpp b/indra/newview/llhudnametag.cpp
index fa89d3986d..9d49c30a49 100644
--- a/indra/newview/llhudnametag.cpp
+++ b/indra/newview/llhudnametag.cpp
@@ -414,7 +414,8 @@ void LLHUDNameTag::clearString()
void LLHUDNameTag::addLine(const std::string &text_utf8,
const LLColor4& color,
const LLFontGL::StyleFlags style,
- const LLFontGL* font)
+ const LLFontGL* font,
+ const bool use_ellipses)
{
LLWString wline = utf8str_to_wstring(text_utf8);
if (!wline.empty())
@@ -431,18 +432,52 @@ void LLHUDNameTag::addLine(const std::string &text_utf8,
tokenizer tokens(wline, sep);
tokenizer::iterator iter = tokens.begin();
- while (iter != tokens.end())
- {
- U32 line_length = 0;
- do
- {
- F32 max_pixels = HUD_TEXT_MAX_WIDTH;
- S32 segment_length = font->maxDrawableChars(iter->substr(line_length).c_str(), max_pixels, wline.length(), LLFontGL::WORD_BOUNDARY_IF_POSSIBLE);
- LLHUDTextSegment segment(iter->substr(line_length, segment_length), style, color, font);
- mTextSegments.push_back(segment);
- line_length += segment_length;
- }
- while (line_length != iter->size());
+ const F32 max_pixels = HUD_TEXT_MAX_WIDTH;
+ while (iter != tokens.end())
+ {
+ U32 line_length = 0;
+ if (use_ellipses)
+ {
+ // "QualityAssuranceAssuresQuality1" will end up like "QualityAssuranceAssuresQual..."
+ // "QualityAssuranceAssuresQuality QualityAssuranceAssuresQuality" will end up like "QualityAssuranceAssuresQual..."
+ // "QualityAssurance AssuresQuality1" will end up as "QualityAssurance AssuresQua..." because we are enforcing single line
+ do
+ {
+ S32 segment_length = font->maxDrawableChars(iter->substr(line_length).c_str(), max_pixels, wline.length(), LLFontGL::ANYWHERE);
+ if (segment_length + line_length < wline.length()) // since we only draw one string, line_length should be 0
+ {
+ // token does does not fit into signle line, need to draw "...".
+ // Use four dots for ellipsis width to generate padding
+ const LLWString dots_pad(utf8str_to_wstring(std::string("....")));
+ S32 elipses_width = font->getWidthF32(dots_pad.c_str());
+ // truncated string length
+ segment_length = font->maxDrawableChars(iter->substr(line_length).c_str(), max_pixels - elipses_width, wline.length(), LLFontGL::ANYWHERE);
+ const LLWString dots(utf8str_to_wstring(std::string("...")));
+ LLHUDTextSegment segment(iter->substr(line_length, segment_length) + dots, style, color, font);
+ mTextSegments.push_back(segment);
+ break; // consider it to be complete
+ }
+ else
+ {
+ // token fits fully into string
+ LLHUDTextSegment segment(iter->substr(line_length, segment_length), style, color, font);
+ mTextSegments.push_back(segment);
+ line_length += segment_length;
+ }
+ } while (line_length != iter->size());
+ }
+ else
+ {
+ // "QualityAssuranceAssuresQuality 1" will be split into two lines "QualityAssuranceAssuresQualit" and "y 1"
+ // "QualityAssurance AssuresQuality 1" will be split into two lines "QualityAssurance" and "AssuresQuality"
+ do
+ {
+ S32 segment_length = font->maxDrawableChars(iter->substr(line_length).c_str(), max_pixels, wline.length(), LLFontGL::WORD_BOUNDARY_IF_POSSIBLE);
+ LLHUDTextSegment segment(iter->substr(line_length, segment_length), style, color, font);
+ mTextSegments.push_back(segment);
+ line_length += segment_length;
+ } while (line_length != iter->size());
+ }
++iter;
}
}