summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/confirm_dialog.cpp6
-rw-r--r--src/gui/itempopup.cpp41
-rw-r--r--src/gui/npc_text.cpp14
-rw-r--r--src/gui/ok_dialog.cpp3
-rw-r--r--src/gui/speechbubble.cpp5
-rw-r--r--src/gui/textbox.cpp6
-rw-r--r--src/gui/textbox.h7
7 files changed, 33 insertions, 49 deletions
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index 569fd93f..643d5d7a 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -41,8 +41,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
mTextArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mTextArea->setOpaque(false);
- mTextBox->setMinWidth(260);
- mTextBox->setTextWrapped(msg);
+ mTextBox->setTextWrapped(msg, 260);
int numRows = mTextBox->getNumberOfRows();
int width = getFont()->getWidth(title);
@@ -77,7 +76,8 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
add(yesButton);
add(noButton);
- if (getParent()) {
+ if (getParent())
+ {
setLocationRelativeTo(getParent());
getParent()->moveToTop(this);
}
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 8235d640..1256275d 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -55,8 +55,6 @@ ItemPopup::ItemPopup():
// Item Description
mItemDesc = new TextBox();
mItemDesc->setEditable(false);
- mItemDesc->setMinWidth(186);
- mItemDesc->setTextWrapped("");
mItemDescScroll = new ScrollArea(mItemDesc);
mItemDescScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -68,8 +66,6 @@ ItemPopup::ItemPopup():
// Item Effect
mItemEffect = new TextBox();
mItemEffect->setEditable(false);
- mItemEffect->setMinWidth(186);
- mItemEffect->setTextWrapped("");
mItemEffectScroll = new ScrollArea(mItemEffect);
mItemEffectScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -81,8 +77,6 @@ ItemPopup::ItemPopup():
// Item Weight
mItemWeight = new TextBox();
mItemWeight->setEditable(false);
- mItemWeight->setMinWidth(186);
- mItemWeight->setTextWrapped("");
mItemWeightScroll = new ScrollArea(mItemWeight);
mItemWeightScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -104,35 +98,40 @@ ItemPopup::ItemPopup():
void ItemPopup::setItem(const ItemInfo &item)
{
- const gcn::Rectangle &area = getChildrenArea();
- const int width = area.width;
-
- mItemDesc->setMinWidth(width - 10);
- mItemEffect->setMinWidth(width - 10);
- mItemWeight->setMinWidth(width - 10);
-
mItemName->setCaption(item.getName());
- mItemDesc->setTextWrapped(item.getDescription());
- mItemEffect->setTextWrapped(item.getEffect());
+ mItemDesc->setTextWrapped(item.getDescription(), 196);
+ mItemEffect->setTextWrapped(item.getEffect(), 196);
mItemWeight->setTextWrapped(_("Weight: ") + toString(item.getWeight()) +
- _(" grams"));
+ _(" grams"), 196);
+
+ int minWidth = mItemName->getWidth();
+
+ if (mItemDesc->getMinWidth() > minWidth)
+ minWidth = mItemDesc->getMinWidth();
+ if (mItemEffect->getMinWidth() > minWidth)
+ minWidth = mItemEffect->getMinWidth();
+ if (mItemWeight->getMinWidth() > minWidth)
+ minWidth = mItemWeight->getMinWidth();
+
+ minWidth += 8;
+ setWidth(minWidth);
int numRowsDesc = mItemDesc->getNumberOfRows();
int numRowsEffect = mItemEffect->getNumberOfRows();
int numRowsWeight = mItemWeight->getNumberOfRows();
- mItemDescScroll->setDimension(gcn::Rectangle(2, 0, 196,
+ mItemDescScroll->setDimension(gcn::Rectangle(2, 0, minWidth,
numRowsDesc * getFont()->getHeight()));
- mItemEffectScroll->setDimension(gcn::Rectangle(2, 0, 196,
+ mItemEffectScroll->setDimension(gcn::Rectangle(2, 0, minWidth,
numRowsEffect * getFont()->getHeight()));
- mItemWeightScroll->setDimension(gcn::Rectangle(2, 0, 196,
+ mItemWeightScroll->setDimension(gcn::Rectangle(2, 0, minWidth,
numRowsWeight * getFont()->getHeight()));
if(item.getEffect() == "")
{
- setContentSize(200, (numRowsDesc * getFont()->getHeight() +
+ setContentSize(minWidth, (numRowsDesc * getFont()->getHeight() +
(3 * getFont()->getHeight())));
mItemWeightScroll->setPosition(2,
@@ -141,7 +140,7 @@ void ItemPopup::setItem(const ItemInfo &item)
}
else
{
- setContentSize(200, (numRowsDesc * getFont()->getHeight()) +
+ setContentSize(minWidth, (numRowsDesc * getFont()->getHeight()) +
(numRowsEffect * getFont()->getHeight()) +
(3 * getFont()->getHeight()));
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index b2256f07..1e29b793 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -64,12 +64,8 @@ NpcTextDialog::NpcTextDialog():
void NpcTextDialog::setText(const std::string &text)
{
- const gcn::Rectangle &area = getChildrenArea();
- const int width = area.width;
-
mText = text;
- mTextBox->setMinWidth(width - 30);
- mTextBox->setTextWrapped(mText);
+ mTextBox->setTextWrapped(mText, scrollArea->getWidth() - 15);
}
void NpcTextDialog::addText(const std::string &text)
@@ -93,12 +89,6 @@ void NpcTextDialog::widgetResized(const gcn::Event &event)
{
Window::widgetResized(event);
- const gcn::Rectangle &area = getChildrenArea();
-
- mTextBox->setMinWidth(area.width - 30);
- mTextBox->setTextWrapped(mText);
-
- // Set the text again so that it gets wrapped according to the new size
- mTextBox->setTextWrapped(mText);
+ setText(mText);
}
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index dc66a900..7f63b152 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -40,8 +40,7 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
mTextArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mTextArea->setOpaque(false);
- mTextBox->setMinWidth(260);
- mTextBox->setTextWrapped(msg);
+ mTextBox->setTextWrapped(msg, 260);
int numRows = mTextBox->getNumberOfRows();
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index a6bb5563..7eedce1c 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -65,8 +65,6 @@ SpeechBubble::SpeechBubble():
// LEEOR / TODO: This causes an exception error.
//moveToBottom(getParent());
-
- mSpeechBox->setTextWrapped( "" );
}
void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color)
@@ -78,8 +76,7 @@ void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color)
void SpeechBubble::setText(std::string mText)
{
- mSpeechBox->setMinWidth(140);
- mSpeechBox->setTextWrapped(mText);
+ mSpeechBox->setTextWrapped(mText, 130);
const int fontHeight = getFont()->getHeight();
const int numRows = mSpeechBox->getNumberOfRows() + 1;
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp
index ee03c79d..fb5a39e6 100644
--- a/src/gui/textbox.cpp
+++ b/src/gui/textbox.cpp
@@ -31,9 +31,10 @@ TextBox::TextBox():
{
setOpaque(false);
setFrameSize(0);
+ mMinWidth = getWidth();
}
-void TextBox::setTextWrapped(const std::string &text)
+void TextBox::setTextWrapped(const std::string &text, int minDimension)
{
// Make sure parent scroll area sets width of this widget
if (getParent())
@@ -41,6 +42,9 @@ void TextBox::setTextWrapped(const std::string &text)
getParent()->logic();
}
+ // Take the supplied minimum dimension as a starting point and try to beat it
+ mMinWidth = minDimension;
+
std::stringstream wrappedStream;
std::string::size_type newlinePos, lastNewlinePos = 0;
int minWidth = 0;
diff --git a/src/gui/textbox.h b/src/gui/textbox.h
index 98b60402..84dd6268 100644
--- a/src/gui/textbox.h
+++ b/src/gui/textbox.h
@@ -43,18 +43,13 @@ class TextBox : public gcn::TextBox {
/**
* Sets the text after wrapping it to the current width of the widget.
*/
- void setTextWrapped(const std::string &text);
+ void setTextWrapped(const std::string &text, int minDimension);
/**
* Get the minimum text width for the text box.
*/
int getMinWidth() { return mMinWidth; }
- /**
- * Set the minimum text width for the text box.
- */
- void setMinWidth(int width) { mMinWidth = width; }
-
private:
int mMinWidth;
};