mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
fixed that chat message gets out of the window. Closes #102
This commit is contained in:
parent
de7504282c
commit
411db8b885
|
@ -541,6 +541,7 @@ public:
|
|||
int i;
|
||||
int GotNewLine = 0;
|
||||
float DrawX, DrawY;
|
||||
int LineCount;
|
||||
float CursorX, CursorY;
|
||||
const char *pEnd;
|
||||
|
||||
|
@ -590,6 +591,7 @@ public:
|
|||
const char *pEnd = pCurrent+Length;
|
||||
DrawX = CursorX;
|
||||
DrawY = CursorY;
|
||||
LineCount = pCursor->m_LineCount;
|
||||
|
||||
if(pCursor->m_Flags&TEXTFLAG_RENDER)
|
||||
{
|
||||
|
@ -607,7 +609,7 @@ public:
|
|||
Graphics()->SetColor(m_TextR, m_TextG, m_TextB, m_TextA);
|
||||
}
|
||||
|
||||
while(pCurrent < pEnd)
|
||||
while(pCurrent < pEnd && (pCursor->m_MaxLines < 1 || LineCount <= pCursor->m_MaxLines))
|
||||
{
|
||||
int NewLine = 0;
|
||||
const char *pBatchEnd = pEnd;
|
||||
|
@ -666,7 +668,9 @@ public:
|
|||
DrawY += Size;
|
||||
DrawX = (int)(DrawX * FakeToScreenX) / FakeToScreenX; // realign
|
||||
DrawY = (int)(DrawY * FakeToScreenY) / FakeToScreenY;
|
||||
++pCursor->m_LineCount;
|
||||
++LineCount;
|
||||
if(pCursor->m_MaxLines > 0 && LineCount > pCursor->m_MaxLines)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -702,7 +706,7 @@ public:
|
|||
GotNewLine = 1;
|
||||
DrawX = (int)(DrawX * FakeToScreenX) / FakeToScreenX; // realign
|
||||
DrawY = (int)(DrawY * FakeToScreenY) / FakeToScreenY;
|
||||
++pCursor->m_LineCount;
|
||||
++LineCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -711,6 +715,7 @@ public:
|
|||
}
|
||||
|
||||
pCursor->m_X = DrawX;
|
||||
pCursor->m_LineCount = LineCount;
|
||||
|
||||
if(GotNewLine)
|
||||
pCursor->m_Y = DrawY;
|
||||
|
|
|
@ -17,6 +17,7 @@ public:
|
|||
int m_Flags;
|
||||
int m_LineCount;
|
||||
int m_CharCount;
|
||||
int m_MaxLines;
|
||||
|
||||
float m_StartX;
|
||||
float m_StartY;
|
||||
|
|
|
@ -31,6 +31,8 @@ void CChat::OnReset()
|
|||
}
|
||||
|
||||
m_Show = false;
|
||||
m_InputUpdate = false;
|
||||
m_ChatStringOffset = 0;
|
||||
}
|
||||
|
||||
void CChat::OnRelease()
|
||||
|
@ -101,7 +103,10 @@ bool CChat::OnInput(IInput::CEvent e)
|
|||
m_pClient->OnRelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Input.ProcessInput(e);
|
||||
m_InputUpdate = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -203,6 +208,7 @@ void CChat::OnRender()
|
|||
CTextCursor Cursor;
|
||||
TextRender()->SetCursor(&Cursor, x, y, 8.0f, TEXTFLAG_RENDER);
|
||||
Cursor.m_LineWidth = 200.0f;
|
||||
Cursor.m_MaxLines = 2;
|
||||
|
||||
if(m_Mode == MODE_ALL)
|
||||
TextRender()->TextEx(&Cursor, Localize("All"), -1);
|
||||
|
@ -213,7 +219,23 @@ void CChat::OnRender()
|
|||
|
||||
TextRender()->TextEx(&Cursor, ": ", -1);
|
||||
|
||||
TextRender()->TextEx(&Cursor, m_Input.GetString(), m_Input.GetCursorOffset());
|
||||
// check if the visible text has to be moved
|
||||
if(m_InputUpdate)
|
||||
{
|
||||
if(m_ChatStringOffset > m_Input.GetCursorOffset())
|
||||
--m_ChatStringOffset;
|
||||
else
|
||||
{
|
||||
CTextCursor Temp = Cursor;
|
||||
Temp.m_Flags = 0;
|
||||
TextRender()->TextEx(&Temp, m_Input.GetString()+m_ChatStringOffset, m_Input.GetCursorOffset()-m_ChatStringOffset);
|
||||
TextRender()->TextEx(&Temp, "|", -1);
|
||||
if(Temp.m_LineCount > 2)
|
||||
++m_ChatStringOffset;
|
||||
}
|
||||
}
|
||||
|
||||
TextRender()->TextEx(&Cursor, m_Input.GetString()+m_ChatStringOffset, m_Input.GetCursorOffset()-m_ChatStringOffset);
|
||||
CTextCursor Marker = Cursor;
|
||||
TextRender()->TextEx(&Marker, "|", -1);
|
||||
TextRender()->TextEx(&Cursor, m_Input.GetString()+m_Input.GetCursorOffset(), -1);
|
||||
|
|
|
@ -35,6 +35,8 @@ class CChat : public CComponent
|
|||
|
||||
int m_Mode;
|
||||
bool m_Show;
|
||||
bool m_InputUpdate;
|
||||
int m_ChatStringOffset;
|
||||
|
||||
static void ConSay(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConSayTeam(IConsole::IResult *pResult, void *pUserData);
|
||||
|
|
Loading…
Reference in a new issue