summaryrefslogtreecommitdiff
path: root/src/gui/ok_dialog.cpp
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 /src/gui/ok_dialog.cpp
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.
Diffstat (limited to 'src/gui/ok_dialog.cpp')
-rw-r--r--src/gui/ok_dialog.cpp54
1 files changed, 40 insertions, 14 deletions
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