summaryrefslogtreecommitdiff
path: root/src/gui/chat.cpp
diff options
context:
space:
mode:
authorEric Scrivner <zenogais@gmail.com>2005-03-13 21:57:24 +0000
committerEric Scrivner <zenogais@gmail.com>2005-03-13 21:57:24 +0000
commitbb5886f5351a148b5443adaee0a64ca6e81ee0b9 (patch)
treee8aaa3e574efe9b0746ae7fb8d26bf348a8ccb20 /src/gui/chat.cpp
parentea6011fbc06a2adc9805baabf8c921b48f60f2c3 (diff)
downloadmana-bb5886f5351a148b5443adaee0a64ca6e81ee0b9.tar.gz
mana-bb5886f5351a148b5443adaee0a64ca6e81ee0b9.tar.bz2
mana-bb5886f5351a148b5443adaee0a64ca6e81ee0b9.tar.xz
mana-bb5886f5351a148b5443adaee0a64ca6e81ee0b9.zip
Added line wrapping on a per-word basis
Diffstat (limited to 'src/gui/chat.cpp')
-rw-r--r--src/gui/chat.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 95f29dbd..253fb3f4 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -96,10 +96,9 @@ void ChatWindow::chat_log(std::string line, int own)
if (line.length() > maxLength)
{
+ tempText = line;
if (line.length() > maxLength)
- tempText = line.substr(0, maxLength);
- else
- tempText = line;
+ line = cut_string(tempText, maxLength);
tmp.text = tempText;
@@ -107,9 +106,6 @@ void ChatWindow::chat_log(std::string line, int own)
//chatlog_file.flush();
chatlog.push_front(tmp);
-
- if (line.length() > maxLength)
- line = line.substr(maxLength, line.length() - maxLength);
}
else // Normal message
{
@@ -312,3 +308,35 @@ std::string ChatWindow::const_msg(CHATSKILL action)
return msg;
}
+
+std::string ChatWindow::cut_string(std::string& value, unsigned int maximumLength)
+{
+ // If the string exceeds the maximum length
+ if(value.length() > maximumLength)
+ {
+ unsigned int index = 0;
+ unsigned int lastSpace = 0;
+ std::string cutOff = "";
+
+ for(index = 0; index < maximumLength; index++) {
+ if(value.at(index) == ' ') {
+ lastSpace = index;
+ }
+ }
+
+ // If the last space is at the beginning of the string
+ if(lastSpace == 0) {
+ // Just cut it right off from the end
+ cutOff = value.substr(maximumLength);
+ value = value.substr(0, maximumLength);
+ } else {
+ // Cut it off from the last space forward
+ cutOff = value.substr(lastSpace + 1);
+ value = value.substr(0, lastSpace);
+ }
+
+ return cutOff;
+ }
+
+ return std::string("");
+} \ No newline at end of file