Possible emoji rendering fix

This commit is contained in:
Michał 2017-05-24 19:37:51 +02:00 committed by def
parent 3c3c7abd3c
commit 58b0ae5fc7
4 changed files with 53 additions and 19 deletions

View file

@ -640,6 +640,8 @@ public:
Graphics()->SetColor(m_TextR, m_TextG, m_TextB, m_TextA);
}
pCursor->m_EmojiX = DrawX;
while(pCurrent < pEnd && (pCursor->m_MaxLines < 1 || LineCount <= pCursor->m_MaxLines))
{
int NewLine = 0;
@ -718,6 +720,8 @@ public:
Graphics()->QuadsDrawTL(&QuadItem, 1);
}
pCursor->m_EmojiX = DrawX + (pChr->m_OffsetX + pChr->m_Width) * Size;
DrawX += Advance*Size;
pCursor->m_CharCount++;
}

View file

@ -25,6 +25,7 @@ public:
float m_StartY;
float m_LineWidth;
float m_X, m_Y;
float m_EmojiX;
CFont *m_pFont;
float m_FontSize;

View file

@ -603,6 +603,29 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
}
m_aLines[m_CurrentLine].m_Emojis.sort_range();
int Offset = 0;
for(int i = 0; i < Length; )
{
CEmojis::CEmojiInfo info;
bool Found = false;
for(int j = 0; j < m_aLines[m_CurrentLine].m_Emojis.size(); j++)
{
if(m_aLines[m_CurrentLine].m_Emojis[j].index >= i) {
Found = true;
info = m_aLines[m_CurrentLine].m_Emojis[j];
break;
}
}
int End = Found ? info.index : str_length(m_aLines[m_CurrentLine].m_aText);
str_copy(m_aLines[m_CurrentLine].m_aTextNoEmojis + Offset, m_aLines[m_CurrentLine].m_aText + i, End - i + 1);
Offset += End - i;
i = End;
if (Found) i += info.length;
}
char aBuf[1024];
str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, Team >= 2?"whisper":(m_aLines[m_CurrentLine].m_Team?"teamchat":"chat"), aBuf, Highlighted);
@ -785,10 +808,18 @@ void CChat::OnRender()
{
TextRender()->SetCursor(&Cursor, Begin, 0.0f, FontSize, 0);
Cursor.m_LineWidth = LineWidth;
Cursor.m_X += Cursor.m_FontSize * m_aLines[r].m_Emojis.size();
Cursor.m_Y += ((int)Cursor.m_X/(int)LineWidth) * Cursor.m_FontSize;
Cursor.m_X = (int)Cursor.m_X % (int)LineWidth;
TextRender()->TextEx(&Cursor, "", -1);
TextRender()->TextEx(&Cursor, aName, -1);
TextRender()->TextEx(&Cursor, m_aLines[r].m_aText, -1);
m_aLines[r].m_YOffset[OffsetType] = Cursor.m_Y + Cursor.m_FontSize;
TextRender()->TextEx(&Cursor, m_aLines[r].m_aTextNoEmojis, -1);
m_aLines[r].m_YOffset[OffsetType] = Cursor.m_Y + Cursor.m_FontSize; // 0 + 6
//this stores float ↓ += (( 198.333 + 6 * 0 )/ 200 )* 6;
//m_aLines[r].m_YOffset[OffsetType] += (int)((Cursor.m_X + Cursor.m_FontSize * m_aLines[r].m_Emojis.size())/LineWidth) * Cursor.m_FontSize;
printf("offset:\n%f %f %d %f\n", Cursor.m_X, Cursor.m_Y, m_aLines[r].m_Emojis.size(), LineWidth);
printf("%f\n", m_aLines[r].m_YOffset[OffsetType]);/*+
((int)(Cursor.m_X + Cursor.m_FontSize * m_aLines[r].m_Emojis.size())/(int)LineWidth)*Cursor.m_FontSize*/;
}
y -= m_aLines[r].m_YOffset[OffsetType];
@ -869,6 +900,7 @@ void CChat::OnRender()
}
int Length = str_length(m_aLines[r].m_aText);
char aBuf[1024];
for (int i = 0; i < Length; )
{
@ -882,32 +914,28 @@ void CChat::OnRender()
break;
}
}
char *pStart = &m_aLines[r].m_aText[i];
if(!Found)
{
char *pStart = &m_aLines[r].m_aText[i];
char *pEnd = &m_aLines[r].m_aText[str_length(m_aLines[r].m_aText)];
char *pSubstr = (char *)mem_alloc(pEnd - pStart + 1, 1);
mem_zero(pSubstr, pEnd - pStart + 1);
str_copy(aBuf, pStart, Length - i + 1);
mem_copy(pSubstr, pStart, pEnd - pStart);
TextRender()->TextEx(&Cursor, pSubstr, -1);
mem_free(pSubstr);
TextRender()->TextEx(&Cursor, aBuf, -1);
i = str_length(m_aLines[r].m_aText);
//i = str_length(m_aLines[r].m_aText);
break;
}
else
{
char *pStart = &m_aLines[r].m_aText[i];
char *pEnd = &m_aLines[r].m_aText[info.index];
char *pSubstr = (char *)mem_alloc(pEnd - pStart + 1, 1);
mem_zero(pSubstr, pEnd - pStart + 1);
str_copy(aBuf, pStart, info.index - i + 1);
mem_copy(pSubstr, pStart, pEnd - pStart);
TextRender()->TextEx(&Cursor, pSubstr, -1);
mem_free(pSubstr);
TextRender()->TextEx(&Cursor, aBuf, -1);
m_pClient->m_pEmojis->Render(info.m_ID, (Cursor.m_EmojiX) + 3, Cursor.m_Y + Cursor.m_FontSize-1, Cursor.m_FontSize, Cursor.m_FontSize);
Cursor.m_X += Cursor.m_FontSize + (Cursor.m_EmojiX - Cursor.m_X);
m_pClient->m_pEmojis->Render(info.m_ID, Cursor.m_X + Cursor.m_FontSize * 2 / 3, Cursor.m_Y + Cursor.m_FontSize * 2 / 3, Cursor.m_FontSize, Cursor.m_FontSize);
Cursor.m_X += Cursor.m_FontSize;
if(Cursor.m_LineWidth < Cursor.m_X + Cursor.m_FontSize)
{
Cursor.m_X = 0;

View file

@ -26,6 +26,7 @@ class CChat : public CComponent
int m_NameColor;
char m_aName[64];
char m_aText[512];
char m_aTextNoEmojis[512];
bool m_Friend;
bool m_Highlighted;
sorted_array<CEmojis::CEmojiInfo> m_Emojis;