diff options
author | Aaron Marks <nymacro@gmail.com> | 2005-05-05 10:39:01 +0000 |
---|---|---|
committer | Aaron Marks <nymacro@gmail.com> | 2005-05-05 10:39:01 +0000 |
commit | e40c16a5f31cab575b1efb4dc69f679e2e857856 (patch) | |
tree | 05cf57121edd05b485618eed055e3bc2c6582707 /src | |
parent | 27c42e6505a99a0464361aca0fb6e23dce9b863e (diff) | |
download | mana-e40c16a5f31cab575b1efb4dc69f679e2e857856.tar.gz mana-e40c16a5f31cab575b1efb4dc69f679e2e857856.tar.bz2 mana-e40c16a5f31cab575b1efb4dc69f679e2e857856.tar.xz mana-e40c16a5f31cab575b1efb4dc69f679e2e857856.zip |
Added text wrapping to NPC dialog.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/npc_text.cpp | 25 |
1 files 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) |