summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/npc_text.cpp40
-rw-r--r--src/gui/npc_text.h13
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