summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-27 15:54:25 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-28 09:34:21 +0100
commit474442f1a49d29d85de769c4fbb3aa8636877b49 (patch)
tree2d8218d3648f370d31009831c86fc4c6b9f30033
parentdac3832265fa17de8d3b9d3ea8d930b83efe9c17 (diff)
downloadmana-474442f1a49d29d85de769c4fbb3aa8636877b49.tar.gz
mana-474442f1a49d29d85de769c4fbb3aa8636877b49.tar.bz2
mana-474442f1a49d29d85de769c4fbb3aa8636877b49.tar.xz
mana-474442f1a49d29d85de769c4fbb3aa8636877b49.zip
Fixed size and child positions for various popups
Most prominently, fixes the tooltips on the window buttons being clipped due to their position being slightly outside of the clipping children area. And fixes NPC tooltips from having a lot of empty space below the NPC name. Also reduced the space between texts in the item tooltip to match the padding rather than being an entire empty line.
-rw-r--r--src/gui/beingpopup.cpp23
-rw-r--r--src/gui/emotepopup.cpp4
-rw-r--r--src/gui/itempopup.cpp49
-rw-r--r--src/gui/itempopup.h2
-rw-r--r--src/gui/popupmenu.cpp3
-rw-r--r--src/gui/socialwindow.cpp7
-rw-r--r--src/gui/speechbubble.cpp24
-rw-r--r--src/gui/textpopup.cpp26
-rw-r--r--src/gui/textpopup.h10
-rw-r--r--src/gui/widgets/popup.cpp9
10 files changed, 66 insertions, 91 deletions
diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp
index 9cb585db..c11937e9 100644
--- a/src/gui/beingpopup.cpp
+++ b/src/gui/beingpopup.cpp
@@ -21,11 +21,8 @@
#include "gui/beingpopup.h"
#include "being.h"
-#include "graphics.h"
-#include "units.h"
#include "gui/gui.h"
-#include "gui/palette.h"
#include "gui/widgets/label.h"
@@ -38,16 +35,19 @@
BeingPopup::BeingPopup():
Popup("BeingPopup")
{
+ setMinWidth(0);
+ setMinHeight(0);
+
+ const int fontHeight = getFont()->getHeight();
+
// Being Name
mBeingName = new Label("A");
mBeingName->setFont(boldFont);
- mBeingName->setPosition(getPadding(), getPadding());
-
- const int fontHeight = mBeingName->getHeight() + getPadding();
+ mBeingName->setPosition(0, 0);
// Being's party
mBeingParty = new Label("A");
- mBeingParty->setPosition(getPadding(), fontHeight);
+ mBeingParty->setPosition(0, fontHeight);
add(mBeingName);
add(mBeingParty);
@@ -67,7 +67,7 @@ void BeingPopup::show(int x, int y, Being *b)
mBeingName->adjustSize();
int minWidth = mBeingName->getWidth();
- const int height = getFont()->getHeight();
+ const int fontHeight = getFont()->getHeight();
if (!(b->getPartyName().empty()))
{
@@ -75,15 +75,14 @@ void BeingPopup::show(int x, int y, Being *b)
b->getPartyName().c_str()));
mBeingParty->adjustSize();
- if (minWidth < mBeingParty->getWidth())
- minWidth = mBeingParty->getWidth();
+ minWidth = std::max(minWidth, mBeingParty->getWidth());
- setContentSize(minWidth + 10, (height * 2) + 10);
+ setContentSize(minWidth, (fontHeight * 2));
}
else
{
mBeingParty->setCaption(std::string());
- setContentSize(minWidth + 10, height + 10);
+ setContentSize(minWidth, fontHeight);
}
position(x, y);
diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp
index b732705e..8a85aca3 100644
--- a/src/gui/emotepopup.cpp
+++ b/src/gui/emotepopup.cpp
@@ -69,8 +69,8 @@ void EmotePopup::draw(gcn::Graphics *graphics)
int row = i / mColumnCount;
int column = i % mColumnCount;
- int emoteX = 4 + column * gridWidth;
- int emoteY = 4 + row * gridHeight;
+ int emoteX = getPadding() + column * gridWidth;
+ int emoteY = getPadding() + row * gridHeight;
// Center the last row when there are less emotes than columns
if (row == mRowCount - 1)
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 7790a3c0..f552a570 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -83,6 +83,8 @@ static const gcn::Color &getColorFromItemType(ItemType type)
ItemPopup::ItemPopup():
Popup("ItemPopup")
{
+ setMinHeight(boldFont->getHeight());
+
// Item Name
mItemName = new Label;
mItemName->setFont(boldFont);
@@ -141,12 +143,12 @@ void ItemPopup::setNoItem()
mItemName->adjustSize();
mItemName->setForegroundColor(Theme::getThemeColor(Theme::GENERIC));
- mItemName->setPosition(getPadding(), getPadding());
+ mItemName->setPosition(0, 0);
mItemDesc->setText(std::string());
mItemEffect->setText(std::string());
- setContentSize(mItemName->getWidth() + 2 * getPadding(), 0);
+ setContentSize(mItemName->getWidth(), mItemName->getHeight());
}
void ItemPopup::setItem(const ItemInfo &item, bool showImage)
@@ -170,9 +172,7 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
mIcon->setImage(image);
if (image)
{
- int x = getPadding();
- int y = getPadding();
- mIcon->setPosition(x, y);
+ mIcon->setPosition(0, 0);
space = mIcon->getWidth();
}
}
@@ -190,7 +190,7 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
mItemName->setCaption(caption);
mItemName->adjustSize();
mItemName->setForegroundColor(getColorFromItemType(mItemType));
- mItemName->setPosition(getPadding() + space, getPadding());
+ mItemName->setPosition(space, 0);
mItemDesc->setTextWrapped(item.getDescription(), ITEMPOPUP_WRAP_WIDTH);
mItemEffect->setTextWrapped(join(item.getEffect(), "\n"), ITEMPOPUP_WRAP_WIDTH);
@@ -207,40 +207,30 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
if (mItemWeight->getMinWidth() > minWidth)
minWidth = mItemWeight->getMinWidth();
- minWidth += 8;
- setWidth(minWidth);
+ const int descHeight = mItemDesc->getHeight();
+ const int effectHeight = mItemEffect->getHeight();
+ const int weightHeight = mItemWeight->getHeight();
- const int numRowsDesc = mItemDesc->getNumberOfRows();
- const int numRowsEffect = mItemEffect->getNumberOfRows();
- const int numRowsWeight = mItemWeight->getNumberOfRows();
- const int fontHeight = getFont()->getHeight();
-
- int nameHeight;
- if (mIcon->getHeight() > 2 * fontHeight)
- nameHeight = mIcon->getHeight();
- else
- nameHeight = 2 * fontHeight;
+ int nameHeight = std::max(mItemName->getHeight(), mIcon->getHeight());
+ nameHeight += getPadding();
if (item.getEffect().empty())
{
- setContentSize(minWidth, nameHeight +
- (numRowsDesc + numRowsWeight + 1) * fontHeight);
+ setContentSize(minWidth, nameHeight + descHeight + weightHeight + getPadding());
- mItemWeight->setPosition(getPadding(),
- nameHeight + (numRowsDesc + 1) * fontHeight);
+ mItemWeight->setPosition(0, nameHeight + descHeight + getPadding());
}
else
{
- setContentSize(minWidth, nameHeight + (numRowsDesc + numRowsEffect +
- numRowsWeight + 1) * fontHeight);
+ setContentSize(minWidth, nameHeight + descHeight + effectHeight +
+ weightHeight + getPadding());
- mItemWeight->setPosition(getPadding(), nameHeight + (numRowsDesc +
- numRowsEffect + 1) * fontHeight);
+ mItemWeight->setPosition(0, nameHeight + descHeight + effectHeight +
+ getPadding());
}
- mItemDesc->setPosition(getPadding(), nameHeight);
- mItemEffect->setPosition(getPadding(), nameHeight +
- (numRowsDesc + 1) * fontHeight);
+ mItemDesc->setPosition(0, nameHeight);
+ mItemEffect->setPosition(0, nameHeight + descHeight + getPadding());
}
void ItemPopup::mouseMoved(gcn::MouseEvent &event)
@@ -251,4 +241,3 @@ void ItemPopup::mouseMoved(gcn::MouseEvent &event)
setVisible(false);
mItemEquipSlot.clear();
}
-
diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h
index 39270ba1..3b213633 100644
--- a/src/gui/itempopup.h
+++ b/src/gui/itempopup.h
@@ -72,7 +72,7 @@ class ItemPopup : public Popup
TextBox *mItemWeight;
std::string mItemEquipSlot;
ItemType mItemType;
- Icon *mIcon = nullptr;
+ Icon *mIcon;
};
#endif // ITEMPOPUP_H
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index dec3faf9..3c91a273 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -58,7 +58,6 @@ PopupMenu::PopupMenu():
Popup("PopupMenu")
{
mBrowserBox = new BrowserBox;
- mBrowserBox->setPosition(4, 4);
mBrowserBox->setHighlightMode(BrowserBox::BACKGROUND);
mBrowserBox->setLinkHandler(this);
add(mBrowserBox);
@@ -399,7 +398,7 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
void PopupMenu::showPopup(int x, int y)
{
- setContentSize(mBrowserBox->getWidth() + 8, mBrowserBox->getHeight() + 8);
+ setContentSize(mBrowserBox->getWidth(), mBrowserBox->getHeight());
if (graphics->getWidth() < (x + getWidth() + 5))
x = graphics->getWidth() - getWidth();
if (graphics->getHeight() < (y + getHeight() + 5))
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index 00211e02..9ba64e9f 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -240,10 +240,9 @@ class CreatePopup : public Popup, public LinkHandler
{
public:
CreatePopup():
- Popup("SocialCreatePopup")
+ Popup("SocialCreatePopup")
{
mBrowserBox = new BrowserBox;
- mBrowserBox->setPosition(4, 4);
mBrowserBox->setHighlightMode(BrowserBox::BACKGROUND);
mBrowserBox->setLinkHandler(this);
@@ -255,8 +254,8 @@ public:
add(mBrowserBox);
- setContentSize(mBrowserBox->getWidth() + 8,
- mBrowserBox->getHeight() + 8);
+ setContentSize(mBrowserBox->getWidth(),
+ mBrowserBox->getHeight());
}
void handleLink(const std::string &link) override
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index 04740458..58747d57 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -22,8 +22,6 @@
#include "gui/speechbubble.h"
-#include "graphics.h"
-
#include "gui/gui.h"
#include "gui/widgets/label.h"
@@ -36,11 +34,10 @@
#include <guichan/widgets/label.hpp>
SpeechBubble::SpeechBubble():
- Popup("Speech", "speechbubble.xml")
+ Popup("Speech", "speechbubble.xml")
{
- setContentSize(140, 46);
- setMinWidth(29);
- setMinHeight(29);
+ setMinWidth(0);
+ setMinHeight(0);
mCaption = new Label;
mCaption->setFont(boldFont);
@@ -68,26 +65,21 @@ void SpeechBubble::setText(const std::string &text, bool showName)
mSpeechBox->setTextColor(&Theme::getThemeColor(Theme::TEXT));
- int width = mCaption->getWidth() + 2 * getPadding();
+ int width = mCaption->getWidth();
mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width);
- const int speechWidth = mSpeechBox->getMinWidth() + 2 * getPadding();
+ const int speechWidth = mSpeechBox->getMinWidth();
const int fontHeight = getFont()->getHeight();
const int nameHeight = showName ? mCaption->getHeight() +
(getPadding() / 2) : 0;
const int numRows = mSpeechBox->getNumberOfRows();
- const int height = (numRows * fontHeight) + nameHeight + getPadding();
+ const int height = (numRows * fontHeight) + nameHeight;
if (width < speechWidth)
width = speechWidth;
- width += 2 * getPadding();
-
setContentSize(width, height);
- const int xPos = ((getWidth() - width) / 2);
- const int yPos = ((getHeight() - height) / 2) + nameHeight;
-
- mCaption->setPosition(xPos, getPadding());
- mSpeechBox->setPosition(xPos, yPos);
+ mCaption->setPosition(0, 0);
+ mSpeechBox->setPosition(0, nameHeight);
}
diff --git a/src/gui/textpopup.cpp b/src/gui/textpopup.cpp
index 4e8272d6..dbb5bc1f 100644
--- a/src/gui/textpopup.cpp
+++ b/src/gui/textpopup.cpp
@@ -35,37 +35,37 @@
TextPopup::TextPopup():
Popup("TextPopup")
{
+ setMinWidth(0);
+ setMinHeight(0);
+
const int fontHeight = getFont()->getHeight();
mText1 = new Label;
- mText1->setPosition(getPadding(), getPadding());
+ mText1->setPosition(0, 0);
mText2 = new Label;
- mText2->setPosition(getPadding(), fontHeight + getPadding());
+ mText2->setPosition(0, fontHeight);
add(mText1);
add(mText2);
addMouseListener(this);
}
-void TextPopup::show(int x, int y, const std::string &str1, const std::string &str2)
+void TextPopup::show(int x, int y,
+ const std::string &str1,
+ const std::string &str2)
{
mText1->setCaption(str1);
mText1->adjustSize();
mText2->setCaption(str2);
mText2->adjustSize();
- int minWidth = mText1->getWidth();
- if (mText2->getWidth() > minWidth)
- minWidth = mText2->getWidth();
-
- minWidth += 4 * getPadding();
- setWidth(minWidth);
-
+ int width = std::max(mText1->getWidth(), mText2->getWidth());
+ int height = mText1->getHeight();
if (!str2.empty())
- setHeight((getPadding() + mText1->getFont()->getHeight()) * 2);
- else
- setHeight(2 * getPadding() + mText1->getFont()->getHeight());
+ height += mText2->getHeight();
+
+ setContentSize(width, height);
const int distance = 20;
diff --git a/src/gui/textpopup.h b/src/gui/textpopup.h
index b12d4475..b1c6b2b3 100644
--- a/src/gui/textpopup.h
+++ b/src/gui/textpopup.h
@@ -41,13 +41,9 @@ class TextPopup : public Popup
/**
* Sets the text to be displayed.
*/
- void show(int x, int y, const std::string &str1)
- { show(x, y, str1, (const char*)""); }
-
- /**
- * Sets the text to be displayed.
- */
- void show(int x, int y, const std::string &str1, const std::string &str2);
+ void show(int x, int y,
+ const std::string &str1,
+ const std::string &str2 = std::string());
void mouseMoved(gcn::MouseEvent &mouseEvent) override;
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index b79f1370..94d8cf85 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -43,7 +43,7 @@ Popup::Popup(const std::string &name, const std::string &skin):
if (!windowContainer)
throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set");
- setPadding(3);
+ setPadding(6);
// Loads the skin
mSkin = Theme::instance()->load(skin);
@@ -78,7 +78,8 @@ void Popup::draw(gcn::Graphics *graphics)
gcn::Rectangle Popup::getChildrenArea()
{
- return gcn::Rectangle(getPadding(), 0, getWidth() - getPadding() * 2,
+ return gcn::Rectangle(getPadding(), getPadding(),
+ getWidth() - getPadding() * 2,
getHeight() - getPadding() * 2);
}
@@ -115,12 +116,12 @@ void Popup::setLocationRelativeTo(gcn::Widget *widget)
void Popup::setMinWidth(int width)
{
- mMinWidth = width > mSkin->getMinWidth() ? width : mSkin->getMinWidth();
+ mMinWidth = std::max(width, mSkin->getMinWidth());
}
void Popup::setMinHeight(int height)
{
- mMinHeight = height > mSkin->getMinHeight() ? height : mSkin->getMinHeight();
+ mMinHeight = std::max(height, mSkin->getMinHeight());
}
void Popup::setMaxWidth(int width)