MCPcopy Create free account
hub / github.com/ddnet/ddnet / PossibleCommandsRenderCallback

Method PossibleCommandsRenderCallback

src/game/client/components/console.cpp:1068–1115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1066};
1067
1068void CGameConsole::PossibleCommandsRenderCallback(int Index, const char *pStr, void *pUser)
1069{
1070 CCompletionOptionRenderInfo *pInfo = static_cast<CCompletionOptionRenderInfo *>(pUser);
1071
1072 ColorRGBA TextColor;
1073 if(Index == pInfo->m_WantedCompletion)
1074 {
1075 TextColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
1076 const float TextWidth = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_FontSize, pStr);
1077 const CUIRect Rect = {pInfo->m_Cursor.m_X - 2.0f, pInfo->m_Cursor.m_Y - 2.0f, TextWidth + 4.0f, pInfo->m_Cursor.m_FontSize + 4.0f};
1078 Rect.Draw(ColorRGBA(0.0f, 0.0f, 0.0f, 0.85f), IGraphics::CORNER_ALL, 2.0f);
1079
1080 // scroll when out of sight
1081 const bool MoveLeft = Rect.x - *pInfo->m_pOffsetChange < 0.0f;
1082 const bool MoveRight = Rect.x + Rect.w - *pInfo->m_pOffsetChange > pInfo->m_Width;
1083 if(MoveLeft && !MoveRight)
1084 {
1085 *pInfo->m_pOffsetChange -= -Rect.x + pInfo->m_Width / 4.0f;
1086 }
1087 else if(!MoveLeft && MoveRight)
1088 {
1089 *pInfo->m_pOffsetChange += Rect.x + Rect.w - pInfo->m_Width + pInfo->m_Width / 4.0f;
1090 }
1091 }
1092 else
1093 {
1094 TextColor = ColorRGBA(0.75f, 0.75f, 0.75f, 1.0f);
1095 }
1096
1097 const char *pMatchStart = str_find_nocase(pStr, pInfo->m_pCurrentCmd);
1098 if(pMatchStart)
1099 {
1100 pInfo->m_pSelf->TextRender()->TextColor(TextColor);
1101 pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, pMatchStart - pStr);
1102 pInfo->m_pSelf->TextRender()->TextColor(1.0f, 0.75f, 0.0f, 1.0f);
1103 pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pMatchStart, str_length(pInfo->m_pCurrentCmd));
1104 pInfo->m_pSelf->TextRender()->TextColor(TextColor);
1105 pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pMatchStart + str_length(pInfo->m_pCurrentCmd));
1106 }
1107 else
1108 {
1109 pInfo->m_pSelf->TextRender()->TextColor(TextColor);
1110 pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr);
1111 }
1112
1113 pInfo->m_Cursor.m_X += 7.0f;
1114 pInfo->m_TotalWidth = pInfo->m_Cursor.m_X + pInfo->m_Offset;
1115}
1116
1117void CGameConsole::Prompt(char (&aPrompt)[32])
1118{

Callers

nothing calls this directly

Calls 8

str_find_nocaseFunction · 0.85
str_lengthFunction · 0.85
TextWidthMethod · 0.80
TextColorMethod · 0.80
TextExMethod · 0.80
ColorRGBAClass · 0.70
TextRenderMethod · 0.45
DrawMethod · 0.45

Tested by

no test coverage detected