summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/npc_text.cpp46
-rw-r--r--src/gui/npc_text.h19
2 files changed, 20 insertions, 45 deletions
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 0570d7a9..fde5dc9c 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -22,7 +22,9 @@
#include <string>
#include "npc_text.h"
-#include "textbox.h"
+#include "browserbox.h"
+#include "button.h"
+#include "scrollarea.h"
#include "../npc.h"
@@ -36,10 +38,10 @@ NpcTextDialog::NpcTextDialog():
setMinWidth(200);
setMinHeight(150);
- mTextBox = new TextBox;
- mTextBox->setEditable(false);
+ mBrowserBox = new BrowserBox(BrowserBox::AUTO_WRAP);
+ mBrowserBox->setOpaque(true);
- scrollArea = new ScrollArea(mTextBox);
+ scrollArea = new ScrollArea(mBrowserBox);
okButton = new Button(_("OK"), "ok", this);
setContentSize(260, 175);
@@ -57,47 +59,27 @@ NpcTextDialog::NpcTextDialog():
setLocationRelativeTo(getParent());
}
-void NpcTextDialog::setText(const std::string &text)
+void NpcTextDialog::clearText()
{
- const gcn::Rectangle &area = getChildrenArea();
- const int width = area.width;
-
- mText = text;
- mTextBox->setMinWidth(width - 30);
- mTextBox->setTextWrapped(mText);
+ mBrowserBox->clearRows();
}
-void NpcTextDialog::addText(const std::string &text)
+void NpcTextDialog::setText(const std::string &text)
{
- setText(mText + text + "\n");
+ mBrowserBox->clearRows();
+ mBrowserBox->addRow(text);
}
-void NpcTextDialog::widgetResized(const gcn::Event &event)
+void NpcTextDialog::addText(const std::string &text)
{
- Window::widgetResized(event);
-
- const gcn::Rectangle &area = getChildrenArea();
- const int width = area.width;
- const int height = area.height;
-
- mTextBox->setMinWidth(width - 30);
- mTextBox->setTextWrapped(mText);
-
- scrollArea->setDimension(gcn::Rectangle(
- 5, 5, width - 10, height - 15 - okButton->getHeight()));
- okButton->setPosition(
- width - 5 - okButton->getWidth(),
- height - 5 - okButton->getHeight());
-
- // Set the text again so that it gets wrapped according to the new size
- mTextBox->setTextWrapped(mText);
+ mBrowserBox->addRow(text);
}
void NpcTextDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok")
{
- setText("");
+ clearText();
setVisible(false);
if (current_npc)
current_npc->nextDialog();
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index 75968fa9..90b15abd 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -26,13 +26,10 @@
#include <guichan/actionlistener.hpp>
-#include "button.h"
#include "scrollarea.h"
#include "window.h"
-#include "../guichanfwd.h"
-
-class TextBox;
+class BrowserBox;
/**
* The npc text dialog.
@@ -50,16 +47,14 @@ class NpcTextDialog : public Window, public gcn::ActionListener
NpcTextDialog();
/**
- * Called when resizing the window.
- *
- * @param event The calling event
+ * Called when receiving actions from the widgets.
*/
- void widgetResized(const gcn::Event &event);
+ void action(const gcn::ActionEvent &event);
/**
- * Called when receiving actions from the widgets.
+ * Clears the text shown in the dialog.
*/
- void action(const gcn::ActionEvent &event);
+ void clearText();
/**
* Sets the text shows in the dialog.
@@ -79,9 +74,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener
private:
gcn::Button *okButton;
gcn::ScrollArea *scrollArea;
- TextBox *mTextBox;
-
- std::string mText;
+ BrowserBox *mBrowserBox;
};
#endif // _TMW_NPC_TEXT_H