mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
Merge pull request #7990 from Robyt3/Client-Console-Minor-Refactoring
Minor refactoring of console rendering
This commit is contained in:
commit
0c7015bdf8
|
@ -884,9 +884,7 @@ void CGameConsole::OnRender()
|
||||||
CUIRect Screen = *UI()->Screen();
|
CUIRect Screen = *UI()->Screen();
|
||||||
CInstance *pConsole = CurrentConsole();
|
CInstance *pConsole = CurrentConsole();
|
||||||
|
|
||||||
float MaxConsoleHeight = Screen.h * 3 / 5.0f;
|
const float MaxConsoleHeight = Screen.h * 3 / 5.0f;
|
||||||
float ConsoleHeight;
|
|
||||||
|
|
||||||
float Progress = (Client()->GlobalTime() - (m_StateChangeEnd - m_StateChangeDuration)) / m_StateChangeDuration;
|
float Progress = (Client()->GlobalTime() - (m_StateChangeEnd - m_StateChangeDuration)) / m_StateChangeDuration;
|
||||||
|
|
||||||
if(Progress >= 1.0f)
|
if(Progress >= 1.0f)
|
||||||
|
@ -916,15 +914,14 @@ void CGameConsole::OnRender()
|
||||||
Input()->MouseModeAbsolute();
|
Input()->MouseModeAbsolute();
|
||||||
|
|
||||||
float ConsoleHeightScale;
|
float ConsoleHeightScale;
|
||||||
|
|
||||||
if(m_ConsoleState == CONSOLE_OPENING)
|
if(m_ConsoleState == CONSOLE_OPENING)
|
||||||
ConsoleHeightScale = ConsoleScaleFunc(Progress);
|
ConsoleHeightScale = ConsoleScaleFunc(Progress);
|
||||||
else if(m_ConsoleState == CONSOLE_CLOSING)
|
else if(m_ConsoleState == CONSOLE_CLOSING)
|
||||||
ConsoleHeightScale = ConsoleScaleFunc(1.0f - Progress);
|
ConsoleHeightScale = ConsoleScaleFunc(1.0f - Progress);
|
||||||
else // if (console_state == CONSOLE_OPEN)
|
else // CONSOLE_OPEN
|
||||||
ConsoleHeightScale = ConsoleScaleFunc(1.0f);
|
ConsoleHeightScale = ConsoleScaleFunc(1.0f);
|
||||||
|
|
||||||
ConsoleHeight = ConsoleHeightScale * MaxConsoleHeight;
|
const float ConsoleHeight = ConsoleHeightScale * MaxConsoleHeight;
|
||||||
|
|
||||||
UI()->MapScreen();
|
UI()->MapScreen();
|
||||||
|
|
||||||
|
@ -959,6 +956,7 @@ void CGameConsole::OnRender()
|
||||||
Array[1] = IGraphics::CColorVertex(1, 0, 0, 0, 0.0f);
|
Array[1] = IGraphics::CColorVertex(1, 0, 0, 0, 0.0f);
|
||||||
Array[2] = IGraphics::CColorVertex(2, 0, 0, 0, 0.25f);
|
Array[2] = IGraphics::CColorVertex(2, 0, 0, 0, 0.25f);
|
||||||
Array[3] = IGraphics::CColorVertex(3, 0, 0, 0, 0.25f);
|
Array[3] = IGraphics::CColorVertex(3, 0, 0, 0, 0.25f);
|
||||||
|
|
||||||
Graphics()->SetColorVertex(Array, 4);
|
Graphics()->SetColorVertex(Array, 4);
|
||||||
QuadItem = IGraphics::CQuadItem(0, ConsoleHeight - 20, Screen.w, 10);
|
QuadItem = IGraphics::CQuadItem(0, ConsoleHeight - 20, Screen.w, 10);
|
||||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||||
|
@ -973,15 +971,14 @@ void CGameConsole::OnRender()
|
||||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||||
Graphics()->QuadsEnd();
|
Graphics()->QuadsEnd();
|
||||||
|
|
||||||
ConsoleHeight -= 22.0f;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// Get height of 1 line
|
// Get height of 1 line
|
||||||
float LineHeight = TextRender()->TextBoundingBox(FONT_SIZE, " ", -1, -1, LINE_SPACING).m_H;
|
const float LineHeight = TextRender()->TextBoundingBox(FONT_SIZE, " ", -1, -1.0f, LINE_SPACING).m_H;
|
||||||
|
|
||||||
|
const float RowHeight = FONT_SIZE * 1.5f;
|
||||||
|
|
||||||
float RowHeight = FONT_SIZE * 1.5f;
|
|
||||||
float x = 3;
|
float x = 3;
|
||||||
float y = ConsoleHeight - RowHeight - 5.0f;
|
float y = ConsoleHeight - RowHeight - 27.0f;
|
||||||
|
|
||||||
const float InitialX = x;
|
const float InitialX = x;
|
||||||
const float InitialY = y;
|
const float InitialY = y;
|
||||||
|
@ -1150,11 +1147,9 @@ void CGameConsole::OnRender()
|
||||||
|
|
||||||
const float XScale = Graphics()->ScreenWidth() / Screen.w;
|
const float XScale = Graphics()->ScreenWidth() / Screen.w;
|
||||||
const float YScale = Graphics()->ScreenHeight() / Screen.h;
|
const float YScale = Graphics()->ScreenHeight() / Screen.h;
|
||||||
float CalcOffsetY = 0;
|
const float CalcOffsetY = LineHeight * std::floor((y - RowHeight) / LineHeight);
|
||||||
while(y - (CalcOffsetY + LineHeight) > RowHeight)
|
const float ClipStartY = (y - CalcOffsetY) * YScale;
|
||||||
CalcOffsetY += LineHeight;
|
Graphics()->ClipEnable(0, ClipStartY, Screen.w * XScale, y * YScale - ClipStartY);
|
||||||
float ClipStartY = y - CalcOffsetY;
|
|
||||||
Graphics()->ClipEnable(0, ClipStartY * YScale, Screen.w * XScale, y * YScale - ClipStartY * YScale);
|
|
||||||
|
|
||||||
while(pEntry)
|
while(pEntry)
|
||||||
{
|
{
|
||||||
|
@ -1175,25 +1170,24 @@ void CGameConsole::OnRender()
|
||||||
OffsetY -= (pConsole->m_BacklogLastActiveLine - SkippedLines) * LineHeight;
|
OffsetY -= (pConsole->m_BacklogLastActiveLine - SkippedLines) * LineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
float LocalOffsetY = OffsetY + pEntry->m_YOffset / (float)pEntry->m_LineCount;
|
const float LocalOffsetY = OffsetY + pEntry->m_YOffset / (float)pEntry->m_LineCount;
|
||||||
OffsetY += pEntry->m_YOffset;
|
OffsetY += pEntry->m_YOffset;
|
||||||
|
|
||||||
// Only apply offset if we do not keep scroll position (m_BacklogCurLine == 0)
|
// Only apply offset if we do not keep scroll position (m_BacklogCurLine == 0)
|
||||||
if((pConsole->m_HasSelection || pConsole->m_MouseIsPress) && pConsole->m_NewLineCounter > 0 && pConsole->m_BacklogCurLine == 0)
|
if((pConsole->m_HasSelection || pConsole->m_MouseIsPress) && pConsole->m_NewLineCounter > 0 && pConsole->m_BacklogCurLine == 0)
|
||||||
{
|
{
|
||||||
float MouseExtraOff = pEntry->m_YOffset;
|
pConsole->m_MousePress.y -= pEntry->m_YOffset;
|
||||||
pConsole->m_MousePress.y -= MouseExtraOff;
|
|
||||||
if(!pConsole->m_MouseIsPress)
|
if(!pConsole->m_MouseIsPress)
|
||||||
pConsole->m_MouseRelease.y -= MouseExtraOff;
|
pConsole->m_MouseRelease.y -= pEntry->m_YOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop rendering when lines reach the top
|
// stop rendering when lines reach the top
|
||||||
bool Outside = y - OffsetY <= RowHeight;
|
const bool Outside = y - OffsetY <= RowHeight;
|
||||||
int CanRenderOneLine = y - LocalOffsetY > RowHeight;
|
const bool CanRenderOneLine = y - LocalOffsetY > RowHeight;
|
||||||
if(Outside && !CanRenderOneLine)
|
if(Outside && !CanRenderOneLine)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
int LinesNotRendered = pEntry->m_LineCount - minimum((int)std::floor((y - LocalOffsetY) / RowHeight), pEntry->m_LineCount);
|
const int LinesNotRendered = pEntry->m_LineCount - minimum((int)std::floor((y - LocalOffsetY) / RowHeight), pEntry->m_LineCount);
|
||||||
pConsole->m_LinesRendered -= LinesNotRendered;
|
pConsole->m_LinesRendered -= LinesNotRendered;
|
||||||
|
|
||||||
TextRender()->SetCursor(&Cursor, 0.0f, y - OffsetY, FONT_SIZE, TEXTFLAG_RENDER);
|
TextRender()->SetCursor(&Cursor, 0.0f, y - OffsetY, FONT_SIZE, TEXTFLAG_RENDER);
|
||||||
|
|
Loading…
Reference in a new issue