summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-28 18:29:04 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-28 18:29:04 +0000
commit5943323aff9db6c1405177478564072e9d2214b3 (patch)
tree410aa9db803119f4ae1ee09883591f382390a5b1 /src
parenta59a96dc0f162a48f8cedcc804e9f89af3b1b9d3 (diff)
downloadmana-5943323aff9db6c1405177478564072e9d2214b3.tar.gz
mana-5943323aff9db6c1405177478564072e9d2214b3.tar.bz2
mana-5943323aff9db6c1405177478564072e9d2214b3.tar.xz
mana-5943323aff9db6c1405177478564072e9d2214b3.zip
Properly fix problems with ItemContainer in InventoryWindow not resizing
properly since upgrade to Guichan 0.8.0.
Diffstat (limited to 'src')
-rw-r--r--src/gui/inventorywindow.cpp4
-rw-r--r--src/gui/inventorywindow.h7
-rw-r--r--src/gui/itemcontainer.cpp34
-rw-r--r--src/gui/itemcontainer.h17
-rw-r--r--src/gui/scrollarea.cpp12
-rw-r--r--src/gui/scrollarea.h12
6 files changed, 33 insertions, 53 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index a5460f1d..4172a532 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -96,8 +96,6 @@ void InventoryWindow::logic()
mWeightLabel->setCaption(
"Total Weight: " + toString(player_node->mTotalWeight) + " - "
"Maximum Weight: " + toString(player_node->mMaxWeight));
-
- mItems->setWidth(mInvenScroll->getAdjustedWidth());
}
void InventoryWindow::action(const gcn::ActionEvent &event)
@@ -205,8 +203,6 @@ void InventoryWindow::widgetResized(const gcn::Event &event)
mInvenScroll->setSize(width - 16,
mItemDescriptionLabel->getY() - mWeightLabel->getHeight() - 18);
- mItems->setWidth(mInvenScroll->getAdjustedWidth());
-
mWeightLabel->setWidth(width - 16);
}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index c016f707..3222009f 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -33,7 +33,6 @@
class Item;
class ItemContainer;
-class ScrollArea;
/**
* Inventory dialog.
@@ -59,8 +58,6 @@ class InventoryWindow : public Window, gcn::ActionListener,
*/
void action(const gcn::ActionEvent &event);
- void mouseClicked(gcn::MouseEvent &event);
-
Item* getItem();
/**
@@ -68,6 +65,8 @@ class InventoryWindow : public Window, gcn::ActionListener,
*/
void valueChanged(const gcn::SelectionEvent &event);
+ void mouseClicked(gcn::MouseEvent &event);
+
/**
* Called whenever the widget changes size.
*/
@@ -79,7 +78,7 @@ class InventoryWindow : public Window, gcn::ActionListener,
ItemContainer *mItems;
gcn::Button *mUseButton, *mDropButton;
- ScrollArea *mInvenScroll;
+ gcn::ScrollArea *mInvenScroll;
gcn::Label *mItemNameLabel;
gcn::Label *mItemDescriptionLabel;
gcn::Label *mItemEffectLabel;
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index eb9d66ec..eb8b91a7 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -38,6 +38,9 @@
#include "../utils/tostring.h"
+const int ItemContainer::gridWidth = 36; // item icon width + 4
+const int ItemContainer::gridHeight = 42; // item icon height + 10
+
ItemContainer::ItemContainer(Inventory *inventory):
mInventory(inventory),
mSelectedItem(NULL)
@@ -50,6 +53,7 @@ ItemContainer::ItemContainer(Inventory *inventory):
mMaxItems = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2
addMouseListener(this);
+ addWidgetListener(this);
}
ItemContainer::~ItemContainer()
@@ -67,15 +71,13 @@ ItemContainer::logic()
if (i != mMaxItems)
{
mMaxItems = i;
- setWidth(getWidth());
+ recalculateHeight();
}
}
void
ItemContainer::draw(gcn::Graphics *graphics)
{
- int gridWidth = 36; //(item icon width + 4)
- int gridHeight = 42; //(item icon height + 10)
int columns = getWidth() / gridWidth;
// Have at least 1 column
@@ -130,22 +132,22 @@ ItemContainer::draw(gcn::Graphics *graphics)
}
}
-void
-ItemContainer::setWidth(int width)
+void ItemContainer::widgetResized(const gcn::Event &event)
{
- gcn::Widget::setWidth(width);
+ recalculateHeight();
+}
- int gridWidth = 36; //item icon width + 4
- int gridHeight = 42; //item icon height + 10
- int columns = getWidth() / gridWidth;
+void ItemContainer::recalculateHeight()
+{
+ int cols = getWidth() / gridWidth;
- if (columns < 1)
- {
- columns = 1;
- }
+ if (cols < 1)
+ cols = 1;
- setHeight(4 + ((mMaxItems / columns) +
- (mMaxItems % columns > 0 ? 1 : 0)) * gridHeight);
+ const int rows = (mMaxItems / cols) + (mMaxItems % cols > 0 ? 1 : 0);
+ const int height = rows * gridHeight + 8;
+ if (height != getHeight())
+ setHeight(height);
}
Item*
@@ -190,8 +192,6 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT)
{
- int gridWidth = 36; //(item icon width + 4)
- int gridHeight = 42; //(item icon height + 10)
int columns = getWidth() / gridWidth;
int mx = event.getX();
int my = event.getY();
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index 58b19179..9320cdcf 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -26,6 +26,7 @@
#include <guichan/mouselistener.hpp>
#include <guichan/widget.hpp>
+#include <guichan/widgetlistener.hpp>
#include <list>
@@ -42,7 +43,8 @@ namespace gcn {
*
* \ingroup GUI
*/
-class ItemContainer : public gcn::Widget, public gcn::MouseListener
+class ItemContainer : public gcn::Widget, public gcn::MouseListener,
+ public gcn::WidgetListener
{
public:
/**
@@ -66,10 +68,9 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
void draw(gcn::Graphics *graphics);
/**
- * Sets the width of the container. This is used to determine the new
- * height of the container.
+ * Called whenever the widget changes size.
*/
- void setWidth(int width);
+ void widgetResized(const gcn::Event &event);
/**
* Handles mouse click.
@@ -111,6 +112,11 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
void setSelectedItem(Item *item);
/**
+ * Determine and set the height of the container.
+ */
+ void recalculateHeight();
+
+ /**
* Sends out selection events to the list of selection listeners.
*/
void distributeValueChangedEvent();
@@ -122,6 +128,9 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
int mMaxItems;
std::list<gcn::SelectionListener*> mListeners;
+
+ static const int gridWidth;
+ static const int gridHeight;
};
#endif
diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp
index 21f37510..255aa2d8 100644
--- a/src/gui/scrollarea.cpp
+++ b/src/gui/scrollarea.cpp
@@ -296,15 +296,3 @@ void ScrollArea::drawHMarker(gcn::Graphics *graphics)
static_cast<Graphics*>(graphics)->
drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker);
}
-
-int ScrollArea::getAdjustedWidth() const
-{
- return ScrollArea::getDimension().width -
- (mVBarVisible ? ScrollArea::getScrollbarWidth() : 0);
-}
-
-int ScrollArea::getAdjustedHeight() const
-{
- return ScrollArea::getDimension().height -
- (mHBarVisible ? ScrollArea::getScrollbarWidth() : 0);
-}
diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h
index c714bf1f..be361f68 100644
--- a/src/gui/scrollarea.h
+++ b/src/gui/scrollarea.h
@@ -78,18 +78,6 @@ class ScrollArea : public gcn::ScrollArea
*/
bool isOpaque() const { return mOpaque; }
- /**
- * Return the width of the scrollarea adjusting for visible
- * vertical scrollbar.
- */
- int getAdjustedWidth() const;
-
- /**
- * Return the height of the scrollarea adjusting for visible
- * horizontal scrollbar.
- */
- int getAdjustedHeight() const;
-
protected:
enum BUTTON_DIR {
UP,