summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/npc_text.cpp21
-rw-r--r--src/gui/npc_text.h16
-rw-r--r--src/gui/npclistdialog.cpp22
-rw-r--r--src/gui/npclistdialog.h22
4 files changed, 24 insertions, 57 deletions
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 052b5f33..a8edc1db 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -55,28 +55,21 @@ NpcTextDialog::NpcTextDialog():
setLocationRelativeTo(getParent());
}
-void
-NpcTextDialog::setText(const std::string &text)
+void NpcTextDialog::setText(const std::string &text)
{
mText = text;
- draw();
+ mTextBox->setTextWrapped(mText);
}
-void
-NpcTextDialog::addText(const std::string &text)
+void NpcTextDialog::addText(const std::string &text)
{
- mText = mTextBox->getText() + text + "\n";
- draw();
+ setText(mText + text + "\n");
}
void NpcTextDialog::widgetResized(const gcn::Event &event)
{
Window::widgetResized(event);
- draw();
-}
-void NpcTextDialog::draw()
-{
const gcn::Rectangle &area = getChildrenArea();
const int width = area.width;
const int height = area.height;
@@ -89,10 +82,12 @@ void NpcTextDialog::draw()
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);
}
-void
-NpcTextDialog::action(const gcn::ActionEvent &event)
+void NpcTextDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok")
{
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index e26dd870..b647b9a1 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -57,23 +57,16 @@ class NpcTextDialog : public Window, public gcn::ActionListener
void widgetResized(const gcn::Event &event);
/**
- * Redraws the window
- */
- void draw();
-
- /**
* Called when receiving actions from the widgets.
*/
- void
- action(const gcn::ActionEvent &event);
+ void action(const gcn::ActionEvent &event);
/**
* Sets the text shows in the dialog.
*
* @param string The new text.
*/
- void
- setText(const std::string &string);
+ void setText(const std::string &string);
/**
* Adds the text to the text shows in the dialog. Also adds a newline
@@ -81,8 +74,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener
*
* @param string The text to add.
*/
- void
- addText(const std::string &string);
+ void addText(const std::string &string);
private:
gcn::Button *okButton;
@@ -92,4 +84,4 @@ class NpcTextDialog : public Window, public gcn::ActionListener
std::string mText;
};
-#endif
+#endif // _TMW_NPC_TEXT_H
diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp
index ba9e3d58..c17cd4aa 100644
--- a/src/gui/npclistdialog.cpp
+++ b/src/gui/npclistdialog.cpp
@@ -61,31 +61,26 @@ NpcListDialog::NpcListDialog():
setLocationRelativeTo(getParent());
}
-int
-NpcListDialog::getNumberOfElements()
+int NpcListDialog::getNumberOfElements()
{
return mItems.size();
}
-std::string
-NpcListDialog::getElementAt(int i)
+std::string NpcListDialog::getElementAt(int i)
{
return mItems[i];
}
-void
-NpcListDialog::parseItems(const std::string &itemString)
+void NpcListDialog::parseItems(const std::string &itemString)
{
std::istringstream iss(itemString);
std::string tmp;
- while(getline(iss, tmp, ':')) {
+ while (getline(iss, tmp, ':'))
mItems.push_back(tmp);
- }
}
-void
-NpcListDialog::reset()
+void NpcListDialog::reset()
{
mItems.clear();
}
@@ -93,11 +88,7 @@ NpcListDialog::reset()
void NpcListDialog::widgetResized(const gcn::Event &event)
{
Window::widgetResized(event);
- draw();
-}
-void NpcListDialog::draw()
-{
const gcn::Rectangle &area = getChildrenArea();
const int width = area.width;
const int height = area.height;
@@ -112,8 +103,7 @@ void NpcListDialog::draw()
cancelButton->getY());
}
-void
-NpcListDialog::action(const gcn::ActionEvent &event)
+void NpcListDialog::action(const gcn::ActionEvent &event)
{
int choice = 0;
diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h
index 77f0c177..04c5c4d9 100644
--- a/src/gui/npclistdialog.h
+++ b/src/gui/npclistdialog.h
@@ -58,41 +58,31 @@ class NpcListDialog : public Window, public gcn::ActionListener,
void widgetResized(const gcn::Event &event);
/**
- * Redraws the window
- */
- void draw();
-
- /**
* Called when receiving actions from the widgets.
*/
- void
- action(const gcn::ActionEvent &event);
+ void action(const gcn::ActionEvent &event);
/**
* Returns the number of items in the choices list.
*/
- int
- getNumberOfElements();
+ int getNumberOfElements();
/**
* Returns the name of item number i of the choices list.
*/
- std::string
- getElementAt(int i);
+ std::string getElementAt(int i);
/**
* Fills the options list for an NPC dialog.
*
* @param itemString A string with the options separated with colons.
*/
- void
- parseItems(const std::string &itemString);
+ void parseItems(const std::string &itemString);
/**
* Resets the list by removing all items.
*/
- void
- reset();
+ void reset();
private:
gcn::ListBox *mItemList;
@@ -103,4 +93,4 @@ class NpcListDialog : public Window, public gcn::ActionListener,
std::vector<std::string> mItems;
};
-#endif
+#endif // _TMW_GUI_NPCLISTDIALOG_H