guiChatConsole: fix the unicode characters crowded together on prompt (#12867)

Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
This commit is contained in:
Riceball LEE 2022-10-21 23:12:07 +08:00 committed by GitHub
parent 7153cb8a0b
commit 8bdedd2bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -353,44 +353,48 @@ void GUIChatConsole::drawPrompt()
if (!m_font) if (!m_font)
return; return;
u32 row = m_chat_backend->getConsoleBuffer().getRows();
s32 line_height = m_fontsize.Y;
s32 y = row * line_height + m_height - m_desired_height;
ChatPrompt& prompt = m_chat_backend->getPrompt(); ChatPrompt& prompt = m_chat_backend->getPrompt();
std::wstring prompt_text = prompt.getVisiblePortion(); std::wstring prompt_text = prompt.getVisiblePortion();
// FIXME Draw string at once, not character by character u32 font_width = m_fontsize.X;
// That will only work with the cursor once we have a monospace font u32 font_height = m_fontsize.Y;
for (u32 i = 0; i < prompt_text.size(); ++i)
{ core::dimension2d<u32> size = m_font->getDimension(prompt_text.c_str());
wchar_t ws[2] = {prompt_text[i], 0}; u32 text_width = size.Width;
s32 x = (1 + i) * m_fontsize.X; if (size.Height > font_height)
font_height = size.Height;
u32 row = m_chat_backend->getConsoleBuffer().getRows();
s32 y = row * font_height + m_height - m_desired_height;
core::rect<s32> destrect( core::rect<s32> destrect(
x, y, x + m_fontsize.X, y + m_fontsize.Y); font_width, y, font_width + text_width, y + font_height);
m_font->draw( m_font->draw(
ws, prompt_text.c_str(),
destrect, destrect,
video::SColor(255, 255, 255, 255), video::SColor(255, 255, 255, 255),
false, false,
false, false,
&AbsoluteClippingRect); &AbsoluteClippingRect);
}
// Draw the cursor during on periods // Draw the cursor during on periods
if ((m_cursor_blink & 0x8000) != 0) if ((m_cursor_blink & 0x8000) != 0)
{ {
s32 cursor_pos = prompt.getVisibleCursorPosition(); s32 cursor_pos = prompt.getVisibleCursorPosition();
if (cursor_pos >= 0) if (cursor_pos >= 0)
{ {
u32 text_to_cursor_pos_width = m_font->getDimension(prompt_text.substr(0, cursor_pos).c_str()).Width;
s32 cursor_len = prompt.getCursorLength(); s32 cursor_len = prompt.getCursorLength();
video::IVideoDriver* driver = Environment->getVideoDriver(); video::IVideoDriver* driver = Environment->getVideoDriver();
s32 x = (1 + cursor_pos) * m_fontsize.X; s32 x = font_width + text_to_cursor_pos_width;
core::rect<s32> destrect( core::rect<s32> destrect(
x, x,
y + m_fontsize.Y * (1.0 - m_cursor_height), y + font_height * (1.0 - m_cursor_height),
x + m_fontsize.X * MYMAX(cursor_len, 1), x + font_width * MYMAX(cursor_len, 1),
y + m_fontsize.Y * (cursor_len ? m_cursor_height+1 : 1) y + font_height * (cursor_len ? m_cursor_height+1 : 1)
); );
video::SColor cursor_color(255,255,255,255); video::SColor cursor_color(255,255,255,255);
driver->draw2DRectangle( driver->draw2DRectangle(