summaryrefslogtreecommitdiff
path: root/src/gui/itemcontainer.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-12 21:29:28 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-12 21:30:49 +0200
commit38c827f67ba233ee11a964eff76714bbbedce4e9 (patch)
treecc3cebfb2bab3ccc552704ce0fe8347354b82388 /src/gui/itemcontainer.cpp
parent0257eaf4d3945eac7cb3e50ccf8dfef18fa29698 (diff)
downloadMana-38c827f67ba233ee11a964eff76714bbbedce4e9.tar.gz
Mana-38c827f67ba233ee11a964eff76714bbbedce4e9.tar.bz2
Mana-38c827f67ba233ee11a964eff76714bbbedce4e9.tar.xz
Mana-38c827f67ba233ee11a964eff76714bbbedce4e9.zip
Only scroll down the inventory as far as necessary
ItemContainer now adjusts its number of rows to the last used slot.
Diffstat (limited to 'src/gui/itemcontainer.cpp')
-rw-r--r--src/gui/itemcontainer.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 6cbdabb2..26382cd2 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -57,6 +57,7 @@ ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
mGridRows(1),
mSelectedIndex(-1),
mHighlightedIndex(-1),
+ mLastUsedSlot(-1),
mSelectionStatus(SEL_NONE),
mForceQuantity(forceQuantity),
mSwapItems(false),
@@ -82,6 +83,19 @@ ItemContainer::~ItemContainer()
delete mItemPopup;
}
+void ItemContainer::logic()
+{
+ gcn::Widget::logic();
+
+ const int lastUsedSlot = mInventory->getLastUsedSlot();
+
+ if (lastUsedSlot != mLastUsedSlot)
+ {
+ mLastUsedSlot = lastUsedSlot;
+ adjustHeight();
+ }
+}
+
void ItemContainer::draw(gcn::Graphics *graphics)
{
Graphics *g = static_cast<Graphics*>(graphics);
@@ -316,8 +330,13 @@ void ItemContainer::mouseExited(gcn::MouseEvent &event)
void ItemContainer::widgetResized(const gcn::Event &event)
{
mGridColumns = std::max(1, getWidth() / BOX_WIDTH);
- mGridRows = mInventory->getSize() / mGridColumns;
- if (mGridRows == 0 || mInventory->getSize() % mGridColumns > 0)
+ adjustHeight();
+}
+
+void ItemContainer::adjustHeight()
+{
+ mGridRows = (mLastUsedSlot + 1) / mGridColumns;
+ if (mGridRows == 0 || (mLastUsedSlot + 1) % mGridColumns > 0)
++mGridRows;
setHeight(mGridRows * BOX_HEIGHT);