mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Merge #3268
3268: Fix ScaleFontSize with too long strings r=Jupeyy a=def- Thanks to PopCorn181 for report ![screenshot_2020-11-08_00-03-19](https://user-images.githubusercontent.com/2335377/98453118-d1c1ae00-2155-11eb-97cf-cd5a455c00d3.png) <!-- What is the motivation for the changes of this pull request --> ## Checklist - [x] Tested the change ingame - [x] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [x] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [x] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
commit
848bbf543d
|
@ -897,7 +897,7 @@ public:
|
||||||
//the outlined texture is always the same size as the current
|
//the outlined texture is always the same size as the current
|
||||||
float UVScale = 1.0f / pFont->m_CurTextureDimensions[0];
|
float UVScale = 1.0f / pFont->m_CurTextureDimensions[0];
|
||||||
|
|
||||||
const char *pCurrent = (char *)pText;
|
const char *pCurrent = pText;
|
||||||
const char *pEnd = pCurrent + Length;
|
const char *pEnd = pCurrent + Length;
|
||||||
|
|
||||||
if((m_RenderFlags & TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT) != 0)
|
if((m_RenderFlags & TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT) != 0)
|
||||||
|
@ -941,7 +941,7 @@ public:
|
||||||
const char *pBatchEnd = pEnd;
|
const char *pBatchEnd = pEnd;
|
||||||
if(pCursor->m_LineWidth > 0 && !(pCursor->m_Flags & TEXTFLAG_STOP_AT_END))
|
if(pCursor->m_LineWidth > 0 && !(pCursor->m_Flags & TEXTFLAG_STOP_AT_END))
|
||||||
{
|
{
|
||||||
int Wlen = minimum(WordLength((char *)pCurrent), (int)(pEnd - pCurrent));
|
int Wlen = minimum(WordLength(pCurrent), (int)(pEnd - pCurrent));
|
||||||
CTextCursor Compare = *pCursor;
|
CTextCursor Compare = *pCursor;
|
||||||
Compare.m_X = DrawX;
|
Compare.m_X = DrawX;
|
||||||
Compare.m_Y = DrawY;
|
Compare.m_Y = DrawY;
|
||||||
|
|
|
@ -2962,9 +2962,9 @@ void CEditor::DoMapEditor(CUIRect View)
|
||||||
//UI()->ClipDisable();
|
//UI()->ClipDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
float CEditor::ScaleFontSize(char *aBuf, float FontSize, int Width)
|
float CEditor::ScaleFontSize(char *pText, int TextSize, float FontSize, int Width)
|
||||||
{
|
{
|
||||||
while(TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f) > Width)
|
while(TextRender()->TextWidth(0, FontSize, pText, -1, -1.0f) > Width)
|
||||||
{
|
{
|
||||||
if(FontSize > 6.0f)
|
if(FontSize > 6.0f)
|
||||||
{
|
{
|
||||||
|
@ -2972,8 +2972,8 @@ float CEditor::ScaleFontSize(char *aBuf, float FontSize, int Width)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
aBuf[str_length(aBuf) - 4] = '\0';
|
pText[str_length(pText) - 4] = '\0';
|
||||||
str_append(aBuf, "...", sizeof(aBuf));
|
str_append(pText, "...", TextSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FontSize;
|
return FontSize;
|
||||||
|
@ -3140,7 +3140,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
|
||||||
else
|
else
|
||||||
str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_lImages[pProps[i].m_Value]->m_aName);
|
str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_lImages[pProps[i].m_Value]->m_aName);
|
||||||
|
|
||||||
float FontSize = ScaleFontSize(aBuf, 10.0f, Shifter.w);
|
float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w);
|
||||||
if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, 0, CUI::CORNER_ALL, FontSize))
|
if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, 0, CUI::CORNER_ALL, FontSize))
|
||||||
PopupSelectImageInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY());
|
PopupSelectImageInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY());
|
||||||
|
|
||||||
|
@ -3194,7 +3194,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
|
||||||
else
|
else
|
||||||
str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_lSounds[pProps[i].m_Value]->m_aName);
|
str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_lSounds[pProps[i].m_Value]->m_aName);
|
||||||
|
|
||||||
float FontSize = ScaleFontSize(aBuf, 10.0f, Shifter.w);
|
float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w);
|
||||||
if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, 0, CUI::CORNER_ALL, FontSize))
|
if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, 0, CUI::CORNER_ALL, FontSize))
|
||||||
PopupSelectSoundInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY());
|
PopupSelectSoundInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY());
|
||||||
|
|
||||||
|
@ -3213,7 +3213,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
|
||||||
else
|
else
|
||||||
str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_lImages[pProps[i].m_Min]->m_AutoMapper.GetConfigName(pProps[i].m_Value));
|
str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_lImages[pProps[i].m_Min]->m_AutoMapper.GetConfigName(pProps[i].m_Value));
|
||||||
|
|
||||||
float FontSize = ScaleFontSize(aBuf, 10.0f, Shifter.w);
|
float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w);
|
||||||
if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, 0, CUI::CORNER_ALL, FontSize))
|
if(DoButton_Ex(&pIDs[i], aBuf, 0, &Shifter, 0, 0, CUI::CORNER_ALL, FontSize))
|
||||||
PopupSelectConfigAutoMapInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY());
|
PopupSelectConfigAutoMapInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY());
|
||||||
|
|
||||||
|
@ -3240,7 +3240,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
|
||||||
else
|
else
|
||||||
str_format(aBuf, sizeof(aBuf), "%d", CurValue);
|
str_format(aBuf, sizeof(aBuf), "%d", CurValue);
|
||||||
|
|
||||||
float FontSize = ScaleFontSize(aBuf, 10.0f, Shifter.w);
|
float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, Shifter.w);
|
||||||
RenderTools()->DrawUIRect(&Shifter, Color, 0, 5.0f);
|
RenderTools()->DrawUIRect(&Shifter, Color, 0, 5.0f);
|
||||||
UI()->DoLabel(&Shifter, aBuf, FontSize, 0, -1);
|
UI()->DoLabel(&Shifter, aBuf, FontSize, 0, -1);
|
||||||
|
|
||||||
|
@ -4785,7 +4785,7 @@ void CEditor::RenderStatusbar(CUIRect View)
|
||||||
else
|
else
|
||||||
str_copy(aBuf, m_pTooltip, sizeof(aBuf));
|
str_copy(aBuf, m_pTooltip, sizeof(aBuf));
|
||||||
|
|
||||||
float FontSize = ScaleFontSize(aBuf, 10.0f, View.w);
|
float FontSize = ScaleFontSize(aBuf, sizeof(aBuf), 10.0f, View.w);
|
||||||
UI()->DoLabel(&View, aBuf, FontSize, -1, View.w);
|
UI()->DoLabel(&View, aBuf, FontSize, -1, View.w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -799,7 +799,7 @@ public:
|
||||||
bool IsQuadSelected(int Index);
|
bool IsQuadSelected(int Index);
|
||||||
int FindSelectedQuadIndex(int Index);
|
int FindSelectedQuadIndex(int Index);
|
||||||
|
|
||||||
float ScaleFontSize(char *aBuf, float FontSize, int Width);
|
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 DoProperties(CUIRect *pToolbox, CProperty *pProps, int *pIDs, int *pNewVal, ColorRGBA Color = ColorRGBA(1, 1, 1, 0.5f));
|
||||||
|
|
||||||
int m_Mode;
|
int m_Mode;
|
||||||
|
|
Loading…
Reference in a new issue