summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-09-20 22:19:45 +0300
committerAndrei Karas <akaras@inbox.ru>2011-09-20 22:19:45 +0300
commit8138d0e61f633546263df94473e91d500ada9c0e (patch)
treecc0f9b2290964c017ad1c0981a429d733a406e3e /src/gui
parent5f2ee9e2f8c8d313de85df08abdc2a7f7396995f (diff)
downloadmv-8138d0e61f633546263df94473e91d500ada9c0e.tar.gz
mv-8138d0e61f633546263df94473e91d500ada9c0e.tar.bz2
mv-8138d0e61f633546263df94473e91d500ada9c0e.tar.xz
mv-8138d0e61f633546263df94473e91d500ada9c0e.zip
Auto hide filter in invetory if window size too small.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/inventorywindow.cpp55
-rw-r--r--src/gui/inventorywindow.h10
-rw-r--r--src/gui/widgets/layout.h29
3 files changed, 74 insertions, 20 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index cd02a6732..35165a16a 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -99,7 +99,8 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
Window("Inventory", false, 0, "inventory.xml"),
mInventory(inventory),
mDropButton(0),
- mSplit(false)
+ mSplit(false),
+ mCompactMode(false)
{
if (inventory)
{
@@ -146,7 +147,6 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
mSortDropDown->setSelected(0);
mFilterLabel = new Label(_("Filter:"));
- mSorterLabel = new Label(_("Sort:"));
mNameFilter = new TextField("", true, this, "namefilter", true);
std::vector<std::string> tags = ItemDB::getTags();
@@ -181,13 +181,12 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
place(0, 0, mWeightLabel, 1).setPadding(3);
place(1, 0, mWeightBar, 3);
place(4, 0, mSlotsLabel, 1).setPadding(3);
- place(5, 0, mSlotsBar, 2);
- place(7, 0, mSorterLabel, 1);
- place(8, 0, mSortDropDown, 3);
+ mSlotsBarCell = &place(5, 0, mSlotsBar, 3);
+ mSortDropDownCell = &place(8, 0, mSortDropDown, 3);
place(0, 1, mFilterLabel, 1).setPadding(3);
- place(1, 1, mFilter, 7).setPadding(3);
- place(8, 1, mNameFilter, 3);
+ mFilterCell = &place(1, 1, mFilter, 8).setPadding(3);
+ mNameFilterCell = &place(8, 1, mNameFilter, 3);
place(0, 2, invenScroll, 11).setPadding(3);
place(0, 3, mUseButton);
@@ -206,13 +205,12 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
mCloseButton = new Button(_("Close"), "close", this);
place(0, 0, mSlotsLabel).setPadding(3);
- place(1, 0, mSlotsBar, 4);
- place(5, 0, mSorterLabel, 1);
- place(6, 0, mSortDropDown, 1);
+ mSlotsBarCell = &place(1, 0, mSlotsBar, 5);
+ mSortDropDownCell = &place(6, 0, mSortDropDown, 1);
place(0, 1, mFilterLabel, 1).setPadding(3);
- place(1, 1, mFilter, 5).setPadding(3);
- place(6, 1, mNameFilter, 1);
+ mFilterCell = &place(1, 1, mFilter, 6).setPadding(3);
+ mNameFilterCell = &place(6, 1, mNameFilter, 1);
place(0, 2, invenScroll, 7, 4);
place(0, 6, mStoreButton);
@@ -240,6 +238,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
loadWindowState();
slotsChanged(mInventory);
+ widgetResized(0);
if (!isMainInventory())
setVisible(true);
}
@@ -666,3 +665,35 @@ bool InventoryWindow::isAnyInputFocused()
}
return false;
}
+
+void InventoryWindow::widgetResized(const gcn::Event &event)
+{
+ Window::widgetResized(event);
+
+ if (!isMainInventory())
+ return;
+
+ if (getWidth() < 600)
+ {
+ if (!mCompactMode)
+ {
+ mSortDropDown->setVisible(false);
+ mNameFilter->setVisible(false);
+ mSortDropDownCell->setType(LayoutCell::NONE);
+ mNameFilterCell->setType(LayoutCell::NONE);
+ mFilterCell->setWidth(mFilterCell->getWidth() + 3);
+ mSlotsBarCell->setWidth(mSlotsBarCell->getWidth() + 3);
+ mCompactMode = true;
+ }
+ }
+ else if (mCompactMode)
+ {
+ mSortDropDown->setVisible(true);
+ mNameFilter->setVisible(true);
+ mSortDropDownCell->setType(LayoutCell::WIDGET);
+ mNameFilterCell->setType(LayoutCell::WIDGET);
+ mFilterCell->setWidth(mFilterCell->getWidth() - 3);
+ mSlotsBarCell->setWidth(mSlotsBarCell->getWidth() - 3);
+ mCompactMode = false;
+ }
+}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index c32fd8905..5592b9449 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -45,6 +45,7 @@ class DropDown;
class Item;
class ItemContainer;
class InventoryFilter;
+class LayoutCell;
class ProgressBar;
class SortListModel;
//class TextBox;
@@ -133,6 +134,8 @@ class InventoryWindow : public Window,
bool isInputFocused() const;
+ void widgetResized(const gcn::Event &event);
+
static bool isAnyInputFocused();
private:
@@ -154,15 +157,20 @@ class InventoryWindow : public Window,
*mSplitButton, *mOutfitButton, *mShopButton,
*mStoreButton, *mRetrieveButton, *mCloseButton;
- gcn::Label *mWeightLabel, *mSlotsLabel, *mFilterLabel, *mSorterLabel;
+ gcn::Label *mWeightLabel, *mSlotsLabel, *mFilterLabel;
ProgressBar *mWeightBar, *mSlotsBar;
InventoryFilter *mFilter;
DropDown *mSortDropDown;
SortListModel *mSortModel;
TextField *mNameFilter;
+ LayoutCell *mSortDropDownCell;
+ LayoutCell *mNameFilterCell;
+ LayoutCell *mFilterCell;
+ LayoutCell *mSlotsBarCell;
bool mSplit;
+ bool mCompactMode;
};
extern InventoryWindow *inventoryWindow;
diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h
index f5e1f1749..5e3ac4532 100644
--- a/src/gui/widgets/layout.h
+++ b/src/gui/widgets/layout.h
@@ -261,6 +261,28 @@ class LayoutCell
*/
void computeSizes();
+ void setType(int t)
+ { mType = t; }
+
+ int getWidth()
+ { return mExtent[0]; }
+
+ int getHeight()
+ { return mExtent[1]; }
+
+ void setWidth(int w)
+ { mExtent[0] = w; }
+
+ void setHeight(int h)
+ { mExtent[1] = h; }
+
+ enum
+ {
+ NONE = 0,
+ WIDGET,
+ ARRAY
+ };
+
private:
// Copy not allowed, as the cell may own an array.
LayoutCell(LayoutCell const &);
@@ -272,13 +294,6 @@ class LayoutCell
LayoutArray *mArray;
};
- enum
- {
- NONE = 0,
- WIDGET,
- ARRAY
- };
-
/**
* Returns the embedded array. Creates it if the cell does not contain
* anything yet. Aborts if it contains a widget.