diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-28 14:59:38 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-28 14:59:38 +0000 |
commit | aea08a9368265c6afd6741fa84c97491552bfb84 (patch) | |
tree | 9693e7c9bfbafd9cbb7b1ad5b1b19227c074d158 | |
parent | c450af8c731fa8dfaa127a4cfe3ad588ede60658 (diff) | |
download | mana-aea08a9368265c6afd6741fa84c97491552bfb84.tar.gz mana-aea08a9368265c6afd6741fa84c97491552bfb84.tar.bz2 mana-aea08a9368265c6afd6741fa84c97491552bfb84.tar.xz mana-aea08a9368265c6afd6741fa84c97491552bfb84.zip |
Separated auto-resizing into two categories: "set" and "add". Removed useless code.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/gui/buy.cpp | 2 | ||||
-rw-r--r-- | src/gui/inventorywindow.cpp | 10 | ||||
-rw-r--r-- | src/gui/sell.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/layout.cpp | 39 | ||||
-rw-r--r-- | src/gui/widgets/layout.h | 29 |
6 files changed, 59 insertions, 31 deletions
@@ -1,3 +1,10 @@ +2007-10-28 Guillaume Melquiond <guillaume.melquiond@gmail.com> + + * src/gui/widgets/layout.h, src/gui/widgets/layout.cpp: Separated + auto-resizing into two categories: "set" and "add". + * src/gui/sell.cpp, src/gui/inventorywindow.cpp, src/gui/buy.cpp: + Removed useless code. Updated constant names. + 2007-10-28 Eugenio Favalli <elvenprogrammer@gmail.com> * src/gui/debugwindow.cpp, tmw.cbp: Fixed coordinates in the debug diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index bf449b2f..a21435f8 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -86,7 +86,7 @@ BuyDialog::BuyDialog(): place(3, 5, mBuyButton); place(4, 5, mQuitButton); Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::FILL); + layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState("Buy"); setLocationRelativeTo(getParent()); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 4621e59a..bf23a419 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -65,10 +65,6 @@ InventoryWindow::InventoryWindow(): mDropButton = new Button(_("Drop"), "drop", this); mSplitButton = new Button(_("Split"), "split", this); - mUseButton->adjustSize(); - mDropButton->adjustSize(); - mSplitButton->adjustSize(); - mItems = new ItemContainer(player_node->mInventory.get(), 10, 5); mItems->addSelectionListener(this); @@ -93,7 +89,7 @@ InventoryWindow::InventoryWindow(): layout.setColWidth(0, 48); layout.setColWidth(1, 48); layout.setColWidth(2, 48); - layout.setRowHeight(1, Layout::FILL); + layout.setRowHeight(1, Layout::AUTO_SET); loadWindowState("Inventory"); } @@ -160,10 +156,6 @@ void InventoryWindow::selectionChanged(const SelectionEvent &event) mItemDescriptionLabel->setCaption(strprintf(_("Description: %s"), info ? info->getDescription().c_str() : "")); - mItemNameLabel->adjustSize(); - mItemEffectLabel->adjustSize(); - mItemDescriptionLabel->adjustSize(); - if (mSplit) { if (item && !item->isEquipment() && item->getQuantity() > 1) { diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 8c442aad..08565654 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -91,8 +91,7 @@ SellDialog::SellDialog(): place(3, 5, mSellButton); place(4, 5, mQuitButton); Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::FILL); - layout.setColWidth(2, Layout::FILL); + layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState("Sell"); setLocationRelativeTo(getParent()); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 2bcc558d..02ed42a1 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -125,14 +125,14 @@ void LayoutArray::resizeGrid(int w, int h) if (extH) { - mSizes[1].resize(h, Layout::FILL); + mSizes[1].resize(h, Layout::AUTO_DEF); mCells.resize(h); if (!extW) w = mSizes[0].size(); } if (extW) { - mSizes[0].resize(w, Layout::FILL); + mSizes[0].resize(w, Layout::AUTO_DEF); } for (std::vector< std::vector< LayoutCell * > >::iterator @@ -157,12 +157,19 @@ void LayoutArray::setRowHeight(int n, int h) void LayoutArray::matchColWidth(int n1, int n2) { resizeGrid(std::max(n1, n2) + 1, 0); - std::vector< short > widths = getSizes(0, Layout::FILL); + std::vector< short > widths = getSizes(0, Layout::AUTO_DEF); int s = std::max(widths[n1], widths[n2]); mSizes[0][n1] = s; mSizes[0][n2] = s; } +void LayoutArray::extend(int x, int y, int w, int h) +{ + LayoutCell &cell = at(x, y, w, h); + cell.mExtent[0] = w; + cell.mExtent[1] = h; +} + LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) { LayoutCell &cell = at(x, y, w, h); @@ -177,8 +184,8 @@ LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) cell.mAlign[0] = LayoutCell::FILL; cell.mAlign[1] = LayoutCell::FILL; short &cs = mSizes[0][x], &rs = mSizes[1][y]; - if (cs == Layout::FILL && w == 1) cs = 0; - if (rs == Layout::FILL && h == 1) rs = 0; + if (cs == Layout::AUTO_DEF && w == 1) cs = 0; + if (rs == Layout::AUTO_DEF && h == 1) rs = 0; return cell; } @@ -228,17 +235,23 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const } } - if (upp == Layout::FILL) return sizes; + if (upp == Layout::AUTO_DEF) return sizes; // Compute the FILL sizes. int nb = sizes.size(); int nbFill = 0; for (int i = 0; i < nb; ++i) { - if (mSizes[dim][i] == Layout::FILL) ++nbFill; - if (sizes[i] == Layout::FILL) sizes[i] = 0; - else upp -= sizes[i]; - upp -= mSpacing; + if (mSizes[dim][i] <= Layout::AUTO_DEF) + { + ++nbFill; + if (mSizes[dim][i] == Layout::AUTO_SET || + sizes[i] <= Layout::AUTO_DEF) + { + sizes[i] = 0; + } + } + upp -= sizes[i] + mSpacing; } upp = upp + mSpacing; @@ -246,7 +259,7 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const for (int i = 0; i < nb; ++i) { - if (mSizes[dim][i] != Layout::FILL) continue; + if (mSizes[dim][i] > Layout::AUTO_DEF) continue; int s = upp / nbFill; sizes[i] += s; upp -= s; @@ -258,12 +271,12 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const int LayoutArray::getSize(int dim) const { - std::vector< short > sizes = getSizes(dim, Layout::FILL); + std::vector< short > sizes = getSizes(dim, Layout::AUTO_DEF); int size = 0; int nb = sizes.size(); for (int i = 0; i < nb; ++i) { - if (sizes[i] != Layout::FILL) size += sizes[i]; + if (sizes[i] > Layout::AUTO_DEF) size += sizes[i]; size += mSpacing; } return size - mSpacing; diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index a6e630c2..2d81ad81 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -88,7 +88,7 @@ class LayoutArray * @param w number of columns the widget spawns. * @param h number of rows the widget spawns. * @note When @a w is 1, the width of column @a x is reset to zero if - * it was FILL. + * it was AUTO_DEF. Similarly for @a h. */ LayoutCell &place(gcn::Widget *, int x, int y, int w = 1, int h = 1); @@ -108,9 +108,14 @@ class LayoutArray void matchColWidth(int n1, int n2); /** + * Spawns a cell over several columns/rows. + */ + void extend(int x, int y, int w, int h); + + /** * Computes and sets the positions of all the widgets. - * @param nW width of the array, used to resize the FILL columns. - * @param nH height of the array, used to resize the FILL rows. + * @param nW width of the array, used to resize the AUTO_ columns. + * @param nH height of the array, used to resize the AUTO_ rows. */ void reflow(int nX, int nY, int nW, int nH); @@ -133,7 +138,7 @@ class LayoutArray /** * Gets the column/row sizes along a given axis. - * @param upp target size for the array. Ignored if FILL. + * @param upp target size for the array. Ignored if AUTO_DEF. */ std::vector< short > getSizes(int dim, int upp) const; @@ -220,6 +225,12 @@ class LayoutCell { getArray().setRowHeight(n, h); } /** + * @see LayoutArray::extend. + */ + void extend(int x, int y, int w, int h) + { getArray().extend(x, y, w, h); } + + /** * Sets the minimum widths and heights of this cell and of all the * inner cells. */ @@ -267,7 +278,7 @@ class LayoutCell * be a single table or a tree of nested tables. * * The size of a given table column can either be set manually or be chosen - * from the widest widget of the column. An empty column has a FILL width, + * from the widest widget of the column. An empty column has a AUTO_DEF width, * which means it will be extended so that the layout fits its minimum width. * * The process is similar for table rows. By default, there is a spacing of 4 @@ -292,9 +303,15 @@ class Layout: public LayoutCell */ void reflow(int &nW, int &nH); + /** + * When the minimum size of the layout is less than the available size, + * the remaining pixels are equally split amongst the FILL items. + */ enum { - FILL = -42, /**< Expand until the layout as the expected size. */ + AUTO_DEF = -42, /**< Default value, behaves like AUTO_ADD. */ + AUTO_SET = -43, /**< Uses the share as the new size. */ + AUTO_ADD = -44, /**< Adds the share to the current size. */ }; private: |