diff options
Diffstat (limited to 'src/Message.cpp')
-rw-r--r-- | src/Message.cpp | 62 |
1 files changed, 5 insertions, 57 deletions
diff --git a/src/Message.cpp b/src/Message.cpp index 19630b3..285a722 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -1,67 +1,15 @@ #include "../include/Message.hpp" -#include "../include/StringView.hpp" +#include "../include/ResourceCache.hpp" +#include "../include/Settings.hpp" using namespace std; namespace dchat { - Message::Message(User *_user) : - user(_user) + Message::Message(User *_user, const std::string &_text) : + user(_user), + text(sf::String::fromUtf8(_text.begin(), _text.end()), ResourceCache::getFont("fonts/Roboto-Regular.ttf"), 17 * Settings::getScaling(), 0.0f, false) { } - - Message::~Message() - { - for(MessagePart *messagePart : messageParts) - { - delete messagePart; - } - } - - void Message::addText(const string &text, bool newLine) - { - messageParts.push_back(new MessagePartText(text, newLine)); - } - - void Message::addEmoji(const string &url, bool newLine) - { - messageParts.push_back(new MessagePartEmoji(url, newLine)); - } - - vector<MessagePart*>& Message::getParts() - { - return messageParts; - } - - StringView getNextNewLine(const StringView &str) - { - for(usize i = 0; i < str.size; ++i) - { - if(str[i] == '\n') - return StringView(str.data, i); - } - return StringView(); - } - - Message* Message::buildFromString(User *user, const std::string &str) - { - Message *message = new Message(user); - usize strOffset = 0; - while(strOffset < str.size()) - { - usize foundIndex = str.find('\n', strOffset); - usize lineEnd = foundIndex; - if(foundIndex == string::npos) - lineEnd = str.size(); - - message->addText(str.substr(strOffset, lineEnd - strOffset), foundIndex != string::npos); - - if(foundIndex == string::npos) - break; - else - strOffset = lineEnd + 1; - } - return message; - } } |