summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2008-10-25 20:36:09 +0000
committerIra Rice <irarice@gmail.com>2008-10-25 20:36:09 +0000
commit0288225cf876d787a29f5b1d4e5885cc1d759e6f (patch)
tree1aad1fc53a8ca36893fcd7b11ecb8d125e9fd3a8
parentcd7415bd8ec7f9dc1ec91edbe052df97a7f644bf (diff)
downloadmana-client-0288225cf876d787a29f5b1d4e5885cc1d759e6f.tar.gz
mana-client-0288225cf876d787a29f5b1d4e5885cc1d759e6f.tar.bz2
mana-client-0288225cf876d787a29f5b1d4e5885cc1d759e6f.tar.xz
mana-client-0288225cf876d787a29f5b1d4e5885cc1d759e6f.zip
Made the ok dialogue use code that's similar to the speech bubble, so
that it can take advantage of the text box's wrapping code.
-rw-r--r--src/gui/npc_text.cpp3
-rw-r--r--src/gui/ok_dialog.cpp54
-rw-r--r--src/gui/ok_dialog.h10
3 files changed, 52 insertions, 15 deletions
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index d51698fb..8324a196 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -36,8 +36,9 @@ NpcTextDialog::NpcTextDialog():
{
mTextBox = new TextBox;
mTextBox->setEditable(false);
+
gcn::ScrollArea *scrollArea = new ScrollArea(mTextBox);
- Button *okButton = new Button("OK", "ok", this);
+ gcn::Button *okButton = new Button("OK", "ok", this);
setContentSize(260, 175);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index c49bb6bb..13124c3c 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -23,31 +23,52 @@
#include "ok_dialog.h"
-#include <guichan/widgets/label.hpp>
-
-#include "button.h"
+#include <guichan/font.hpp>
OkDialog::OkDialog(const std::string &title, const std::string &msg,
Window *parent):
Window(title, true, parent)
{
- gcn::Label *textLabel = new gcn::Label(msg);
- gcn::Button *okButton = new Button("Ok", "ok", this);
+ mTextBox = new TextBox();
+ mTextBox->setEditable(false);
+ mTextBox->setOpaque(false);
+
+ mTextArea = new ScrollArea(mTextBox);
+ okButton = new Button("Ok", "ok", this);
+
+ mTextArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mTextArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mTextArea->setOpaque(false);
- int w = textLabel->getWidth() + 20;
- int h = textLabel->getHeight() + 25 + okButton->getHeight();
+ mTextBox->setMinWidth(260);
+ mTextBox->setTextWrapped(msg);
- if (okButton->getWidth() + 10 > w) {
- w = okButton->getWidth() + 10;
+ int numRows = mTextBox->getNumberOfRows();
+
+ if (numRows > 1)
+ {
+ // 15 == height of each line of text (based on font heights)
+ // 14 == row top + bottom graphic pixel heights
+ setContentSize(mTextBox->getMinWidth() + 15, 15 + (numRows * 15));
+ mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5,
+ 3 + (numRows * 14)));
+ }
+ else
+ {
+ int width = getFont()->getWidth(title);
+ if (width < getFont()->getWidth(msg))
+ width = getFont()->getWidth(msg);
+ if (width < okButton->getWidth())
+ width = okButton->getWidth();
+ setContentSize(width + 15, 30 + okButton->getHeight());
+ mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17));
}
- setContentSize(w, h);
- textLabel->setPosition(10, 10);
- okButton->setPosition((w - okButton->getWidth()) / 2,
- h - 5 - okButton->getHeight());
+ okButton->setPosition((mTextBox->getMinWidth() - okButton->getWidth()) / 2,
+ (numRows * 14) + okButton->getHeight() - 8);
- add(textLabel);
+ add(mTextArea);
add(okButton);
setLocationRelativeTo(getParent());
@@ -55,6 +76,11 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
okButton->requestFocus();
}
+unsigned int OkDialog::getNumRows()
+{
+ return mTextBox->getNumberOfRows();
+}
+
void OkDialog::action(const gcn::ActionEvent &event)
{
// Proxy button events to our listeners
diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h
index 47a0c780..426da538 100644
--- a/src/gui/ok_dialog.h
+++ b/src/gui/ok_dialog.h
@@ -26,6 +26,9 @@
#include <guichan/actionlistener.hpp>
+#include "button.h"
+#include "scrollarea.h"
+#include "textbox.h"
#include "window.h"
#include "../guichanfwd.h"
@@ -45,10 +48,17 @@ class OkDialog : public Window, public gcn::ActionListener {
OkDialog(const std::string &title, const std::string &msg,
Window *parent = NULL);
+ unsigned int getNumRows();
+
/**
* Called when receiving actions from the widgets.
*/
void action(const gcn::ActionEvent &event);
+
+ private:
+ TextBox *mTextBox;
+ ScrollArea *mTextArea;
+ gcn::Button *okButton;
};
#endif