+/******************************************************************************/
+static void updateChat(Client& client, f32 dtime, bool show_debug,
+ const v2u32& screensize, bool show_chat, u32 show_profiler,
+ ChatBackend& chat_backend, gui::IGUIStaticText* guitext_chat,
+ gui::IGUIFont* font)
+{
+ // Add chat log output for errors to be shown in chat
+ static LogOutputBuffer chat_log_error_buf(LMT_ERROR);
+
+ // Get new messages from error log buffer
+ while(!chat_log_error_buf.empty()) {
+ chat_backend.addMessage(L"", narrow_to_wide(chat_log_error_buf.get()));
+ }
+
+ // Get new messages from client
+ std::wstring message;
+ while (client.getChatMessage(message)) {
+ chat_backend.addUnparsedMessage(message);
+ }
+
+ // Remove old messages
+ chat_backend.step(dtime);
+
+ // Display all messages in a static text element
+ unsigned int recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
+ std::wstring recent_chat = chat_backend.getRecentChat();
+
+ // TODO replace by fontengine fcts
+ unsigned int line_height = font->getDimension(L"Ay").Height + font->getKerningHeight();
+
+ guitext_chat->setText(recent_chat.c_str());
+
+ // Update gui element size and position
+ s32 chat_y = 5 + line_height;
+ if (show_debug)
+ chat_y += line_height;
+
+ core::rect<s32> rect(10, chat_y, font->getDimension(recent_chat.c_str()).Width +10,
+ chat_y + (recent_chat_count * line_height));
+
+ guitext_chat->setRelativePosition(rect);
+ // Don't show chat if disabled or empty or profiler is enabled
+ guitext_chat->setVisible(
+ show_chat && recent_chat_count != 0 && !show_profiler);
+}
+