summaryrefslogtreecommitdiff
path: root/src/gui/itemcontainer.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-28 18:29:04 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-28 18:29:04 +0000
commit5943323aff9db6c1405177478564072e9d2214b3 (patch)
tree410aa9db803119f4ae1ee09883591f382390a5b1 /src/gui/itemcontainer.cpp
parenta59a96dc0f162a48f8cedcc804e9f89af3b1b9d3 (diff)
downloadmana-client-5943323aff9db6c1405177478564072e9d2214b3.tar.gz
mana-client-5943323aff9db6c1405177478564072e9d2214b3.tar.bz2
mana-client-5943323aff9db6c1405177478564072e9d2214b3.tar.xz
mana-client-5943323aff9db6c1405177478564072e9d2214b3.zip
Properly fix problems with ItemContainer in InventoryWindow not resizing
properly since upgrade to Guichan 0.8.0.
Diffstat (limited to 'src/gui/itemcontainer.cpp')
-rw-r--r--src/gui/itemcontainer.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index eb9d66ec..eb8b91a7 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -38,6 +38,9 @@
#include "../utils/tostring.h"
+const int ItemContainer::gridWidth = 36; // item icon width + 4
+const int ItemContainer::gridHeight = 42; // item icon height + 10
+
ItemContainer::ItemContainer(Inventory *inventory):
mInventory(inventory),
mSelectedItem(NULL)
@@ -50,6 +53,7 @@ ItemContainer::ItemContainer(Inventory *inventory):
mMaxItems = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2
addMouseListener(this);
+ addWidgetListener(this);
}
ItemContainer::~ItemContainer()
@@ -67,15 +71,13 @@ ItemContainer::logic()
if (i != mMaxItems)
{
mMaxItems = i;
- setWidth(getWidth());
+ recalculateHeight();
}
}
void
ItemContainer::draw(gcn::Graphics *graphics)
{
- int gridWidth = 36; //(item icon width + 4)
- int gridHeight = 42; //(item icon height + 10)
int columns = getWidth() / gridWidth;
// Have at least 1 column
@@ -130,22 +132,22 @@ ItemContainer::draw(gcn::Graphics *graphics)
}
}
-void
-ItemContainer::setWidth(int width)
+void ItemContainer::widgetResized(const gcn::Event &event)
{
- gcn::Widget::setWidth(width);
+ recalculateHeight();
+}
- int gridWidth = 36; //item icon width + 4
- int gridHeight = 42; //item icon height + 10
- int columns = getWidth() / gridWidth;
+void ItemContainer::recalculateHeight()
+{
+ int cols = getWidth() / gridWidth;
- if (columns < 1)
- {
- columns = 1;
- }
+ if (cols < 1)
+ cols = 1;
- setHeight(4 + ((mMaxItems / columns) +
- (mMaxItems % columns > 0 ? 1 : 0)) * gridHeight);
+ const int rows = (mMaxItems / cols) + (mMaxItems % cols > 0 ? 1 : 0);
+ const int height = rows * gridHeight + 8;
+ if (height != getHeight())
+ setHeight(height);
}
Item*
@@ -190,8 +192,6 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT)
{
- int gridWidth = 36; //(item icon width + 4)
- int gridHeight = 42; //(item icon height + 10)
int columns = getWidth() / gridWidth;
int mx = event.getX();
int my = event.getY();