3022: Text alignment r=def- a=Jupeyy

i think the round borders create a bit of optical illusion, e.g. the "V" in edtior is only 1 pixel of, but looks like its completly left xd

i checked at few resolutions with gimp and only saw around 1 pixel margin of error, but go ahead and test yourself :D

Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2020-10-09 14:31:25 +00:00 committed by GitHub
commit cf6ace1744
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 118 additions and 77 deletions

View file

@ -765,6 +765,7 @@ public:
pCursor->m_Flags = Flags;
pCursor->m_GlyphCount = 0;
pCursor->m_CharCount = 0;
pCursor->m_MaxCharacterHeight = 0;
}
virtual void Text(void *pFontSetV, float x, float y, float Size, const char *pText, float LineWidth)
@ -772,17 +773,27 @@ public:
CTextCursor Cursor;
SetCursor(&Cursor, x, y, Size, TEXTFLAG_RENDER);
Cursor.m_LineWidth = LineWidth;
int OldRenderFlags = m_RenderFlags;
if(LineWidth <= 0)
SetRenderFlags(OldRenderFlags | ETextRenderFlags::TEXT_RENDER_FLAG_NO_FIRST_CHARACTER_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE);
TextEx(&Cursor, pText, -1);
SetRenderFlags(OldRenderFlags);
}
virtual float TextWidth(void *pFontSetV, float Size, const char *pText, int StrLength, float LineWidth, float *pAlignedHeight = NULL)
virtual float TextWidth(void *pFontSetV, float Size, const char *pText, int StrLength, float LineWidth, float *pAlignedHeight = NULL, float *pMaxCharacterHeightInLine = NULL)
{
CTextCursor Cursor;
SetCursor(&Cursor, 0, 0, Size, 0);
Cursor.m_LineWidth = LineWidth;
int OldRenderFlags = m_RenderFlags;
if(LineWidth <= 0)
SetRenderFlags(OldRenderFlags | ETextRenderFlags::TEXT_RENDER_FLAG_NO_FIRST_CHARACTER_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE);
TextEx(&Cursor, pText, StrLength);
SetRenderFlags(OldRenderFlags);
if(pAlignedHeight != NULL)
*pAlignedHeight = Cursor.m_AlignedFontSize;
if(pMaxCharacterHeightInLine != NULL)
*pMaxCharacterHeightInLine = Cursor.m_MaxCharacterHeight;
return Cursor.m_X;
}
@ -791,7 +802,11 @@ public:
CTextCursor Cursor;
SetCursor(&Cursor, 0, 0, Size, 0);
Cursor.m_LineWidth = LineWidth;
int OldRenderFlags = m_RenderFlags;
if(LineWidth <= 0)
SetRenderFlags(OldRenderFlags | ETextRenderFlags::TEXT_RENDER_FLAG_NO_FIRST_CHARACTER_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE);
TextEx(&Cursor, pText, -1);
SetRenderFlags(OldRenderFlags);
return Cursor.m_LineCount;
}
@ -997,6 +1012,21 @@ public:
float BearingX = (!ApplyBearingX ? 0.f : pChr->m_OffsetX) * Scale * Size;
float CharWidth = pChr->m_Width * Scale * Size;
float BearingY = 0.f;
BearingY = (((m_RenderFlags & TEXT_RENDER_FLAG_NO_Y_BEARING) != 0) ? 0.f : (pChr->m_OffsetY * Scale * Size));
float CharHeight = pChr->m_Height * Scale * Size;
if((m_RenderFlags & TEXT_RENDER_FLAG_NO_OVERSIZE) != 0)
{
if(CharHeight + BearingY > Size)
{
BearingY = 0;
float ScaleChar = (CharHeight + BearingY) / Size;
CharHeight = Size;
CharWidth /= ScaleChar;
}
}
if(pCursor->m_Flags & TEXTFLAG_RENDER && m_Color.a != 0.f)
{
if(Graphics()->IsTextBufferingEnabled())
@ -1005,19 +1035,12 @@ public:
Graphics()->QuadsSetSubset(pChr->m_aUVs[0] * UVScale, pChr->m_aUVs[3] * UVScale, pChr->m_aUVs[2] * UVScale, pChr->m_aUVs[1] * UVScale);
float Y = (DrawY + Size);
float BearingY = 0.f;
BearingY = (((m_RenderFlags & TEXT_RENDER_FLAG_NO_Y_BEARING) != 0) ? 0.f : (pChr->m_OffsetY * Scale * Size));
if((m_RenderFlags & TEXT_RENDER_FLAG_NO_OVERSIZE) != 0)
{
if(pChr->m_Height * Scale * Size + BearingY > Size)
BearingY -= pChr->m_Height * Scale * Size - Size;
}
IGraphics::CQuadItem QuadItem((DrawX + CharKerning) + BearingX, Y - BearingY, CharWidth, -pChr->m_Height * Scale * Size);
IGraphics::CQuadItem QuadItem((DrawX + CharKerning) + BearingX, Y - BearingY, CharWidth, -CharHeight);
Graphics()->QuadsDrawTL(&QuadItem, 1);
}
pCursor->m_MaxCharacterHeight = maximum(pCursor->m_MaxCharacterHeight, CharHeight + BearingY);
if(NextCharacter == 0 && (m_RenderFlags & TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE) != 0)
DrawX += BearingX + CharKerning + CharWidth;
else
@ -1079,6 +1102,10 @@ public:
if(!pFont)
return -1;
int OldRenderFlags = m_RenderFlags;
if(pCursor->m_LineWidth <= 0)
SetRenderFlags(OldRenderFlags | ETextRenderFlags::TEXT_RENDER_FLAG_NO_FIRST_CHARACTER_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE);
int ContainerIndex = GetFreeTextContainerIndex();
STextContainer &TextContainer = GetTextContainer(ContainerIndex);
TextContainer.m_pFont = pFont;
@ -1151,6 +1178,7 @@ public:
TextContainer.m_UnscaledFontSize = pCursor->m_FontSize;
}
SetRenderFlags(OldRenderFlags);
return ContainerIndex;
}
@ -1306,6 +1334,20 @@ public:
float BearingX = (!ApplyBearingX ? 0.f : pChr->m_OffsetX) * Scale * Size;
float CharWidth = pChr->m_Width * Scale * Size;
float BearingY = (((RenderFlags & TEXT_RENDER_FLAG_NO_Y_BEARING) != 0) ? 0.f : (pChr->m_OffsetY * Scale * Size));
float CharHeight = pChr->m_Height * Scale * Size;
if((RenderFlags & TEXT_RENDER_FLAG_NO_OVERSIZE) != 0)
{
if(CharHeight + BearingY > Size)
{
BearingY = 0;
float ScaleChar = (CharHeight + BearingY) / Size;
CharHeight = Size;
CharWidth /= ScaleChar;
}
}
// don't add text that isn't drawn, the color overwrite is used for that
if(m_Color.a != 0.f)
{
@ -1314,14 +1356,6 @@ public:
float Y = (DrawY + Size);
float BearingY = (((RenderFlags & TEXT_RENDER_FLAG_NO_Y_BEARING) != 0) ? 0.f : (pChr->m_OffsetY * Scale * Size));
if((RenderFlags & TEXT_RENDER_FLAG_NO_OVERSIZE) != 0)
{
if(pChr->m_Height * Scale * Size + BearingY > Size)
BearingY -= pChr->m_Height * Scale * Size - Size;
}
TextCharQuad.m_Vertices[0].m_X = (DrawX + CharKerning) + BearingX;
TextCharQuad.m_Vertices[0].m_Y = Y - BearingY;
TextCharQuad.m_Vertices[0].m_U = pChr->m_aUVs[0];
@ -1341,7 +1375,7 @@ public:
TextCharQuad.m_Vertices[1].m_Color.m_A = (unsigned char)(m_Color.a * 255.f);
TextCharQuad.m_Vertices[2].m_X = (DrawX + CharKerning) + BearingX + CharWidth;
TextCharQuad.m_Vertices[2].m_Y = Y - BearingY - pChr->m_Height * Scale * Size;
TextCharQuad.m_Vertices[2].m_Y = Y - BearingY - CharHeight;
TextCharQuad.m_Vertices[2].m_U = pChr->m_aUVs[2];
TextCharQuad.m_Vertices[2].m_V = pChr->m_aUVs[1];
TextCharQuad.m_Vertices[2].m_Color.m_R = (unsigned char)(m_Color.r * 255.f);
@ -1350,7 +1384,7 @@ public:
TextCharQuad.m_Vertices[2].m_Color.m_A = (unsigned char)(m_Color.a * 255.f);
TextCharQuad.m_Vertices[3].m_X = (DrawX + CharKerning) + BearingX;
TextCharQuad.m_Vertices[3].m_Y = Y - BearingY - pChr->m_Height * Scale * Size;
TextCharQuad.m_Vertices[3].m_Y = Y - BearingY - CharHeight;
TextCharQuad.m_Vertices[3].m_U = pChr->m_aUVs[0];
TextCharQuad.m_Vertices[3].m_V = pChr->m_aUVs[1];
TextCharQuad.m_Vertices[3].m_Color.m_R = (unsigned char)(m_Color.r * 255.f);
@ -1359,6 +1393,8 @@ public:
TextCharQuad.m_Vertices[3].m_Color.m_A = (unsigned char)(m_Color.a * 255.f);
}
pCursor->m_MaxCharacterHeight = maximum(pCursor->m_MaxCharacterHeight, CharHeight + BearingY);
if(NextCharacter == 0 && (RenderFlags & TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE) != 0)
DrawX += BearingX + CharKerning + CharWidth;
else

View file

@ -47,6 +47,7 @@ public:
float m_StartY;
float m_LineWidth;
float m_X, m_Y;
float m_MaxCharacterHeight;
CFont *m_pFont;
float m_FontSize;
@ -110,7 +111,7 @@ public:
virtual void TextColor(ColorRGBA rgb) = 0;
virtual void TextOutlineColor(float r, float g, float b, float a) = 0;
virtual void Text(void *pFontSetV, float x, float y, float Size, const char *pText, float LineWidth) = 0;
virtual float TextWidth(void *pFontSetV, float Size, const char *pText, int StrLength, float LineWidth, float *pAlignedHeight = NULL) = 0;
virtual float TextWidth(void *pFontSetV, float Size, const char *pText, int StrLength, float LineWidth, float *pAlignedHeight = NULL, float *pMaxCharacterHeightInLine = NULL) = 0;
virtual int TextLineCount(void *pFontSetV, float Size, const char *pText, float LineWidth) = 0;
virtual void OnWindowResize() = 0;

View file

@ -155,7 +155,7 @@ int CMenus::DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect,
return Active ? UI()->DoButtonLogic(pID, "", Checked, pRect) : 0;
}
int CMenus::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName, int Corners, float r, float FontFactor, vec4 ColorHot, vec4 Color)
int CMenus::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName, int Corners, float r, float FontFactor, vec4 ColorHot, vec4 Color, int AlignVertically)
{
CUIRect Text = *pRect;
@ -184,7 +184,7 @@ int CMenus::DoButton_Menu(const void *pID, const char *pText, int Checked, const
Text.HMargin(pRect->h >= 20.0f ? 2.0f : 1.0f, &Text);
Text.HMargin((Text.h * FontFactor) / 2.0f, &Text);
UI()->DoLabel(&Text, pText, Text.h * ms_FontmodHeight, 0);
UI()->DoLabel(&Text, pText, Text.h * ms_FontmodHeight, 0, -1, AlignVertically);
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
}
@ -196,7 +196,7 @@ void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked,
UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0);
}
int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, const ColorRGBA *pDefaultColor, const ColorRGBA *pActiveColor, const ColorRGBA *pHoverColor, float EdgeRounding)
int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, const ColorRGBA *pDefaultColor, const ColorRGBA *pActiveColor, const ColorRGBA *pHoverColor, float EdgeRounding, int AlignVertically)
{
if(Checked)
{
@ -224,7 +224,7 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co
}
CUIRect Temp;
pRect->HMargin(2.0f, &Temp);
UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0);
UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0, -1, AlignVertically);
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
}
@ -253,16 +253,16 @@ int CMenus::DoButton_CheckBox_Common(const void *pID, const char *pText, const c
c.Margin(2.0f, &c);
RenderTools()->DrawUIRect(&c, ColorRGBA(1, 1, 1, 0.25f * ButtonColorMul(pID)), CUI::CORNER_ALL, 3.0f);
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);
bool CheckAble = *pBoxText == 'X';
if(CheckAble)
{
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_OVERSIZE | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT);
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
UI()->DoLabel(&c, "\xEE\x97\x8D", c.h * ms_FontmodHeight, 0);
UI()->DoLabel(&c, "\xEE\x97\x8D", c.h * ms_FontmodHeight, 0, -1, 0);
TextRender()->SetCurFont(NULL);
}
else
UI()->DoLabel(&c, pBoxText, c.h * ms_FontmodHeight, 0);
UI()->DoLabel(&c, pBoxText, c.h * ms_FontmodHeight, 0, -1, 0);
TextRender()->SetRenderFlags(0);
UI()->DoLabel(&t, pText, c.h * ms_FontmodHeight, -1);
@ -532,8 +532,10 @@ int CMenus::DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect,
ReturnValue = true;
}
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);
RenderTools()->DrawUIRect(&ClearButton, ColorRGBA(1, 1, 1, 0.33f * ButtonColorMul(pClearID)), Corners & ~CUI::CORNER_L, 3.0f);
UI()->DoLabel(&ClearButton, "×", ClearButton.h * ms_FontmodHeight, 0);
UI()->DoLabel(&ClearButton, "×", ClearButton.h * ms_FontmodHeight, 0, -1, 0);
TextRender()->SetRenderFlags(0);
if(UI()->DoButtonLogic(pClearID, "×", 0, &ClearButton))
{
pStr[0] = 0;
@ -761,7 +763,7 @@ int CMenus::RenderMenubar(CUIRect r)
static int s_StartButton = 0;
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
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);
bool GotNewsOrUpdate = false;
@ -789,7 +791,7 @@ int CMenus::RenderMenubar(CUIRect r)
pHomeButtonColorHover = &HomeButtonColorAlertHover;
}
if(DoButton_MenuTab(&s_StartButton, pHomeScreenButtonLabel, false, &Button, CUI::CORNER_T, pHomeButtonColor, pHomeButtonColor, pHomeButtonColorHover))
if(DoButton_MenuTab(&s_StartButton, pHomeScreenButtonLabel, false, &Button, CUI::CORNER_T, pHomeButtonColor, pHomeButtonColor, pHomeButtonColorHover, 10.0f, 0))
{
m_ShowStart = true;
m_DoubleClickIndex = -1;
@ -922,12 +924,12 @@ int CMenus::RenderMenubar(CUIRect r)
}
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
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);
Box.VSplitRight(33.0f, &Box, &Button);
static int s_QuitButton = 0;
ColorRGBA QuitColor(1, 0, 0, 0.5f);
if(DoButton_MenuTab(&s_QuitButton, "\xEE\x97\x8D", 0, &Button, CUI::CORNER_T, NULL, NULL, &QuitColor))
if(DoButton_MenuTab(&s_QuitButton, "\xEE\x97\x8D", 0, &Button, CUI::CORNER_T, NULL, NULL, &QuitColor, 10.0f, 0))
{
if(m_pClient->Editor()->HasUnsavedData() || (Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0))
{
@ -943,13 +945,13 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitRight(33.0f, &Box, &Button);
static int s_SettingsButton = 0;
if(DoButton_MenuTab(&s_SettingsButton, "\xEE\xA2\xB8", m_ActivePage == PAGE_SETTINGS, &Button, CUI::CORNER_T))
if(DoButton_MenuTab(&s_SettingsButton, "\xEE\xA2\xB8", m_ActivePage == PAGE_SETTINGS, &Button, CUI::CORNER_T, NULL, NULL, NULL, 10.0f, 0))
NewPage = PAGE_SETTINGS;
Box.VSplitRight(10.0f, &Box, &Button);
Box.VSplitRight(33.0f, &Box, &Button);
static int s_EditorButton = 0;
if(DoButton_MenuTab(&s_EditorButton, "\xEE\x8F\x89", 0, &Button, CUI::CORNER_T))
if(DoButton_MenuTab(&s_EditorButton, "\xEE\x8F\x89", 0, &Button, CUI::CORNER_T, NULL, NULL, NULL, 10.0f, 0))
{
g_Config.m_ClEditor = 1;
}
@ -960,14 +962,14 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitRight(33.0f, &Box, &Button);
static int s_DemoButton = 0;
if(DoButton_MenuTab(&s_DemoButton, "\xEE\x80\xAC", m_ActivePage == PAGE_DEMOS, &Button, CUI::CORNER_T))
if(DoButton_MenuTab(&s_DemoButton, "\xEE\x80\xAC", m_ActivePage == PAGE_DEMOS, &Button, CUI::CORNER_T, NULL, NULL, NULL, 10.0f, 0))
NewPage = PAGE_DEMOS;
Box.VSplitRight(10.0f, &Box, &Button);
Box.VSplitRight(33.0f, &Box, &Button);
static int s_ServerButton = 0;
if(DoButton_MenuTab(&s_ServerButton, "\xEE\xA0\x8B", m_ActivePage == g_Config.m_UiPage, &Button, CUI::CORNER_T))
if(DoButton_MenuTab(&s_ServerButton, "\xEE\xA0\x8B", m_ActivePage == g_Config.m_UiPage, &Button, CUI::CORNER_T, NULL, NULL, NULL, 10.0f, 0))
NewPage = g_Config.m_UiPage;
}

View file

@ -53,8 +53,8 @@ class CMenus : public CComponent
int DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
int DoButton_Sprite(const void *pID, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners);
int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active);
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName = 0, int Corners = CUI::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f));
int DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, const ColorRGBA *pDefaultColor = NULL, const ColorRGBA *pActiveColor = NULL, const ColorRGBA *pHoverColor = NULL, float EdgeRounding = 10);
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName = 0, int Corners = CUI::CORNER_ALL, float r = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4 Color = vec4(1, 1, 1, 0.5f), int AlignVertically = 1);
int DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, const ColorRGBA *pDefaultColor = NULL, const ColorRGBA *pActiveColor = NULL, const ColorRGBA *pHoverColor = NULL, float EdgeRounding = 10, int AlignVertically = 1);
int DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect);
int DoButton_CheckBox(const void *pID, const char *pText, int Checked, const CUIRect *pRect);

View file

@ -532,8 +532,8 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
// render quick search
{
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
UI()->DoLabelScaled(&QuickSearch, pSearchLabel, 16.0f, -1);
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);
UI()->DoLabelScaled(&QuickSearch, pSearchLabel, 16.0f, -1, -1, 0);
SearchIconWidth = TextRender()->TextWidth(0, 16.0f, pSearchLabel, -1, -1.0f);
ExcludeIconWidth = TextRender()->TextWidth(0, 16.0f, pExcludeLabel, -1, -1.0f);
ExcludeSearchIconMax = maximum(SearchIconWidth, ExcludeIconWidth);
@ -559,8 +559,8 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
// render quick exclude
{
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
UI()->DoLabelScaled(&QuickExclude, pExcludeLabel, 16.0f, -1);
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);
UI()->DoLabelScaled(&QuickExclude, pExcludeLabel, 16.0f, -1, -1, 0);
TextRender()->SetRenderFlags(0);
TextRender()->SetCurFont(NULL);
QuickExclude.VSplitLeft(ExcludeSearchIconMax, 0, &QuickExclude);

View file

@ -650,8 +650,8 @@ void CMenus::RenderServerControl(CUIRect MainView)
QuickSearch.HSplitTop(5.0f, 0, &QuickSearch);
const char *pSearchLabel = "\xEE\xA2\xB6";
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
UI()->DoLabelScaled(&QuickSearch, pSearchLabel, 14.0f, -1);
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);
UI()->DoLabelScaled(&QuickSearch, pSearchLabel, 14.0f, -1, -1, 0);
float wSearch = TextRender()->TextWidth(0, 14.0f, pSearchLabel, -1, -1.0f);
TextRender()->SetRenderFlags(0);
TextRender()->SetCurFont(NULL);

View file

@ -658,8 +658,8 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
QuickSearch.HSplitTop(5.0f, 0, &QuickSearch);
const char *pSearchLabel = "\xEE\xA2\xB6";
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
UI()->DoLabelScaled(&QuickSearch, pSearchLabel, 14.0f, -1);
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);
UI()->DoLabelScaled(&QuickSearch, pSearchLabel, 14.0f, -1, -1, 0);
float wSearch = TextRender()->TextWidth(0, 14.0f, pSearchLabel, -1, -1.0f);
TextRender()->SetRenderFlags(0);
TextRender()->SetCurFont(NULL);
@ -702,8 +702,8 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
}
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
if(DoButton_Menu(&RefreshButton, "\xEE\x97\x95", 0, &RefreshButton))
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);
if(DoButton_Menu(&RefreshButton, "\xEE\x97\x95", 0, &RefreshButton, NULL, 15, 5, 0, vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4(1, 1, 1, 0.5f), 0))
{
m_pClient->m_pSkins->Refresh();
s_InitSkinlist = true;

View file

@ -497,8 +497,8 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
QuickSearch.HSplitTop(5.0f, 0, &QuickSearch);
const char *pSearchLabel = "\xEE\xA2\xB6";
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
UI()->DoLabelScaled(&QuickSearch, pSearchLabel, 14.0f, -1);
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);
UI()->DoLabelScaled(&QuickSearch, pSearchLabel, 14.0f, -1, -1, 0);
float wSearch = TextRender()->TextWidth(0, 14.0f, pSearchLabel, -1, -1.0f);
TextRender()->SetRenderFlags(0);
TextRender()->SetCurFont(NULL);
@ -540,8 +540,8 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
}
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
if(DoButton_Menu(&ReloadButton, "\xEE\x97\x95", 0, &ReloadButton))
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);
if(DoButton_Menu(&ReloadButton, "\xEE\x97\x95", 0, &ReloadButton, NULL, 15, 5, 0, vec4(1.0f, 1.0f, 1.0f, 0.75f), vec4(1, 1, 1, 0.5f), 0))
{
ClearCustomItems(s_CurCustomTab);
}

View file

@ -375,29 +375,31 @@ int CUI::DoButton(const void *id, const char *text, int checked, const CUIRect *
return ret;
}*/
void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, int Align, int MaxWidth)
void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, int Align, int MaxWidth, int AlignVertically)
{
float AlignedSize = 0;
float MaxCharacterHeightInLine = 0;
float tw = TextRender()->TextWidth(0, Size, pText, -1, MaxWidth, &AlignedSize, &MaxCharacterHeightInLine);
float AlignmentVert = r->y + (r->h - AlignedSize) / 2.f;
if(AlignVertically == 0)
{
AlignmentVert = r->y + (r->h - AlignedSize) / 2.f - (AlignedSize - MaxCharacterHeightInLine) / 2.f;
}
if(Align == 0)
{
float AlignedSize = 0;
float tw = TextRender()->TextWidth(0, Size, pText, -1, MaxWidth, &AlignedSize);
TextRender()->Text(0, r->x + (r->w - tw) / 2.f, r->y + (r->h - AlignedSize) / 2.f, Size, pText, MaxWidth);
TextRender()->Text(0, r->x + (r->w - tw) / 2.f, AlignmentVert, Size, pText, MaxWidth);
}
else if(Align < 0)
{
float AlignedSize = 0;
TextRender()->TextWidth(0, Size, pText, -1, MaxWidth, &AlignedSize);
TextRender()->Text(0, r->x, r->y + (r->h - AlignedSize) / 2.f, Size, pText, MaxWidth);
TextRender()->Text(0, r->x, AlignmentVert, Size, pText, MaxWidth);
}
else if(Align > 0)
{
float AlignedSize = 0;
float tw = TextRender()->TextWidth(0, Size, pText, -1, MaxWidth, &AlignedSize);
TextRender()->Text(0, r->x + r->w - tw, r->y + (r->h - AlignedSize) / 2.f, Size, pText, MaxWidth);
TextRender()->Text(0, r->x + r->w - tw, AlignmentVert, Size, pText, MaxWidth);
}
}
void CUI::DoLabelScaled(const CUIRect *r, const char *pText, float Size, int Align, int MaxWidth)
void CUI::DoLabelScaled(const CUIRect *r, const char *pText, float Size, int Align, int MaxWidth, int AlignVertically)
{
DoLabel(r, pText, Size * Scale(), Align, MaxWidth);
DoLabel(r, pText, Size * Scale(), Align, MaxWidth, AlignVertically);
}

View file

@ -177,8 +177,8 @@ public:
int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY);
// TODO: Refactor: Remove this?
void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1);
void DoLabelScaled(const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1);
void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1, int AlignVertically = 1);
void DoLabelScaled(const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1, int AlignVertically = 1);
};
#endif

View file

@ -602,11 +602,11 @@ int CEditor::DoButton_Editor_Common(const void *pID, const char *pText, int Chec
//return UI()->DoButton(id, text, checked, r, draw_func, 0);
}
int CEditor::DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip)
int CEditor::DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int AlignVert)
{
RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), CUI::CORNER_ALL, 3.0f);
CUIRect NewRect = *pRect;
UI()->DoLabel(&NewRect, pText, 10.f, 0, -1);
UI()->DoLabel(&NewRect, pText, 10.f, 0, -1, AlignVert);
Checked %= 2;
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
}
@ -664,11 +664,11 @@ int CEditor::DoButton_Tab(const void *pID, const char *pText, int Checked, const
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
}
int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize)
int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize, int AlignVert)
{
RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), Corners, 3.0f);
CUIRect NewRect = *pRect;
UI()->DoLabel(&NewRect, pText, FontSize, 0, -1);
UI()->DoLabel(&NewRect, pText, FontSize, 0, -1, AlignVert);
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
}
@ -3308,7 +3308,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View)
{
LayersBox.HSplitTop(12.0f, &Slot, &LayersBox);
Slot.VSplitLeft(12, &VisibleToggle, &Slot);
if(DoButton_Ex(&m_Map.m_lGroups[g]->m_Visible, m_Map.m_lGroups[g]->m_Visible ? "V" : "H", m_Map.m_lGroups[g]->m_Collapse ? 1 : 0, &VisibleToggle, 0, "Toggle group visibility", CUI::CORNER_L))
if(DoButton_Ex(&m_Map.m_lGroups[g]->m_Visible, m_Map.m_lGroups[g]->m_Visible ? "V" : "H", m_Map.m_lGroups[g]->m_Collapse ? 1 : 0, &VisibleToggle, 0, "Toggle group visibility", CUI::CORNER_L, 10.0f, 0))
m_Map.m_lGroups[g]->m_Visible = !m_Map.m_lGroups[g]->m_Visible;
str_format(aBuf, sizeof(aBuf), "#%d %s", g, m_Map.m_lGroups[g]->m_aName);
@ -3359,7 +3359,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View)
Slot.VSplitLeft(12.0f, 0, &Button);
Button.VSplitLeft(15, &VisibleToggle, &Button);
if(DoButton_Ex(&m_Map.m_lGroups[g]->m_lLayers[i]->m_Visible, m_Map.m_lGroups[g]->m_lLayers[i]->m_Visible ? "V" : "H", 0, &VisibleToggle, 0, "Toggle layer visibility", CUI::CORNER_L))
if(DoButton_Ex(&m_Map.m_lGroups[g]->m_lLayers[i]->m_Visible, m_Map.m_lGroups[g]->m_lLayers[i]->m_Visible ? "V" : "H", 0, &VisibleToggle, 0, "Toggle layer visibility", CUI::CORNER_L, 10.0f, 0))
m_Map.m_lGroups[g]->m_lLayers[i]->m_Visible = !m_Map.m_lGroups[g]->m_lLayers[i]->m_Visible;
if(m_Map.m_lGroups[g]->m_lLayers[i]->m_aName[0])
@ -5761,7 +5761,7 @@ void CEditor::RenderMenubar(CUIRect MenuBar)
UI()->DoLabel(&Info, aBuf, 10.0f, 1, -1);
static int s_CloseButton = 0;
if(DoButton_Editor(&s_CloseButton, "×", 0, &Close, 0, "Exits from the editor") || (m_Dialog == DIALOG_NONE && !UiPopupOpen() && !m_PopupEventActivated && Input()->KeyPress(KEY_ESCAPE)))
if(DoButton_Editor(&s_CloseButton, "×", 0, &Close, 0, "Exits from the editor", 0) || (m_Dialog == DIALOG_NONE && !UiPopupOpen() && !m_PopupEventActivated && Input()->KeyPress(KEY_ESCAPE)))
g_Config.m_ClEditor = 0;
}

View file

@ -952,11 +952,11 @@ public:
void PlaceBorderTiles();
int DoButton_Editor_Common(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int AlignVert = 1);
int DoButton_Env(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pToolTip, ColorRGBA Color);
int DoButton_Tab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize = 10.0f);
int DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize = 10.0f, int AlignVert = 1);
int DoButton_ButtonDec(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_ButtonInc(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);