summaryrefslogtreecommitdiff
path: root/src/gui/itemcontainer.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-03-05 23:13:55 -0700
committerIra Rice <irarice@gmail.com>2009-03-05 23:13:55 -0700
commitaa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5 (patch)
tree19c5a75a766b7df51ae468fb6b8fdbcfd2c6cc72 /src/gui/itemcontainer.cpp
parent93e45964f3b7a0735984616f622ec32b40a21781 (diff)
downloadmana-aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5.tar.gz
mana-aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5.tar.bz2
mana-aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5.tar.xz
mana-aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5.zip
Made some optimizations based on some profiling done by Octalot, as well
as some other optimizations that I could see that cut down on some unneeded redraws, which in turn improved frame rates slightly. Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/itemcontainer.cpp')
-rw-r--r--src/gui/itemcontainer.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 79aeb227..02d6e66d 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -20,13 +20,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <SDL_mouse.h>
-
#include <guichan/mouseinput.hpp>
#include <guichan/selectionlistener.hpp>
#include "itemcontainer.h"
#include "itempopup.h"
+#include "viewport.h"
#include "../graphics.h"
#include "../inventory.h"
@@ -72,6 +71,9 @@ ItemContainer::~ItemContainer()
void ItemContainer::logic()
{
+ if (!isVisible())
+ return;
+
gcn::Widget::logic();
int i = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2
@@ -85,18 +87,19 @@ void ItemContainer::logic()
void ItemContainer::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
int columns = getWidth() / gridWidth;
// Have at least 1 column
if (columns < 1)
- {
columns = 1;
- }
/*
- * mOffset is used to compensate for some weirdness that eAthena inherited from
- * Ragnarok Online. Inventory slots and cart slots are +2 from their actual index,
- * while storage slots are +1.
+ * mOffset is used to compensate for some weirdness that eAthena inherited
+ * from Ragnarok Online. Inventory slots and cart slots are +2 from their
+ * actual index, while storage slots are +1.
*/
for (int i = mOffset; i < mInventory->getSize(); i++)
{
@@ -105,31 +108,25 @@ void ItemContainer::draw(gcn::Graphics *graphics)
if (!item || item->getQuantity() <= 0)
continue;
- int itemX = ((i - 2) % columns) * gridWidth;
- int itemY = ((i - 2) / columns) * gridHeight;
+ int itemX = ((i - mOffset) % columns) * gridWidth;
+ int itemY = ((i - mOffset) / columns) * gridHeight;
// Draw selection image below selected item
if (mSelectedItemIndex == i)
- {
- static_cast<Graphics*>(graphics)->drawImage(
- mSelImg, itemX, itemY);
- }
+ static_cast<Graphics*>(graphics)->drawImage(mSelImg, itemX, itemY);
// Draw item icon
Image* image = item->getImage();
+
if (image)
- {
- static_cast<Graphics*>(graphics)->drawImage(
- image, itemX, itemY);
- }
+ static_cast<Graphics*>(graphics)->drawImage(image, itemX, itemY);
// Draw item caption
graphics->setFont(getFont());
graphics->setColor(0x000000);
graphics->drawText(
(item->isEquipped() ? "Eq." : toString(item->getQuantity())),
- itemX + gridWidth / 2,
- itemY + gridHeight - 11,
+ itemX + gridWidth / 2, itemY + gridHeight - 11,
gcn::Graphics::CENTER);
}
}
@@ -258,12 +255,9 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event)
if (item)
{
- int mouseX, mouseY;
- SDL_GetMouseState(&mouseX, &mouseY);
-
mItemPopup->setItem(item->getInfo());
mItemPopup->setOpaque(false);
- mItemPopup->view(mouseX, mouseY);
+ mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
}
else
{