summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/equipmentwindow.cpp58
-rw-r--r--src/gui/equipmentwindow.h10
-rw-r--r--src/gui/widgets/window.cpp8
-rw-r--r--src/gui/widgets/window.h8
4 files changed, 55 insertions, 29 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 17c243734..3fa5f68cf 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -65,7 +65,11 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment,
mBorderColor(getThemeColor(Theme::BORDER)),
mLabelsColor(getThemeColor(Theme::LABEL)),
mItemPadding(getOption("itemPadding")),
- mBoxSize(getOption("boxSize"))
+ mBoxSize(getOption("boxSize")),
+ mMinX(180),
+ mMinY(345),
+ mMaxX(0),
+ mMaxY(0)
{
if (setupWindow)
setupWindow->registerWindowForReset(this);
@@ -86,20 +90,20 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment,
setSaveVisible(true);
setStickyButtonLock(true);
- setDefaultSize(180, 345, ImageRect::CENTER);
-
mBoxes.reserve(BOX_COUNT);
for (int f = 0; f < BOX_COUNT; f ++)
mBoxes.push_back(nullptr);
+ mButtonPadding = getOption("buttonPadding", 5);
+
fillBoxes();
+ recalcSize();
loadWindowState();
const gcn::Rectangle &area = getChildrenArea();
- const int buttonPadding = getOption("buttonPadding", 5);
- mUnequip->setPosition(area.width - mUnequip->getWidth() - buttonPadding,
- area.height - mUnequip->getHeight() - buttonPadding);
+ mUnequip->setPosition(area.width - mUnequip->getWidth() - mButtonPadding,
+ area.height - mUnequip->getHeight() - mButtonPadding);
mUnequip->setEnabled(false);
ImageRect rect;
@@ -369,9 +373,7 @@ void EquipmentWindow::fillBoxes()
for_each_xml_child_node(node, root)
{
- if (xmlNameEqual(node, "window"))
- loadWindow(node);
- else if (xmlNameEqual(node, "playerbox"))
+ if (xmlNameEqual(node, "playerbox"))
loadPlayerBox(node);
else if (xmlNameEqual(node, "slot"))
loadSlot(node, mImageSet);
@@ -379,12 +381,6 @@ void EquipmentWindow::fillBoxes()
delete doc;
}
-void EquipmentWindow::loadWindow(const XmlNodePtr windowNode)
-{
- setDefaultSize(XML::getProperty(windowNode, "width", 180),
- XML::getProperty(windowNode, "height", 345), ImageRect::CENTER);
-}
-
void EquipmentWindow::loadPlayerBox(const XmlNodePtr playerBoxNode)
{
mPlayerBox->setDimension(gcn::Rectangle(
@@ -423,6 +419,14 @@ void EquipmentWindow::loadSlot(const XmlNodePtr slotNode,
{
mBoxes[slot] = new EquipmentBox(x, y, image);
}
+ if (x < mMinX)
+ mMinX = x;
+ if (y < mMinY)
+ mMinY = y;
+ if (x + mBoxSize > mMaxX)
+ mMaxX = x + mBoxSize;
+ if (y + mBoxSize > mMaxY)
+ mMaxY = y + mBoxSize;
}
int EquipmentWindow::parseSlotName(std::string name) const
@@ -508,8 +512,7 @@ void EquipmentWindow::fillDefault()
addBox(12, 129, 123, 5); // ring
}
-void EquipmentWindow::addBox(const int idx, const int x, const int y,
- const int imageIndex)
+void EquipmentWindow::addBox(const int idx, int x, int y, const int imageIndex)
{
Image *image = nullptr;
@@ -519,6 +522,23 @@ void EquipmentWindow::addBox(const int idx, const int x, const int y,
image = mImageSet->get(imageIndex);
}
- mBoxes[idx] = new EquipmentBox(x + getPadding(), y + getTitleBarHeight(),
- image);
+ x += getPadding();
+ y += getTitleBarHeight();
+ mBoxes[idx] = new EquipmentBox(x, y, image);
+
+ if (x < mMinX)
+ mMinX = x;
+ if (y < mMinY)
+ mMinY = y;
+ if (x + mBoxSize > mMaxX)
+ mMaxX = x + mBoxSize;
+ if (y + mBoxSize > mMaxY)
+ mMaxY = y + mBoxSize;
+}
+
+void EquipmentWindow::recalcSize()
+{
+ mMaxX += mMinX;
+ mMaxY += mMinY + mUnequip->getHeight() + mButtonPadding;
+ setDefaultSize(mMaxX, mMaxY, ImageRect::CENTER);
}
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index cb6d5c087..c8cc36fbd 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -101,6 +101,8 @@ class EquipmentWindow final : public Window, public gcn::ActionListener
void mouseMoved(gcn::MouseEvent &event) override;
+ void recalcSize();
+
private:
Item *getItem(const int x, const int y) const;
@@ -110,8 +112,7 @@ class EquipmentWindow final : public Window, public gcn::ActionListener
void fillDefault();
- void addBox(const int idx, const int x, const int y,
- const int imageIndex);
+ void addBox(const int idx, int x, int y, const int imageIndex);
void loadWindow(const XmlNodePtr windowNode);
@@ -140,6 +141,11 @@ class EquipmentWindow final : public Window, public gcn::ActionListener
Image *mSlotHighlightedBackground;
int mItemPadding;
int mBoxSize;
+ int mButtonPadding;
+ int mMinX;
+ int mMinY;
+ int mMaxX;
+ int mMaxY;
};
extern EquipmentWindow *equipmentWindow;
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 3f54ce3cc..9128402ad 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -50,6 +50,10 @@ Window::Window(const std::string &caption, const bool modal,
Widget2(),
gcn::WidgetListener(),
mSkin(nullptr),
+ mDefaultX(0),
+ mDefaultY(0),
+ mDefaultWidth(0),
+ mDefaultHeight(0),
mGrip(nullptr),
mParent(parent),
mLayout(nullptr),
@@ -66,10 +70,6 @@ Window::Window(const std::string &caption, const bool modal,
mMinWinHeight(40),
mMaxWinWidth(mainGraphics->mWidth),
mMaxWinHeight(mainGraphics->mHeight),
- mDefaultX(0),
- mDefaultY(0),
- mDefaultWidth(0),
- mDefaultHeight(0),
mVertexes(new GraphicsVertexes()),
mCaptionOffsetX(7),
mCaptionOffsetY(5),
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index e758a4d99..73cd1c2be 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -428,6 +428,10 @@ class Window : public gcn::Window,
{ return mTitlePadding; }
Skin *mSkin; /**< Skin in use by this window */
+ int mDefaultX; /**< Default window X position */
+ int mDefaultY; /**< Default window Y position */
+ int mDefaultWidth; /**< Default window width */
+ int mDefaultHeight; /**< Default window height */
private:
enum ResizeHandles
@@ -474,10 +478,6 @@ class Window : public gcn::Window,
int mMinWinHeight; /**< Minimum window height */
int mMaxWinWidth; /**< Maximum window width */
int mMaxWinHeight; /**< Maximum window height */
- int mDefaultX; /**< Default window X position */
- int mDefaultY; /**< Default window Y position */
- int mDefaultWidth; /**< Default window width */
- int mDefaultHeight; /**< Default window height */
static int mouseResize; /**< Active resize handles */
static int instances; /**< Number of Window instances */