From 6498f9a6b140385b1614fe59abc4f5981d050050 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 20 Jan 2009 10:09:59 +0000 Subject: Switch the NPC text dialog over to a BrowserBox --- src/gui/npc_text.cpp | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) (limited to 'src/gui/npc_text.cpp') 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 #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(); -- cgit v1.2.3-70-g09d2