From 1baf22ad58cc1a9aa9089ca9a09fc80a453cb3c9 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Wed, 9 Dec 2020 16:12:53 +0000 Subject: gui: receive msg from server to chat and move it --- src/client/gui/Client.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src/client/gui/Client.cpp') diff --git a/src/client/gui/Client.cpp b/src/client/gui/Client.cpp index 2465ab7..137558d 100644 --- a/src/client/gui/Client.cpp +++ b/src/client/gui/Client.cpp @@ -1,6 +1,39 @@ #include "Client.hpp" -void Client::ShowMessage(const char *msg) +void Client::AddMessage(const char *msg, int type) { - chat->value(msg); + int len_msg = strlen(msg); + char *source = new char[len_msg+1]; + strcpy(source, msg); + + int lines = (len_msg / oneline_len) + 1; + + for(int i = lines; i < lines_in_chat; i++) { + chat[i-lines]->value(chat[i]->value()); + chat[i-lines]->textfont(chat[i]->textfont()); + } + + int need_print = lines; + while(need_print > 0) + { + int len = strlen(source); + int size = len > oneline_len ? oneline_len : len; + + char *str = new char[oneline_len + 1]; + int str_ptr = oneline_len * (lines - need_print); + memcpy(str, source + str_ptr, oneline_len); + str[size] = '\0'; + + int spec = 0; + if(type == system_msg) spec = FL_ITALIC; + + int p = lines_in_chat-need_print; + chat[p]->textfont(STD_FONT+spec); + chat[p]->value(str); + delete[] str; + + need_print--; + } + + delete[] source; } \ No newline at end of file -- cgit v1.2.3-18-g5258