mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
Merge #3171
3171: Some chat fixes r=def- a=Jupeyy Very round: ![screenshot_2020-10-22_22-16-56](https://user-images.githubusercontent.com/6654924/96926091-6a4d0280-14b5-11eb-81bf-387019f29562.png) bit round: ![screenshot_2020-10-22_22-17-33](https://user-images.githubusercontent.com/6654924/96926098-6de08980-14b5-11eb-8086-6b1ffc48bc86.png) No rounding left: ![screenshot_2020-10-22_22-18-16](https://user-images.githubusercontent.com/6654924/96926111-72a53d80-14b5-11eb-93d3-cb3e4ff8b475.png) No rounding at all: ![screenshot_2020-10-22_22-18-54](https://user-images.githubusercontent.com/6654924/96926120-76d15b00-14b5-11eb-8ab8-1cb1dfc8c1a8.png) old chat: ![screenshot_2020-10-22_22-28-43](https://user-images.githubusercontent.com/6654924/96926568-04ad4600-14b6-11eb-92eb-ff3400edc499.png) Just gave some examples so its easier to see what is nice Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
commit
641d4db676
|
@ -272,6 +272,11 @@ class CTextRender : public IEngineTextRender
|
|||
m_RenderFlags = Flags;
|
||||
}
|
||||
|
||||
virtual unsigned int GetRenderFlags()
|
||||
{
|
||||
return m_RenderFlags;
|
||||
}
|
||||
|
||||
void Grow(unsigned char *pIn, unsigned char *pOut, int w, int h, int OutlineCount)
|
||||
{
|
||||
for(int y = 0; y < h; y++)
|
||||
|
@ -1057,6 +1062,9 @@ public:
|
|||
|
||||
++CharacterCounter;
|
||||
}
|
||||
|
||||
if(DrawX > pCursor->m_LongestLineWidth)
|
||||
pCursor->m_LongestLineWidth = DrawX;
|
||||
}
|
||||
|
||||
if(NewLine)
|
||||
|
@ -1168,16 +1176,10 @@ public:
|
|||
TextContainer.m_StringInfo.m_QuadNum = TextContainer.m_StringInfo.m_CharacterQuads.size();
|
||||
if(Graphics()->IsTextBufferingEnabled())
|
||||
{
|
||||
size_t DataSize = TextContainer.m_StringInfo.m_CharacterQuads.size() * sizeof(STextCharQuad);
|
||||
void *pUploadData = &TextContainer.m_StringInfo.m_CharacterQuads[0];
|
||||
|
||||
TextContainer.m_StringInfo.m_QuadBufferObjectIndex = Graphics()->CreateBufferObject(DataSize, pUploadData);
|
||||
|
||||
for(size_t i = 0; i < m_DefaultTextContainerInfo.m_Attributes.size(); ++i)
|
||||
m_DefaultTextContainerInfo.m_Attributes[i].m_VertBufferBindingIndex = TextContainer.m_StringInfo.m_QuadBufferObjectIndex;
|
||||
|
||||
TextContainer.m_StringInfo.m_QuadBufferContainerIndex = Graphics()->CreateBufferContainer(&m_DefaultTextContainerInfo);
|
||||
Graphics()->IndicesNumRequiredNotify(TextContainer.m_StringInfo.m_QuadNum * 6);
|
||||
if((TextContainer.m_RenderFlags & TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD) == 0)
|
||||
{
|
||||
UploadTextContainer(ContainerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
TextContainer.m_LineCount = pCursor->m_LineCount;
|
||||
|
@ -1447,7 +1449,7 @@ public:
|
|||
size_t DataSize = TextContainer.m_StringInfo.m_CharacterQuads.size() * sizeof(STextCharQuad);
|
||||
void *pUploadData = &TextContainer.m_StringInfo.m_CharacterQuads[0];
|
||||
|
||||
if(TextContainer.m_StringInfo.m_QuadBufferObjectIndex != -1)
|
||||
if(TextContainer.m_StringInfo.m_QuadBufferObjectIndex != -1 && (TextContainer.m_RenderFlags & TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD) == 0)
|
||||
{
|
||||
Graphics()->RecreateBufferObject(TextContainer.m_StringInfo.m_QuadBufferObjectIndex, DataSize, pUploadData);
|
||||
Graphics()->IndicesNumRequiredNotify(TextContainer.m_StringInfo.m_QuadNum * 6);
|
||||
|
@ -1709,6 +1711,20 @@ public:
|
|||
FreeTextContainer(TextContainerIndex);
|
||||
}
|
||||
|
||||
virtual void UploadTextContainer(int TextContainerIndex)
|
||||
{
|
||||
STextContainer &TextContainer = GetTextContainer(TextContainerIndex);
|
||||
size_t DataSize = TextContainer.m_StringInfo.m_CharacterQuads.size() * sizeof(STextCharQuad);
|
||||
void *pUploadData = &TextContainer.m_StringInfo.m_CharacterQuads[0];
|
||||
TextContainer.m_StringInfo.m_QuadBufferObjectIndex = Graphics()->CreateBufferObject(DataSize, pUploadData);
|
||||
|
||||
for(size_t i = 0; i < m_DefaultTextContainerInfo.m_Attributes.size(); ++i)
|
||||
m_DefaultTextContainerInfo.m_Attributes[i].m_VertBufferBindingIndex = TextContainer.m_StringInfo.m_QuadBufferObjectIndex;
|
||||
|
||||
TextContainer.m_StringInfo.m_QuadBufferContainerIndex = Graphics()->CreateBufferContainer(&m_DefaultTextContainerInfo);
|
||||
Graphics()->IndicesNumRequiredNotify(TextContainer.m_StringInfo.m_QuadNum * 6);
|
||||
}
|
||||
|
||||
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor)
|
||||
{
|
||||
STextContainer &TextContainer = GetTextContainer(TextContainerIndex);
|
||||
|
|
|
@ -25,6 +25,7 @@ enum ETextRenderFlags
|
|||
TEXT_RENDER_FLAG_NO_OVERSIZE = 1 << 5,
|
||||
TEXT_RENDER_FLAG_NO_FIRST_CHARACTER_X_BEARING = 1 << 6,
|
||||
TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE = 1 << 7,
|
||||
TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD = 1 << 8,
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -95,6 +96,7 @@ public:
|
|||
virtual void SetCurFont(CFont *pFont) = 0;
|
||||
|
||||
virtual void SetRenderFlags(unsigned int Flags) = 0;
|
||||
virtual unsigned int GetRenderFlags() = 0;
|
||||
|
||||
ColorRGBA DefaultTextColor() { return ColorRGBA(1, 1, 1, 1); }
|
||||
ColorRGBA DefaultTextOutlineColor() { return ColorRGBA(0, 0, 0, 0.3f); }
|
||||
|
@ -109,6 +111,8 @@ public:
|
|||
virtual void SetTextContainerSelection(int TextContainerIndex, const char *pText, int CursorPos, int SelectionStart, int SelectionEnd) = 0;
|
||||
virtual void DeleteTextContainer(int TextContainerIndex) = 0;
|
||||
|
||||
virtual void UploadTextContainer(int TextContainerIndex) = 0;
|
||||
|
||||
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor) = 0;
|
||||
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor, float X, float Y) = 0;
|
||||
|
||||
|
|
|
@ -972,21 +972,28 @@ void CChat::OnPrepareLines()
|
|||
TextRender()->SetCursor(&Cursor, TextBegin, 0.0f, FontSize, 0);
|
||||
Cursor.m_LineWidth = LineWidth;
|
||||
|
||||
Cursor.m_X += RealMsgPaddingTee;
|
||||
|
||||
if(m_aLines[r].m_Friend && g_Config.m_ClMessageFriend)
|
||||
if(m_aLines[r].m_ClientID >= 0 && m_aLines[r].m_aName[0] != '\0')
|
||||
{
|
||||
TextRender()->TextEx(&Cursor, "♥ ", -1);
|
||||
Cursor.m_X += RealMsgPaddingTee;
|
||||
|
||||
if(m_aLines[r].m_Friend && g_Config.m_ClMessageFriend)
|
||||
{
|
||||
TextRender()->TextEx(&Cursor, "♥ ", -1);
|
||||
}
|
||||
}
|
||||
|
||||
TextRender()->TextEx(&Cursor, aName, -1);
|
||||
if(m_aLines[r].m_TimesRepeated > 0)
|
||||
TextRender()->TextEx(&Cursor, aCount, -1);
|
||||
|
||||
TextRender()->TextEx(&Cursor, ": ", -1);
|
||||
if(m_aLines[r].m_ClientID >= 0 && m_aLines[r].m_aName[0] != '\0')
|
||||
{
|
||||
TextRender()->TextEx(&Cursor, ": ", -1);
|
||||
}
|
||||
|
||||
CTextCursor AppendCursor = Cursor;
|
||||
AppendCursor.m_StartX = Cursor.m_X;
|
||||
AppendCursor.m_LineWidth -= (Cursor.m_LongestLineWidth - Cursor.m_StartX);
|
||||
|
||||
TextRender()->TextEx(&AppendCursor, m_aLines[r].m_aText, -1);
|
||||
|
||||
|
@ -1002,6 +1009,9 @@ void CChat::OnPrepareLines()
|
|||
// the position the text was created
|
||||
m_aLines[r].m_TextYOffset = y + RealMsgPaddingY / 2.f;
|
||||
|
||||
int CurRenderFlags = TextRender()->GetRenderFlags();
|
||||
TextRender()->SetRenderFlags(CurRenderFlags | ETextRenderFlags::TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD);
|
||||
|
||||
// reset the cursor
|
||||
TextRender()->SetCursor(&Cursor, TextBegin, m_aLines[r].m_TextYOffset, FontSize, TEXTFLAG_RENDER);
|
||||
Cursor.m_LineWidth = LineWidth;
|
||||
|
@ -1091,6 +1101,7 @@ void CChat::OnPrepareLines()
|
|||
TextRender()->TextColor(Color);
|
||||
|
||||
CTextCursor AppendCursor = Cursor;
|
||||
AppendCursor.m_LineWidth -= (Cursor.m_LongestLineWidth - Cursor.m_StartX);
|
||||
AppendCursor.m_StartX = Cursor.m_X;
|
||||
|
||||
if(m_aLines[r].m_TextContainerIndex == -1)
|
||||
|
@ -1102,8 +1113,12 @@ void CChat::OnPrepareLines()
|
|||
{
|
||||
float Height = m_aLines[r].m_YOffset[OffsetType];
|
||||
Graphics()->SetColor(1, 1, 1, 1);
|
||||
m_aLines[r].m_QuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Begin, y, AppendCursor.m_LongestLineWidth - Begin + RealMsgPaddingX, Height, RealMsgPaddingY, CUI::CORNER_ALL);
|
||||
m_aLines[r].m_QuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Begin, y, (AppendCursor.m_LongestLineWidth - TextBegin) + RealMsgPaddingX * 1.5f, Height, MESSAGE_ROUNDING, CUI::CORNER_ALL);
|
||||
}
|
||||
|
||||
TextRender()->SetRenderFlags(CurRenderFlags);
|
||||
if(m_aLines[r].m_TextContainerIndex != -1)
|
||||
TextRender()->UploadTextContainer(m_aLines[r].m_TextContainerIndex);
|
||||
}
|
||||
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
@ -1262,7 +1277,7 @@ void CChat::OnRender()
|
|||
float RowHeight = FONT_SIZE + RealMsgPaddingY;
|
||||
float OffsetTeeY = MESSAGE_TEE_SIZE / 2.0f;
|
||||
float FullHeightMinusTee = RowHeight - MESSAGE_TEE_SIZE;
|
||||
float TWSkinUnreliableOffset = 0.5f; // teeworlds skins were always a bit in the ground
|
||||
float TWSkinUnreliableOffset = 1.0f; // teeworlds skins were always a bit in the ground
|
||||
|
||||
CAnimState *pIdleState = CAnimState::GetIdle();
|
||||
RenderTools()->RenderTee(pIdleState, &RenderInfo, EMOTE_NORMAL, vec2(1, 0.1f), vec2(x + (RealMsgPaddingX + MESSAGE_TEE_SIZE) / 2.0f, y + OffsetTeeY + FullHeightMinusTee / 2.0f + TWSkinUnreliableOffset), Blend);
|
||||
|
|
|
@ -12,11 +12,12 @@ class CChat : public CComponent
|
|||
CLineInput m_Input;
|
||||
|
||||
static constexpr float MESSAGE_PADDING_X = 5.0f;
|
||||
static constexpr float MESSAGE_TEE_SIZE = 8.0f;
|
||||
static constexpr float MESSAGE_TEE_SIZE = 7.0f;
|
||||
static constexpr float MESSAGE_TEE_PADDING_RIGHT = 0.5f;
|
||||
static constexpr float FONT_SIZE = 6.0f;
|
||||
static constexpr float MESSAGE_PADDING_Y = 3.f;
|
||||
static_assert(FONT_SIZE + MESSAGE_PADDING_Y >= 8.0f, "Corners for background chat are too huge for this combination of font size and message padding.");
|
||||
static constexpr float MESSAGE_PADDING_Y = 1.0f;
|
||||
static constexpr float MESSAGE_ROUNDING = 3.0f;
|
||||
static_assert(FONT_SIZE + MESSAGE_PADDING_Y >= MESSAGE_ROUNDING * 2.0f, "Corners for background chat are too huge for this combination of font size and message padding.");
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue