From f883ad28b77a499fa66497158db425ce1db50f78 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Mar 2009 09:55:21 -0600 Subject: 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 --- src/gui/ok_dialog.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/gui/ok_dialog.cpp') 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); -- cgit v1.2.3-70-g09d2