summaryrefslogtreecommitdiff
path: root/src/gui/itemcontainer.cpp
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-08-01 08:18:23 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-08-01 08:18:23 +0000
commit1a2dc3de03fee33e8d2a52767424498e2019321e (patch)
treebea722900f87fba80fdf4257c9d026ceca27a388 /src/gui/itemcontainer.cpp
parent15e4760a93edd430053cbad5d638b68593b61bc0 (diff)
downloadmana-1a2dc3de03fee33e8d2a52767424498e2019321e.tar.gz
mana-1a2dc3de03fee33e8d2a52767424498e2019321e.tar.bz2
mana-1a2dc3de03fee33e8d2a52767424498e2019321e.tar.xz
mana-1a2dc3de03fee33e8d2a52767424498e2019321e.zip
Added code to dynamically adjust the itemcontainer size.
Diffstat (limited to 'src/gui/itemcontainer.cpp')
-rw-r--r--src/gui/itemcontainer.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 8fd3a23e..a4e7a7d0 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -41,6 +41,7 @@ ItemContainer::ItemContainer(Inventory *inventory):
if (!selImg) logger->error("Unable to load selection.png");
selectedItem = 0; // No item selected
+ maxItems = inventory->getLastUsedSlot();
addMouseListener(this);
}
@@ -51,6 +52,18 @@ ItemContainer::~ItemContainer()
selImg->decRef();
}
+void ItemContainer::logic()
+{
+ gcn::Widget::logic();
+
+ int i = inventory->getLastUsedSlot();
+
+ if (i != maxItems) {
+ maxItems = i;
+ setWidth(getWidth());
+ }
+}
+
void ItemContainer::draw(gcn::Graphics* graphics)
{
int gridWidth = itemset->spriteset[0]->getWidth() + 4;
@@ -125,7 +138,7 @@ void ItemContainer::setWidth(int width)
gcn::Widget::setWidth(width);
int gridWidth = itemset->spriteset[0]->getWidth() + 4;
- int gridHeight = itemset->spriteset[0]->getHeight() + 10;
+ int gridHeight = itemset->spriteset[0]->getHeight() + 14;
int columns = getWidth() / gridWidth;
if (columns < 1)
@@ -133,8 +146,8 @@ void ItemContainer::setWidth(int width)
columns = 1;
}
- setHeight(((INVENTORY_SIZE / columns) +
- (INVENTORY_SIZE % columns > 0 ? 1 : 0)) * gridHeight);
+ setHeight(((maxItems / columns) +
+ (maxItems % columns > 0 ? 1 : 0)) * gridHeight);
}
Item* ItemContainer::getItem()