aboutsummaryrefslogtreecommitdiff
path: root/src/Message.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-23 09:53:31 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-23 09:55:12 +0200
commitddff0f1b7ea84f6a1321b8eb8a4d47317873d955 (patch)
tree28565c3a3d336559fcf149e1552ae237cc3d855d /src/Message.cpp
parent1e0e68f9cda51c881b32a54d9eece71c1428f7ac (diff)
Add word wrap for message board & TODO
TODO: Message board is now redrawn every frame. Text should be modified to render on static & dynamic texture -> text & static images on static texture, gif & video on dynamic texture
Diffstat (limited to 'src/Message.cpp')
-rw-r--r--src/Message.cpp62
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;
- }
}