00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIDGET_LAYOUT_H
00023 #define WIDGET_LAYOUT_H
00024
00025 #include <guichan/widgets/container.hpp>
00026
00027 #include <vector>
00028
00029 class LayoutCell;
00030
00034 class ContainerPlacer
00035 {
00036 public:
00037
00038 ContainerPlacer(gcn::Container *c = NULL, LayoutCell *l = NULL):
00039 mContainer(c), mCell(l)
00040 {}
00041
00045 LayoutCell &getCell()
00046 { return *mCell; }
00047
00051 ContainerPlacer at(int x, int y);
00052
00057 LayoutCell &operator()
00058 (int x, int y, gcn::Widget *, int w = 1, int h = 1);
00059
00060 private:
00061
00062 gcn::Container *mContainer;
00063 LayoutCell *mCell;
00064 };
00065
00069 class LayoutArray
00070 {
00071 friend class LayoutCell;
00072
00073 public:
00074
00075 LayoutArray();
00076
00077 ~LayoutArray();
00078
00082 LayoutCell &at(int x, int y, int w = 1, int h = 1);
00083
00091 LayoutCell &place(gcn::Widget *, int x, int y, int w = 1, int h = 1);
00092
00096 void setColWidth(int n, int w);
00097
00101 void setRowHeight(int n, int h);
00102
00106 void matchColWidth(int n1, int n2);
00107
00111 void extend(int x, int y, int w, int h);
00112
00118 void reflow(int nX, int nY, int nW, int nH);
00119
00120 private:
00121
00122
00123 LayoutArray(LayoutArray const &);
00124 LayoutArray &operator=(LayoutArray const &);
00125
00129 void align(int &pos, int &size, int dim,
00130 LayoutCell const &cell, short *sizes) const;
00131
00135 void resizeGrid(int w, int h);
00136
00141 std::vector< short > getSizes(int dim, int upp) const;
00142
00146 int getSize(int dim) const;
00147
00148 std::vector< short > mSizes[2];
00149 std::vector< std::vector < LayoutCell * > > mCells;
00150
00151 char mSpacing;
00152 };
00153
00161 class LayoutCell
00162 {
00163 friend class Layout;
00164 friend class LayoutArray;
00165
00166 public:
00167
00168 enum Alignment
00169 {
00170 LEFT, RIGHT, CENTER, FILL
00171 };
00172
00173 LayoutCell(): mType(NONE) {}
00174
00175 ~LayoutCell();
00176
00180 LayoutCell &setPadding(int p)
00181 { mPadding = p; return *this; }
00182
00186 LayoutCell &setHAlign(Alignment a)
00187 { mAlign[0] = a; return *this; }
00188
00192 LayoutCell &setVAlign(Alignment a)
00193 { mAlign[1] = a; return *this; }
00194
00198 LayoutCell &at(int x, int y)
00199 { return getArray().at(x, y); }
00200
00204 LayoutCell &place(gcn::Widget *wg, int x, int y, int w = 1, int h = 1)
00205 { return getArray().place(wg, x, y, w, h); }
00206
00210 void matchColWidth(int n1, int n2)
00211 { getArray().matchColWidth(n1, n2); }
00212
00216 void setColWidth(int n, int w)
00217 { getArray().setColWidth(n, w); }
00218
00222 void setRowHeight(int n, int h)
00223 { getArray().setRowHeight(n, h); }
00224
00228 void extend(int x, int y, int w, int h)
00229 { getArray().extend(x, y, w, h); }
00230
00235 void computeSizes();
00236
00237 private:
00238
00239
00240 LayoutCell(LayoutCell const &);
00241 LayoutCell &operator=(LayoutCell const &);
00242
00243 union
00244 {
00245 gcn::Widget *mWidget;
00246 LayoutArray *mArray;
00247 };
00248
00249 enum
00250 {
00251 NONE, WIDGET, ARRAY
00252 };
00253
00258 LayoutArray &getArray();
00259
00263 void reflow(int nx, int ny, int nw, int nh);
00264
00265 short mSize[2];
00266 char mPadding;
00267 char mExtent[2];
00268 char mAlign[2];
00269 char mNbFill[2];
00270 char mType;
00271 };
00272
00286 class Layout: public LayoutCell
00287 {
00288 public:
00289
00290 Layout();
00291
00295 void setMargin(int m)
00296 { setPadding(m); }
00297
00302 void reflow(int &nW, int &nH);
00303
00308 enum
00309 {
00310 AUTO_DEF = -42,
00311 AUTO_SET = -43,
00312 AUTO_ADD = -44
00313 };
00314
00315 private:
00316
00317 bool mComputed;
00318 };
00319
00320 #endif // WIDGET_LAYOUT_H