From e40c16a5f31cab575b1efb4dc69f679e2e857856 Mon Sep 17 00:00:00 2001 From: Aaron Marks Date: Thu, 5 May 2005 10:39:01 +0000 Subject: Added text wrapping to NPC dialog. --- src/gui/npc_text.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 9b94fac6..b6bd962f 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -61,13 +61,32 @@ NpcTextDialog::~NpcTextDialog() void NpcTextDialog::setText(const char *text) { - textBox->setText(std::string(text)); + std::string tmp = ""; + int lineWidth = 0; + int w = scrollArea->getWidth(); + for (unsigned int i = 0; i < strlen(text); i++) + { + if (text[i] != '\n') + { + std::string tmpChar = ""; tmpChar += text[i]; + lineWidth += getFont()->getWidth(tmpChar); + if (lineWidth > w) { + tmp += '\n'; + lineWidth = 0; + } + } else + { + lineWidth = 0; + } + tmp += text[i]; + } + textBox->setText(tmp); } void NpcTextDialog::addText(const char *text) { - textBox->setText( - textBox->getText() + std::string(text) + std::string("\n")); + std::string tmp = textBox->getText() + std::string(text) + std::string("\n"); + setText(tmp.c_str()); } void NpcTextDialog::action(const std::string& eventId) -- cgit v1.2.3-70-g09d2