summaryrefslogtreecommitdiff
path: root/src/gui/itemcontainer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/itemcontainer.h')
-rw-r--r--src/gui/itemcontainer.h71
1 files changed, 58 insertions, 13 deletions
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index 8c548fcd..38dc9f6e 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -24,7 +24,9 @@
#ifndef _TMW_ITEMCONTAINER_H__
#define _TMW_ITEMCONTAINER_H__
+#include <guichan/keylistener.hpp>
#include <guichan/mouselistener.hpp>
+
#include <guichan/widget.hpp>
#include <list>
@@ -39,13 +41,18 @@ class SelectionListener;
*
* \ingroup GUI
*/
-class ItemContainer : public gcn::Widget, public gcn::MouseListener
+class ItemContainer : public gcn::Widget,
+ public gcn::KeyListener,
+ public gcn::MouseListener
{
public:
/**
* Constructor. Initializes the graphic.
+ * @param inventory
+ * @param gridColumns Amount of columns in grid.
+ * @param gridRows Amount of rows in grid.
*/
- ItemContainer(Inventory *inventory);
+ ItemContainer(Inventory *inventory, int gridColumns, int gridRows);
/**
* Destructor.
@@ -53,20 +60,19 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
virtual ~ItemContainer();
/**
- * Handles the logic of the ItemContainer
+ * Draws the items.
*/
- void logic();
+ void draw(gcn::Graphics *graphics);
/**
- * Draws the items.
+ * Handles the key presses.
*/
- void draw(gcn::Graphics *graphics);
+ void keyPressed(gcn::KeyEvent &event);
/**
- * Sets the width of the container. This is used to determine the new
- * height of the container.
+ * Handles the key releases.
*/
- void setWidth(int width);
+ void keyReleased(gcn::KeyEvent &event);
/**
* Handles mouse click.
@@ -74,9 +80,20 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
void mousePressed(gcn::MouseEvent &event);
/**
+ * Handles mouse dragged.
+ */
+ void mouseDragged(gcn::MouseEvent &event);
+
+ /**
+ * Handles mouse released.
+ */
+ void mouseReleased(gcn::MouseEvent &event);
+
+ /**
* Returns the selected item.
*/
- Item* getItem();
+ Item* getItem() const
+ { return mSelectedItem; }
/**
* Sets selected item to NULL.
@@ -101,8 +118,26 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
mListeners.remove(listener);
}
+ enum {
+ MOVE_SELECTED_LEFT, // 0
+ MOVE_SELECTED_RIGHT, // 1
+ MOVE_SELECTED_UP, // 2
+ MOVE_SELECTED_DOWN // 3
+ };
private:
/**
+ * Execute all the functionality associated with the action key.
+ */
+ void keyAction();
+
+ /**
+ * Moves the highlight in the direction specified.
+ *
+ * @param direction The move direction of the highlighter.
+ */
+ void moveHighlight(int direction);
+
+ /**
* Sets the currently selected item.
*/
void setSelectedItem(Item *item);
@@ -112,11 +147,21 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
*/
void fireSelectionChangedEvent();
+ /**
+ * Gets the slot index based on the cursor position.
+ *
+ * @param posX The X Coordinate position.
+ * @param posY The Y Coordinate position.
+ * @return The slot index on success, -1 on failure.
+ */
+ int getSlotIndex(const int posX, const int posY) const;
+
Inventory *mInventory;
+ int mGridColumns, mGridRows;
Image *mSelImg;
- Item *mSelectedItem;
-
- int mMaxItems;
+ Item *mSelectedItem, *mHighlightedItem;
+ bool mDragged, mSwapItems;
+ int mDragPosX, mDragPosY;
std::list<SelectionListener*> mListeners;
};