summaryrefslogtreecommitdiff
path: root/src/gui/ok_dialog.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-03-26 09:55:21 -0600
committerIra Rice <irarice@gmail.com>2009-03-26 09:55:21 -0600
commitf883ad28b77a499fa66497158db425ce1db50f78 (patch)
tree47156bc38c68130d1fb83f8d83b2543375d17d1a /src/gui/ok_dialog.cpp
parent58eb615a589cd6444092f9c928f26210087aa78b (diff)
downloadmana-client-f883ad28b77a499fa66497158db425ce1db50f78.tar.gz
mana-client-f883ad28b77a499fa66497158db425ce1db50f78.tar.bz2
mana-client-f883ad28b77a499fa66497158db425ce1db50f78.tar.xz
mana-client-f883ad28b77a499fa66497158db425ce1db50f78.zip
Some code cleanups (mostly reducing how many calculations need to be
done in certain statements, rearranging arguements to make them look cleaner, or overall making the code slightly more flexible) Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/ok_dialog.cpp')
-rw-r--r--src/gui/ok_dialog.cpp38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index d3e7bec6..84fa20ea 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -31,7 +31,7 @@
#include "../utils/gettext.h"
OkDialog::OkDialog(const std::string &title, const std::string &msg,
- Window *parent):
+ Window *parent):
Window(title, true, parent)
{
mTextBox = new TextBox();
@@ -47,30 +47,24 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
mTextBox->setTextWrapped(msg, 260);
- int numRows = mTextBox->getNumberOfRows();
+ const int numRows = mTextBox->getNumberOfRows();
const int fontHeight = getFont()->getHeight();
+ const int height = numRows * fontHeight;
+ int width = getFont()->getWidth(title);
- if (numRows > 1)
- {
- // 14 == row top + bottom graphic pixel heights
- setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) *
- fontHeight) + okButton->getHeight());
- mTextArea->setDimension(gcn::Rectangle(4, 5,
- mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight)));
- }
- else
- {
- int width = getFont()->getWidth(title);
- if (width < getFont()->getWidth(msg))
- width = getFont()->getWidth(msg);
- if (width < okButton->getWidth())
- width = okButton->getWidth();
- setContentSize(width + fontHeight, 30 + okButton->getHeight());
- mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17));
- }
+ if (width < mTextBox->getMinWidth())
+ width = mTextBox->getMinWidth();
+ if (width < okButton->getWidth())
+ width = okButton->getWidth();
+
+ setContentSize(mTextBox->getMinWidth() + fontHeight, height +
+ fontHeight + okButton->getHeight());
+ mTextArea->setDimension(gcn::Rectangle(4, 5, width + 2 * getPadding(),
+ height + getPadding()));
- okButton->setPosition((mTextBox->getMinWidth() - okButton->getWidth()) / 2,
- ((numRows - 1) * fontHeight) + okButton->getHeight() + 2);
+ // 8 is the padding that GUIChan adds to button widgets
+ // (top and bottom combined)
+ okButton->setPosition((width - okButton->getWidth()) / 2, height + 8);
add(mTextArea);
add(okButton);