MCPcopy Create free account
hub / github.com/ddnet/ddnet / CalcFontSizeCursorHeightAndBoundingBox

Function CalcFontSizeCursorHeightAndBoundingBox

src/game/client/ui.cpp:723–756  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

721};
722
723static SCursorAndBoundingBox CalcFontSizeCursorHeightAndBoundingBox(ITextRender *pTextRender, const char *pText, int Flags, float &Size, float MaxWidth, const SLabelProperties &LabelProps)
724{
725 const float MaxTextWidth = LabelProps.m_MaxWidth != -1.0f ? LabelProps.m_MaxWidth : MaxWidth;
726 const int FlagsWithoutStop = Flags & ~(TEXTFLAG_STOP_AT_END | TEXTFLAG_ELLIPSIS_AT_END);
727 const float MaxTextWidthWithoutStop = Flags == FlagsWithoutStop ? LabelProps.m_MaxWidth : -1.0f;
728
729 float TextBoundingHeight = 0.0f;
730 float TextHeight = 0.0f;
731 int LineCount = 0;
732 STextSizeProperties TextSizeProps{};
733 TextSizeProps.m_pHeight = &TextHeight;
734 TextSizeProps.m_pMaxCharacterHeightInLine = &TextBoundingHeight;
735 TextSizeProps.m_pLineCount = &LineCount;
736
737 float TextWidth;
738 do
739 {
740 Size = maximum(Size, LabelProps.m_MinimumFontSize);
741 // Only consider stop-at-end and ellipsis-at-end when minimum font size reached or font scaling disabled
742 if((Size == LabelProps.m_MinimumFontSize || !LabelProps.m_EnableWidthCheck) && Flags != FlagsWithoutStop)
743 TextWidth = pTextRender->TextWidth(Size, pText, -1, LabelProps.m_MaxWidth, Flags, TextSizeProps);
744 else
745 TextWidth = pTextRender->TextWidth(Size, pText, -1, MaxTextWidthWithoutStop, FlagsWithoutStop, TextSizeProps);
746 if(TextWidth <= MaxTextWidth + 0.001f || !LabelProps.m_EnableWidthCheck || Size == LabelProps.m_MinimumFontSize)
747 break;
748 Size--;
749 } while(true);
750
751 SCursorAndBoundingBox Res{};
752 Res.m_TextSize = vec2(TextWidth, TextHeight);
753 Res.m_BiggestCharacterHeight = TextBoundingHeight;
754 Res.m_LineCount = LineCount;
755 return Res;
756}
757
758static int GetFlagsForLabelProperties(const SLabelProperties &LabelProps, const CTextCursor *pReadCursor)
759{

Callers 1

DoLabelMethod · 0.85

Calls 2

maximumFunction · 0.85
TextWidthMethod · 0.80

Tested by

no test coverage detected