diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 4edbb8efe80..082693a7ddb 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -205,7 +205,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE); TextRender()->TextColor(TextColor); TextRender()->TextOutlineColor(TextOutlineColor); - UI()->DoLabelStreamed(UIRect, pRect, pText, FontSize, TextAlign, -1.0f); + UI()->DoLabelStreamed(UIRect, pRect, pText, FontSize, TextAlign); TextRender()->TextOutlineColor(TextRender()->DefaultTextOutlineColor()); TextRender()->TextColor(TextRender()->DefaultTextColor()); TextRender()->SetRenderFlags(0); @@ -250,6 +250,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) continue; } + const float FontSize = 12.0f; for(int c = 0; c < NumCols; c++) { CUIRect Button; @@ -285,19 +286,21 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) } else if(ID == COL_NAME) { - float FontSize = 12.0f; + SLabelProperties Props; + Props.m_MaxWidth = Button.w; + Props.m_StopAtEnd = true; + Props.m_EnableWidthCheck = false; bool Printed = false; - if(g_Config.m_BrFilterString[0] && (pItem->m_QuickSearchHit & IServerBrowser::QUICK_SERVERNAME)) - Printed = PrintHighlighted(pItem->m_aName, [this, pItem, FontSize, &Button](const char *pFilteredStr, const int FilterLen) { - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColName + 0), &Button, pItem->m_aName, FontSize, TEXTALIGN_ML, Button.w, true, (int)(pFilteredStr - pItem->m_aName)); + Printed = PrintHighlighted(pItem->m_aName, [this, pItem, FontSize, Props, &Button](const char *pFilteredStr, const int FilterLen) { + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColName + 0), &Button, pItem->m_aName, FontSize, TEXTALIGN_ML, Props, (int)(pFilteredStr - pItem->m_aName)); TextRender()->TextColor(0.4f, 0.4f, 1.0f, 1); - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColName + 1), &Button, pFilteredStr, FontSize, TEXTALIGN_ML, Button.w, true, FilterLen, &pItem->m_pUIElement->Rect(gs_OffsetColName + 0)->m_Cursor); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColName + 1), &Button, pFilteredStr, FontSize, TEXTALIGN_ML, Props, FilterLen, &pItem->m_pUIElement->Rect(gs_OffsetColName + 0)->m_Cursor); TextRender()->TextColor(1, 1, 1, 1); - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColName + 2), &Button, pFilteredStr + FilterLen, FontSize, TEXTALIGN_ML, Button.w, true, -1, &pItem->m_pUIElement->Rect(gs_OffsetColName + 1)->m_Cursor); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColName + 2), &Button, pFilteredStr + FilterLen, FontSize, TEXTALIGN_ML, Props, -1, &pItem->m_pUIElement->Rect(gs_OffsetColName + 1)->m_Cursor); }); if(!Printed) - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColName), &Button, pItem->m_aName, FontSize, TEXTALIGN_ML, Button.w, true); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColName), &Button, pItem->m_aName, FontSize, TEXTALIGN_ML, Props); } else if(ID == COL_MAP) { @@ -314,18 +317,21 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) } } - float FontSize = 12.0f; + SLabelProperties Props; + Props.m_MaxWidth = Button.w; + Props.m_StopAtEnd = true; + Props.m_EnableWidthCheck = false; bool Printed = false; if(g_Config.m_BrFilterString[0] && (pItem->m_QuickSearchHit & IServerBrowser::QUICK_MAPNAME)) - Printed = PrintHighlighted(pItem->m_aMap, [this, pItem, FontSize, &Button](const char *pFilteredStr, const int FilterLen) { - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColMap + 0), &Button, pItem->m_aMap, FontSize, TEXTALIGN_ML, Button.w, true, (int)(pFilteredStr - pItem->m_aMap)); + Printed = PrintHighlighted(pItem->m_aMap, [this, pItem, FontSize, Props, &Button](const char *pFilteredStr, const int FilterLen) { + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColMap + 0), &Button, pItem->m_aMap, FontSize, TEXTALIGN_ML, Props, (int)(pFilteredStr - pItem->m_aMap)); TextRender()->TextColor(0.4f, 0.4f, 1.0f, 1); - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColMap + 1), &Button, pFilteredStr, FontSize, TEXTALIGN_ML, Button.w, true, FilterLen, &pItem->m_pUIElement->Rect(gs_OffsetColMap + 0)->m_Cursor); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColMap + 1), &Button, pFilteredStr, FontSize, TEXTALIGN_ML, Props, FilterLen, &pItem->m_pUIElement->Rect(gs_OffsetColMap + 0)->m_Cursor); TextRender()->TextColor(1, 1, 1, 1); - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColMap + 2), &Button, pFilteredStr + FilterLen, FontSize, TEXTALIGN_ML, Button.w, true, -1, &pItem->m_pUIElement->Rect(gs_OffsetColMap + 1)->m_Cursor); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColMap + 2), &Button, pFilteredStr + FilterLen, FontSize, TEXTALIGN_ML, Props, -1, &pItem->m_pUIElement->Rect(gs_OffsetColMap + 1)->m_Cursor); }); if(!Printed) - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColMap), &Button, pItem->m_aMap, FontSize, TEXTALIGN_ML, Button.w, true); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColMap), &Button, pItem->m_aMap, FontSize, TEXTALIGN_ML, Props); } else if(ID == COL_PLAYERS) { @@ -350,8 +356,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) str_format(aTemp, sizeof(aTemp), "%i/%i", pItem->m_NumFilteredPlayers, ServerBrowser()->Max(*pItem)); if(g_Config.m_BrFilterString[0] && (pItem->m_QuickSearchHit & IServerBrowser::QUICK_PLAYER)) TextRender()->TextColor(0.4f, 0.4f, 1.0f, 1); - float FontSize = 12.0f; - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColPlayers), &Button, aTemp, FontSize, TEXTALIGN_MR, -1.0f, false); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColPlayers), &Button, aTemp, FontSize, TEXTALIGN_MR); TextRender()->TextColor(1, 1, 1, 1); } else if(ID == COL_PING) @@ -364,20 +369,20 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) TextRender()->TextColor(rgb); } - float FontSize = 12.0f; - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColPing), &Button, aTemp, FontSize, TEXTALIGN_MR, -1.0f, false); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColPing), &Button, aTemp, FontSize, TEXTALIGN_MR); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); } else if(ID == COL_VERSION) { const char *pVersion = pItem->m_aVersion; - float FontSize = 12.0f; - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColVersion), &Button, pVersion, FontSize, TEXTALIGN_MR, -1.0f, false); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColVersion), &Button, pVersion, FontSize, TEXTALIGN_MR); } else if(ID == COL_GAMETYPE) { - float FontSize = 12.0f; - + SLabelProperties Props; + Props.m_MaxWidth = Button.w; + Props.m_StopAtEnd = true; + Props.m_EnableWidthCheck = false; if(g_Config.m_UiColorizeGametype) { ColorHSLA hsl = ColorHSLA(1.0f, 1.0f, 1.0f); @@ -405,11 +410,11 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) ColorRGBA rgb = color_cast(hsl); TextRender()->TextColor(rgb); - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColGameType), &Button, pItem->m_aGameType, FontSize, TEXTALIGN_ML, Button.w, true); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColGameType), &Button, pItem->m_aGameType, FontSize, TEXTALIGN_ML, Props); TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); } else - UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColGameType), &Button, pItem->m_aGameType, FontSize, TEXTALIGN_ML, Button.w, true); + UI()->DoLabelStreamed(*pItem->m_pUIElement->Rect(gs_OffsetColGameType), &Button, pItem->m_aGameType, FontSize, TEXTALIGN_ML, Props); } } } diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 23cb4a01d06..70a26100696 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -580,24 +580,33 @@ struct SCursorAndBoundingBox static SCursorAndBoundingBox CalcFontSizeCursorHeightAndBoundingBox(ITextRender *pTextRender, const char *pText, int Flags, float &Size, float MaxWidth, const SLabelProperties &LabelProps) { + const float MinFontSize = 5.0f; + const float MaxTextWidth = LabelProps.m_MaxWidth != -1.0f ? LabelProps.m_MaxWidth : MaxWidth; + const int FlagsWithoutStop = Flags & ~(TEXTFLAG_STOP_AT_END | TEXTFLAG_ELLIPSIS_AT_END); + const float MaxTextWidthWithoutStop = Flags == FlagsWithoutStop ? LabelProps.m_MaxWidth : -1.0f; + float TextBoundingHeight = 0.0f; float TextHeight = 0.0f; int LineCount = 0; - float MaxTextWidth = LabelProps.m_MaxWidth != -1 ? LabelProps.m_MaxWidth : MaxWidth; STextSizeProperties TextSizeProps{}; TextSizeProps.m_pHeight = &TextHeight; TextSizeProps.m_pMaxCharacterHeightInLine = &TextBoundingHeight; TextSizeProps.m_pLineCount = &LineCount; - float TextWidth = pTextRender->TextWidth(Size, pText, -1, LabelProps.m_MaxWidth, Flags, TextSizeProps); - while(TextWidth > MaxTextWidth + 0.001f) + + float TextWidth; + do { - if(!LabelProps.m_EnableWidthCheck) - break; - if(Size < 4.0f) + Size = maximum(Size, MinFontSize); + // Only consider stop-at-end and ellipsis-at-end when minimum font size reached or font scaling disabled + if((Size == MinFontSize || !LabelProps.m_EnableWidthCheck) && Flags != FlagsWithoutStop) + TextWidth = pTextRender->TextWidth(Size, pText, -1, LabelProps.m_MaxWidth, Flags, TextSizeProps); + else + TextWidth = pTextRender->TextWidth(Size, pText, -1, MaxTextWidthWithoutStop, FlagsWithoutStop, TextSizeProps); + if(TextWidth <= MaxTextWidth + 0.001f || !LabelProps.m_EnableWidthCheck || Size == MinFontSize) break; - Size -= 1.0f; - TextWidth = pTextRender->TextWidth(Size, pText, -1, LabelProps.m_MaxWidth, Flags, TextSizeProps); - } + Size--; + } while(true); + SCursorAndBoundingBox Res{}; Res.m_TextSize = vec2(TextWidth, TextHeight); Res.m_BiggestCharacterHeight = TextBoundingHeight; @@ -605,6 +614,17 @@ static SCursorAndBoundingBox CalcFontSizeCursorHeightAndBoundingBox(ITextRender return Res; } +static int GetFlagsForLabelProperties(const SLabelProperties &LabelProps, const CTextCursor *pReadCursor) +{ + if(pReadCursor != nullptr) + return pReadCursor->m_Flags & ~TEXTFLAG_RENDER; + + int Flags = 0; + Flags |= LabelProps.m_StopAtEnd ? TEXTFLAG_STOP_AT_END : 0; + Flags |= LabelProps.m_EllipsisAtEnd ? TEXTFLAG_ELLIPSIS_AT_END : 0; + return Flags; +} + vec2 CUI::CalcAlignedCursorPos(const CUIRect *pRect, vec2 TextSize, int Align, const float *pBiggestCharHeight) { vec2 Cursor(pRect->x, pRect->y); @@ -634,7 +654,7 @@ vec2 CUI::CalcAlignedCursorPos(const CUIRect *pRect, vec2 TextSize, int Align, c void CUI::DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps) { - const int Flags = LabelProps.m_StopAtEnd ? TEXTFLAG_STOP_AT_END : 0; + const int Flags = GetFlagsForLabelProperties(LabelProps, nullptr); const SCursorAndBoundingBox TextBounds = CalcFontSizeCursorHeightAndBoundingBox(TextRender(), pText, Flags, Size, pRect->w, LabelProps); const vec2 CursorPos = CalcAlignedCursorPos(pRect, TextBounds.m_TextSize, Align, TextBounds.m_LineCount == 1 ? &TextBounds.m_BiggestCharacterHeight : nullptr); @@ -646,7 +666,7 @@ void CUI::DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps, int StrLen, const CTextCursor *pReadCursor) { - const int Flags = pReadCursor ? (pReadCursor->m_Flags & ~TEXTFLAG_RENDER) : LabelProps.m_StopAtEnd ? TEXTFLAG_STOP_AT_END : 0; + const int Flags = GetFlagsForLabelProperties(LabelProps, pReadCursor); const SCursorAndBoundingBox TextBounds = CalcFontSizeCursorHeightAndBoundingBox(TextRender(), pText, Flags, Size, pRect->w, LabelProps); CTextCursor Cursor; @@ -671,7 +691,7 @@ void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, cons RectEl.m_Cursor = Cursor; } -void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth, bool StopAtEnd, int StrLen, const CTextCursor *pReadCursor) +void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps, int StrLen, const CTextCursor *pReadCursor) { bool NeedsRecreate = false; bool ColorChanged = RectEl.m_TextColor != TextRender()->GetTextColor() || RectEl.m_TextOutlineColor != TextRender()->GetTextOutlineColor(); @@ -714,10 +734,7 @@ void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRe TmpRect.w = pRect->w; TmpRect.h = pRect->h; - SLabelProperties Props; - Props.m_MaxWidth = MaxWidth; - Props.m_StopAtEnd = StopAtEnd; - DoLabel(RectEl, &TmpRect, pText, Size, TEXTALIGN_TL, Props, StrLen, pReadCursor); + DoLabel(RectEl, &TmpRect, pText, Size, TEXTALIGN_TL, LabelProps, StrLen, pReadCursor); } ColorRGBA ColorText(RectEl.m_TextColor); diff --git a/src/game/client/ui.h b/src/game/client/ui.h index bf20f900ca5..dbd498b6bb7 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -193,6 +193,7 @@ struct SLabelProperties { float m_MaxWidth = -1; bool m_StopAtEnd = false; + bool m_EllipsisAtEnd = false; bool m_EnableWidthCheck = true; }; @@ -488,7 +489,7 @@ class CUI void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {}); void DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {}, int StrLen = -1, const CTextCursor *pReadCursor = nullptr); - void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, float MaxWidth = -1, bool StopAtEnd = false, int StrLen = -1, const CTextCursor *pReadCursor = nullptr); + void DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps = {}, int StrLen = -1, const CTextCursor *pReadCursor = nullptr); bool DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners = IGraphics::CORNER_ALL); bool DoClearableEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners = IGraphics::CORNER_ALL); diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index d6bb80c8f4e..c7590a948de 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -449,7 +449,12 @@ int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked, CUIRect Rect; pRect->VMargin(5.0f, &Rect); - UI()->DoLabel(&Rect, pText, 10.0f, TEXTALIGN_ML); + + SLabelProperties Props; + Props.m_MaxWidth = Rect.w; + Props.m_EllipsisAtEnd = true; + UI()->DoLabel(&Rect, pText, 10.0f, TEXTALIGN_ML, Props); + return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } @@ -463,7 +468,15 @@ int CEditor::DoButton_Tab(const void *pID, const char *pText, int Checked, const int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize) { pRect->Draw(GetButtonColor(pID, Checked), Corners, 3.0f); - UI()->DoLabel(pRect, pText, FontSize, TEXTALIGN_MC); + + CUIRect Rect; + pRect->VMargin(pRect->w > 20.0f ? 5.0f : 0.0f, &Rect); + + SLabelProperties Props; + Props.m_MaxWidth = Rect.w; + Props.m_EllipsisAtEnd = true; + UI()->DoLabel(&Rect, pText, FontSize, TEXTALIGN_MC, Props); + return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } @@ -498,7 +511,13 @@ int CEditor::DoButton_DraggableEx(const void *pID, const char *pText, int Checke { pRect->Draw(GetButtonColor(pID, Checked), Corners, 3.0f); - UI()->DoLabel(pRect, pText, FontSize, TEXTALIGN_MC); + CUIRect Rect; + pRect->VMargin(pRect->w > 20.0f ? 5.0f : 0.0f, &Rect); + + SLabelProperties Props; + Props.m_MaxWidth = Rect.w; + Props.m_EllipsisAtEnd = true; + UI()->DoLabel(&Rect, pText, FontSize, TEXTALIGN_MC, Props); if(UI()->MouseInside(pRect)) { @@ -3077,23 +3096,6 @@ void CEditor::DoMapEditor(CUIRect View) UI()->MapScreen(); } -float CEditor::ScaleFontSize(char *pText, int TextSize, float FontSize, int Width) -{ - while(TextRender()->TextWidth(FontSize, pText, -1, -1.0f) > Width) - { - if(FontSize > 6.0f) - { - FontSize--; - } - else - { - pText[str_length(pText) - 4] = '\0'; - str_append(pText, "…", TextSize); - } - } - return FontSize; -} - int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *pNewVal, ColorRGBA Color) { int Change = -1; @@ -3239,14 +3241,13 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * } else if(pProps[i].m_Type == PROPTYPE_IMAGE) { - char aBuf[64]; + const char *pName; if(pProps[i].m_Value < 0) - str_copy(aBuf, "None"); + pName = "None"; else - str_copy(aBuf, m_Map.m_vpImages[pProps[i].m_Value]->m_aName); + pName = m_Map.m_vpImages[pProps[i].m_Value]->m_aName; - float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w); - if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL, FontSize)) + if(DoButton_Ex(&pIDs[i], pName, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL)) PopupSelectImageInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY()); int r = PopupSelectImageResult(); @@ -3291,14 +3292,13 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * } else if(pProps[i].m_Type == PROPTYPE_SOUND) { - char aBuf[64]; + const char *pName; if(pProps[i].m_Value < 0) - str_copy(aBuf, "None"); + pName = "None"; else - str_copy(aBuf, m_Map.m_vpSounds[pProps[i].m_Value]->m_aName); + pName = m_Map.m_vpSounds[pProps[i].m_Value]->m_aName; - float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w); - if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL, FontSize)) + if(DoButton_Ex(&pIDs[i], pName, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL)) PopupSelectSoundInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY()); int r = PopupSelectSoundResult(); @@ -3310,14 +3310,13 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * } else if(pProps[i].m_Type == PROPTYPE_AUTOMAPPER) { - char aBuf[64]; + const char *pName; if(pProps[i].m_Value < 0 || pProps[i].m_Min < 0 || pProps[i].m_Min >= (int)m_Map.m_vpImages.size()) - str_copy(aBuf, "None"); + pName = "None"; else - str_copy(aBuf, m_Map.m_vpImages[pProps[i].m_Min]->m_AutoMapper.GetConfigName(pProps[i].m_Value)); + pName = m_Map.m_vpImages[pProps[i].m_Min]->m_AutoMapper.GetConfigName(pProps[i].m_Value); - float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w); - if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL, FontSize)) + if(DoButton_Ex(&pIDs[i], pName, 0, &Shifter, 0, nullptr, IGraphics::CORNER_ALL)) PopupSelectConfigAutoMapInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY()); int r = PopupSelectConfigAutoMapResult(); @@ -3502,14 +3501,11 @@ void CEditor::RenderLayers(CUIRect LayersBox) m_Map.m_vpGroups[g]->m_Visible = !m_Map.m_vpGroups[g]->m_Visible; str_format(aBuf, sizeof(aBuf), "#%d %s", g, m_Map.m_vpGroups[g]->m_aName); - float FontSize = 10.0f; - while(TextRender()->TextWidth(FontSize, aBuf, -1, -1.0f) > Slot.w && FontSize >= 7.0f) - FontSize--; bool Clicked; bool Abrupted; if(int Result = DoButton_DraggableEx(&m_Map.m_vpGroups[g], aBuf, g == m_SelectedGroup, &Slot, &Clicked, &Abrupted, - BUTTON_CONTEXT, m_Map.m_vpGroups[g]->m_Collapse ? "Select group. Shift click to select all layers. Double click to expand." : "Select group. Shift click to select all layers. Double click to collapse.", IGraphics::CORNER_R, FontSize)) + BUTTON_CONTEXT, m_Map.m_vpGroups[g]->m_Collapse ? "Select group. Shift click to select all layers. Double click to expand." : "Select group. Shift click to select all layers. Double click to collapse.", IGraphics::CORNER_R)) { if(s_Operation == OP_NONE) { @@ -3648,14 +3644,8 @@ void CEditor::RenderLayers(CUIRect LayersBox) CLayerSounds *pSounds = (CLayerSounds *)m_Map.m_vpGroups[g]->m_vpLayers[i]; str_copy(aBuf, pSounds->m_Sound >= 0 ? m_Map.m_vpSounds[pSounds->m_Sound]->m_aName : "Sounds"); } - if(str_length(aBuf) > 11) - str_format(aBuf, sizeof(aBuf), "%.8s…", aBuf); } - float FontSize = 10.0f; - while(TextRender()->TextWidth(FontSize, aBuf, -1, -1.0f) > Button.w && FontSize >= 7.0f) - FontSize--; - int Checked = IsLayerSelected ? 1 : 0; if(m_Map.m_vpGroups[g]->m_vpLayers[i]->IsEntitiesLayer()) { @@ -3665,7 +3655,7 @@ void CEditor::RenderLayers(CUIRect LayersBox) bool Clicked; bool Abrupted; if(int Result = DoButton_DraggableEx(m_Map.m_vpGroups[g]->m_vpLayers[i], aBuf, Checked, &Button, &Clicked, &Abrupted, - BUTTON_CONTEXT, "Select layer. Shift click to select multiple.", IGraphics::CORNER_R, FontSize)) + BUTTON_CONTEXT, "Select layer. Shift click to select multiple.", IGraphics::CORNER_R)) { if(s_Operation == OP_NONE) { @@ -4394,12 +4384,8 @@ void CEditor::RenderImagesList(CUIRect ToolBox) } } - float FontSize = 10.0f; - while(TextRender()->TextWidth(FontSize, m_Map.m_vpImages[i]->m_aName, -1, -1.0f) > Slot.w) - FontSize--; - if(int Result = DoButton_Ex(&m_Map.m_vpImages[i], m_Map.m_vpImages[i]->m_aName, Selected, &Slot, - BUTTON_CONTEXT, "Select image.", IGraphics::CORNER_ALL, FontSize)) + BUTTON_CONTEXT, "Select image.", IGraphics::CORNER_ALL)) { m_SelectedImage = i; @@ -4514,12 +4500,8 @@ void CEditor::RenderSounds(CUIRect ToolBox) if(!SoundUsed) Selected += 2; // Sound is unused - float FontSize = 10.0f; - while(TextRender()->TextWidth(FontSize, m_Map.m_vpSounds[i]->m_aName, -1, -1.0f) > Slot.w) - FontSize--; - if(int Result = DoButton_Ex(&m_Map.m_vpSounds[i], m_Map.m_vpSounds[i]->m_aName, Selected, &Slot, - BUTTON_CONTEXT, "Select sound.", IGraphics::CORNER_ALL, FontSize)) + BUTTON_CONTEXT, "Select sound.", IGraphics::CORNER_ALL)) { m_SelectedSound = i; @@ -4894,6 +4876,7 @@ void CEditor::RenderFileDialog() Item.m_Rect.VSplitLeft(Item.m_Rect.h, &FileIcon, &Button); Button.VSplitLeft(5.0f, nullptr, &Button); Button.VSplitRight(100.0f, &Button, &TimeModified); + Button.VSplitRight(5.0f, &Button, nullptr); const char *pIconType; if(!m_vpFilteredFileList[i]->m_IsDir) @@ -4925,7 +4908,10 @@ void CEditor::RenderFileDialog() UI()->DoLabel(&FileIcon, pIconType, 12.0f, TEXTALIGN_ML); TextRender()->SetCurFont(nullptr); - UI()->DoLabel(&Button, m_vpFilteredFileList[i]->m_aName, 10.0f, TEXTALIGN_ML); + SLabelProperties Props; + Props.m_MaxWidth = Button.w; + Props.m_EllipsisAtEnd = true; + UI()->DoLabel(&Button, m_vpFilteredFileList[i]->m_aName, 10.0f, TEXTALIGN_ML, Props); if(!m_vpFilteredFileList[i]->m_IsLink && str_comp(m_vpFilteredFileList[i]->m_aFilename, "..") != 0) { @@ -5236,8 +5222,8 @@ void CEditor::RenderStatusbar(CUIRect View) m_ShowServerSettingsEditor = false; } - View.VSplitRight(100.0f, &View, &Button); - Button.VSplitRight(10.0f, &Button, nullptr); + View.VSplitRight(10.0f, &View, nullptr); + View.VSplitRight(90.0f, &View, &Button); static int s_SettingsButton = 0; if(DoButton_Editor(&s_SettingsButton, "Server settings", m_ShowServerSettingsEditor, &Button, 0, "Toggles the server settings editor.")) { @@ -5253,10 +5239,11 @@ void CEditor::RenderStatusbar(CUIRect View) else str_copy(aBuf, m_pTooltip); - float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, View.w); + View.VSplitRight(10.0f, &View, nullptr); SLabelProperties Props; Props.m_MaxWidth = View.w; - UI()->DoLabel(&View, aBuf, FontSize, TEXTALIGN_ML, Props); + Props.m_EllipsisAtEnd = true; + UI()->DoLabel(&View, aBuf, 10.0f, TEXTALIGN_ML, Props); } } @@ -6093,6 +6080,7 @@ void CEditor::RenderMenubar(CUIRect MenuBar) MenuBar.VSplitRight(20.0f, &MenuBar, &Close); Close.VSplitLeft(5.0f, nullptr, &Close); MenuBar.VSplitLeft(MenuBar.w * 0.6f, &MenuBar, &Info); + MenuBar.VSplitRight(5.0f, &MenuBar, nullptr); if(m_Map.m_Modified) { @@ -6107,7 +6095,10 @@ void CEditor::RenderMenubar(CUIRect MenuBar) char aBuf[IO_MAX_PATH_LENGTH + 32]; str_format(aBuf, sizeof(aBuf), "File: %s", m_aFileName); - UI()->DoLabel(&MenuBar, aBuf, 10.0f, TEXTALIGN_ML); + SLabelProperties Props; + Props.m_MaxWidth = MenuBar.w; + Props.m_EllipsisAtEnd = true; + UI()->DoLabel(&MenuBar, aBuf, 10.0f, TEXTALIGN_ML, Props); char aTimeStr[6]; str_timestamp_format(aTimeStr, sizeof(aTimeStr), "%H:%M"); diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 4074b1f710d..06e21ba80a2 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -915,7 +915,6 @@ class CEditor : public IEditor bool IsQuadSelected(int Index) const; int FindSelectedQuadIndex(int Index) const; - float ScaleFontSize(char *pText, int TextSize, float FontSize, int Width); int DoProperties(CUIRect *pToolbox, CProperty *pProps, int *pIDs, int *pNewVal, ColorRGBA Color = ColorRGBA(1, 1, 1, 0.5f)); int m_Mode;