From 987120463333c3e412927e49234173de0b894490 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 11 Jan 2011 03:06:38 +0200 Subject: Fix drawing inventory and selecting items. --- src/gui/widgets/itemcontainer.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 3f6a6b45c..0ba676fe5 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -140,7 +140,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) Image *image = item->getImage(); if (image) { - if (itemIndex == mSelectedIndex) + if (mShowMatrix[itemIndex] == mSelectedIndex) { if (mSelectionStatus == SEL_DRAGGING) { @@ -401,18 +401,18 @@ void ItemContainer::adjustHeight() void ItemContainer::updateMatrix() { - delete mShowMatrix; + delete []mShowMatrix; mShowMatrix = new int[mGridRows * mGridColumns]; - memset(mShowMatrix, -1, mGridRows * mGridColumns); int i = 0; int j = 0; for (int idx = 0; idx < mInventory->getSize(); idx ++) { -// int itemX = i * BOX_WIDTH; -// int itemY = j * BOX_HEIGHT; int itemIndex = idx; + if (j >= mGridRows) + break; + Item *item = mInventory->getItem(itemIndex); if (!item || item->getId() == 0 || !item->isHaveTag(mTag)) @@ -426,15 +426,20 @@ void ItemContainer::updateMatrix() i = 0; j ++; } - if (j >= mGridRows) - break; } + + for (int idx = j * mGridColumns + i; idx < mGridRows * mGridColumns; idx ++) + mShowMatrix[idx] = -1; } int ItemContainer::getSlotIndex(int x, int y) const { if (x < getWidth() && y < getHeight()) - return (y / BOX_HEIGHT) * mGridColumns + (x / BOX_WIDTH); + { + int idx = (y / BOX_HEIGHT) * mGridColumns + (x / BOX_WIDTH); + if (idx < mGridRows * mGridColumns && mShowMatrix[idx] >= 0) + return mShowMatrix[idx]; + } return Inventory::NO_SLOT_INDEX; } -- cgit v1.2.3-70-g09d2