diff options
author | Ira Rice <irarice@gmail.com> | 2009-01-28 16:58:56 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-01-28 16:58:56 -0700 |
commit | 4418d3678337276070e6d46d8011ce052be388a5 (patch) | |
tree | 03137a83a020670cfce5a7044238314509025464 /src/gui | |
parent | 1ca8d08b7619e1958371ce8d82e201b82ae39e32 (diff) | |
download | mana-4418d3678337276070e6d46d8011ce052be388a5.tar.gz mana-4418d3678337276070e6d46d8011ce052be388a5.tar.bz2 mana-4418d3678337276070e6d46d8011ce052be388a5.tar.xz mana-4418d3678337276070e6d46d8011ce052be388a5.zip |
Moved NPC text back to using the textbox. Rationale is that the textbox
code is in much better shape than the browserbox code at the moment, and
that the move to using the browserbox was a bit silly, as textbox
already wraps.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/npc_text.cpp | 40 | ||||
-rw-r--r-- | src/gui/npc_text.h | 13 |
2 files changed, 38 insertions, 15 deletions
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index a2e043d1..b2256f07 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -22,9 +22,9 @@ #include <string> #include "npc_text.h" -#include "browserbox.h" #include "button.h" #include "scrollarea.h" +#include "textbox.h" #include "widgets/layout.h" @@ -42,10 +42,11 @@ NpcTextDialog::NpcTextDialog(): setDefaultSize(0, 0, 260, 200); - mBrowserBox = new BrowserBox(BrowserBox::AUTO_WRAP); - mBrowserBox->setOpaque(false); + mTextBox = new TextBox; + mTextBox->setEditable(false); + mTextBox->setOpaque(false); - scrollArea = new ScrollArea(mBrowserBox); + scrollArea = new ScrollArea(mTextBox); okButton = new Button(_("OK"), "ok", this); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); @@ -61,30 +62,43 @@ NpcTextDialog::NpcTextDialog(): setLocationRelativeTo(getParent()); } -void NpcTextDialog::clearText() -{ - mBrowserBox->clearRows(); -} - void NpcTextDialog::setText(const std::string &text) { - mBrowserBox->clearRows(); - mBrowserBox->addRow(text); + const gcn::Rectangle &area = getChildrenArea(); + const int width = area.width; + + mText = text; + mTextBox->setMinWidth(width - 30); + mTextBox->setTextWrapped(mText); } void NpcTextDialog::addText(const std::string &text) { - mBrowserBox->addRow(text); + setText(mText + text + "\n"); } void NpcTextDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") { - clearText(); + setText(""); setVisible(false); if (current_npc) current_npc->nextDialog(); current_npc = 0; } } + +void NpcTextDialog::widgetResized(const gcn::Event &event) +{ + Window::widgetResized(event); + + const gcn::Rectangle &area = getChildrenArea(); + + mTextBox->setMinWidth(area.width - 30); + mTextBox->setTextWrapped(mText); + + // Set the text again so that it gets wrapped according to the new size + mTextBox->setTextWrapped(mText); +} + diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index b4b6f1af..4e0d33aa 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -29,7 +29,7 @@ #include "scrollarea.h" #include "window.h" -class BrowserBox; +class TextBox; /** * The npc text dialog. @@ -71,10 +71,19 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + /** + * Called when resizing the window. + * + * @param event The calling event + */ + void widgetResized(const gcn::Event &event); + private: gcn::Button *okButton; gcn::ScrollArea *scrollArea; - BrowserBox *mBrowserBox; + TextBox *mTextBox; + + std::string mText; }; #endif // NPC_TEXT_H |