summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2008-10-28 14:31:05 +0000
committerIra Rice <irarice@gmail.com>2008-10-28 14:31:05 +0000
commita5c89d99f3a75bfa0d7a8605f310747772bb690b (patch)
tree4c8936e851305d8d567f24dfeef9f2559fb707b6
parentb00a8da8f954cd8116bd7a5375f70550bdcb9009 (diff)
downloadmana-a5c89d99f3a75bfa0d7a8605f310747772bb690b.tar.gz
mana-a5c89d99f3a75bfa0d7a8605f310747772bb690b.tar.bz2
mana-a5c89d99f3a75bfa0d7a8605f310747772bb690b.tar.xz
mana-a5c89d99f3a75bfa0d7a8605f310747772bb690b.zip
Fixed up confirm dialogues so that they also can utilize the text
wrapping code, like the ok dialogues.
-rw-r--r--src/gui/confirm_dialog.cpp55
-rw-r--r--src/gui/confirm_dialog.h10
-rw-r--r--src/gui/ok_dialog.cpp1
3 files changed, 50 insertions, 16 deletions
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index 5b700831..848c4767 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -23,37 +23,57 @@
#include "confirm_dialog.h"
-#include <guichan/widgets/label.hpp>
-
-#include "button.h"
-
+#include <guichan/font.hpp>
ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
Window *parent):
Window(title, true, parent)
{
- gcn::Label *textLabel = new gcn::Label(msg);
+ mTextBox = new TextBox();
+ mTextBox->setEditable(false);
+ mTextBox->setOpaque(false);
+
+ mTextArea = new ScrollArea(mTextBox);
gcn::Button *yesButton = new Button("Yes", "yes", this);
gcn::Button *noButton = new Button("No", "no", this);
- int w = textLabel->getWidth() + 20;
+ mTextArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mTextArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mTextArea->setOpaque(false);
+
+ mTextBox->setMinWidth(260);
+ mTextBox->setTextWrapped(msg);
+
+ int numRows = mTextBox->getNumberOfRows();
+ int width = getFont()->getWidth(title);
int inWidth = yesButton->getWidth() + noButton->getWidth() + 5;
- int h = textLabel->getHeight() + 25 + yesButton->getHeight();
- if (w < inWidth + 10) {
- w = inWidth + 10;
+ 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) + noButton->getHeight());
+ mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5,
+ 3 + (numRows * 14)));
+ }
+ else
+ {
+ if (width < getFont()->getWidth(msg))
+ width = getFont()->getWidth(msg);
+ if (width < inWidth)
+ width = inWidth;
+ setContentSize(width + 15, 30 + noButton->getHeight());
+ mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17));
}
- setContentSize(w, h);
- textLabel->setPosition(10, 10);
yesButton->setPosition(
- (w - inWidth) / 2,
- h - 5 - noButton->getHeight());
+ (mTextBox->getMinWidth() - inWidth) / 2,
+ (numRows * 14) + noButton->getHeight() - 8);
noButton->setPosition(
yesButton->getX() + yesButton->getWidth() + 5,
- h - 5 - noButton->getHeight());
+ (numRows * 14) + noButton->getHeight() - 8);
- add(textLabel);
+ add(mTextArea);
add(yesButton);
add(noButton);
@@ -65,6 +85,11 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
yesButton->requestFocus();
}
+unsigned int ConfirmDialog::getNumRows()
+{
+ return mTextBox->getNumberOfRows();
+}
+
void ConfirmDialog::action(const gcn::ActionEvent &event)
{
// Proxy button events to our listeners
diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h
index b8e385f6..65f33cac 100644
--- a/src/gui/confirm_dialog.h
+++ b/src/gui/confirm_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 ConfirmDialog : public Window, public gcn::ActionListener {
ConfirmDialog(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
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index 2c7661a1..b8d3c7ba 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -25,7 +25,6 @@
#include <guichan/font.hpp>
-
OkDialog::OkDialog(const std::string &title, const std::string &msg,
Window *parent):
Window(title, true, parent)