summaryrefslogtreecommitdiff
path: root/src/gui/confirm_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/confirm_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/confirm_dialog.cpp')
-rw-r--r--src/gui/confirm_dialog.cpp53
1 files changed, 22 insertions, 31 deletions
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index f4b49251..4c08eb73 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -48,47 +48,38 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
mTextBox->setTextWrapped(msg, 260);
- int numRows = mTextBox->getNumberOfRows();
- int width = getFont()->getWidth(title);
- int inWidth = yesButton->getWidth() + noButton->getWidth() + 5;
+ const int numRows = mTextBox->getNumberOfRows();
+ const int inWidth = yesButton->getWidth() + noButton->getWidth() +
+ (2 * getPadding());
const int fontHeight = getFont()->getHeight();
+ const int height = numRows * fontHeight;
+ int width = getFont()->getWidth(title);
- if (numRows > 1)
- {
- // fontHeight == height of each line of text (based on font heights)
- // 14 == row top + bottom graphic pixel heights
- setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) *
- fontHeight) + noButton->getHeight());
- mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5,
- 3 + (numRows * fontHeight)));
- }
- else
- {
- if (width < getFont()->getWidth(msg))
- width = getFont()->getWidth(msg);
- if (width < inWidth)
- width = inWidth;
- setContentSize(width + fontHeight, (2 * fontHeight) +
- noButton->getHeight());
- mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17));
- }
+ if (width < mTextBox->getMinWidth())
+ width = mTextBox->getMinWidth();
+ if (width < inWidth)
+ width = inWidth;
- yesButton->setPosition(
- (mTextBox->getMinWidth() - inWidth) / 2,
- ((numRows - 1) * fontHeight) + noButton->getHeight() + 2);
- noButton->setPosition(
- yesButton->getX() + yesButton->getWidth() + 5,
- ((numRows - 1) * fontHeight) + noButton->getHeight() + 2);
+ setContentSize(mTextBox->getMinWidth() + fontHeight, height + fontHeight +
+ noButton->getHeight());
+ mTextArea->setDimension(gcn::Rectangle(4, 5, width + 2 * getPadding(),
+ height + getPadding()));
+
+ // 8 is the padding that GUIChan adds to button widgets
+ // (top and bottom combined)
+ yesButton->setPosition((width - inWidth) / 2, height + 8);
+ noButton->setPosition(yesButton->getX() + inWidth - noButton->getWidth(),
+ height + 8);
add(mTextArea);
add(yesButton);
add(noButton);
+ setLocationRelativeTo(getParent());
+
if (getParent())
- {
- setLocationRelativeTo(getParent());
getParent()->moveToTop(this);
- }
+
setVisible(true);
yesButton->requestFocus();
}