ManaPlus
layoutcell.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2007-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "gui/widgets/layoutcell.h"
25 
27 #include "gui/widgets/widget.h"
28 
29 #include "utils/delete2.h"
30 
31 #include "debug.h"
32 
35 
37 {
38  if (mType == ARRAY)
40 }
41 
43 {
44  if (mType == WIDGET)
45  return tempArray;
46  if (mType == ARRAY)
47  {
48  if (mArray == nullptr)
49  return tempArray;
50  return *mArray;
51  }
52 
53  mArray = new LayoutArray;
54  mType = ARRAY;
55  mExtent[0] = 1;
56  mExtent[1] = 1;
57  mHPadding = 0;
58  mVPadding = 0;
59  mAlign[0] = FILL;
60  mAlign[1] = FILL;
61  return *mArray;
62 }
63 
64 void LayoutCell::reflow(int nx, int ny, int nw, int nh)
65 {
66  if (mType == NONE)
67  return;
68 
69  nx += mHPadding;
70  ny += mVPadding;
71  nw -= 2 * mHPadding;
72  nh -= 2 * mVPadding;
73  if (mType == ARRAY)
74  mArray->reflow(nx, ny, nw, nh);
75  else
76  mWidget->setDimension(Rect(nx, ny, nw, nh));
77 }
78 
80 {
81  if (mType != ARRAY)
82  return;
83 
84  STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
85  i = mArray->mCells.begin();
86  const STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
87  i_end = mArray->mCells.end();
88  while (i != i_end)
89  {
90  STD_VECTOR <LayoutCell *>::const_iterator j = i->begin();
91  while (j != i->end())
92  {
93  LayoutCell *const cell = *j;
94  if ((cell != nullptr) && cell->mType == ARRAY)
95  cell->computeSizes();
96 
97  ++j;
98  }
99  ++i;
100  }
101 
102  mSize[0] = mArray->getSize(0);
103  mSize[1] = mArray->getSize(1);
104 }
105 
106 LayoutCell &LayoutCell::at(const int x, const int y)
107 {
108  return getArray().at(x, y, 1, 1);
109 }
110 
112  const int x, const int y,
113  const int w, const int h)
114 {
115  return getArray().place(wg, x, y, w, h);
116 }
117 
118 void LayoutCell::matchColWidth(const int n1, const int n2)
119 {
120  getArray().matchColWidth(n1, n2);
121 }
122 
123 void LayoutCell::setColWidth(const int n, const int w)
124 {
125  getArray().setColWidth(n, w);
126 }
127 
128 void LayoutCell::setRowHeight(const int n, const int h)
129 {
130  getArray().setRowHeight(n, h);
131 }
132 
133 void LayoutCell::extend(const int x, const int y,
134  const int w, const int h)
135 {
136  getArray().extend(x, y, w, h);
137 }
std::vector< std::vector< LayoutCell * > > mCells
Definition: layoutarray.h:128
void extend(const int x, const int y, const int w, const int h)
int getSize(const int dim) const
void setColWidth(const int n, const int w)
void matchColWidth(const int n1, const int n2)
void setRowHeight(const int n, const int h)
LayoutCell & at(const int x, const int y, const int w, const int h)
Definition: layoutarray.cpp:60
LayoutCell & place(Widget *const widget, const int x, const int y, const int w, const int h)
void reflow(const int nX, const int nY, const int nW, const int nH)
virtual ~LayoutCell()
Definition: layoutcell.cpp:36
void extend(const int x, const int y, const int w, const int h)
Definition: layoutcell.cpp:133
static LayoutCell emptyCell
Definition: layoutcell.h:156
void reflow(int nx, int ny, int nw, int nh)
Definition: layoutcell.cpp:64
int mExtent[2]
Definition: layoutcell.h:199
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:128
int mSize[2]
Definition: layoutcell.h:196
friend class LayoutArray
Definition: layoutcell.h:42
void setColWidth(const int n, const int w)
Definition: layoutcell.cpp:123
Alignment mAlign[2]
Definition: layoutcell.h:200
LayoutArray * mArray
Definition: layoutcell.h:182
LayoutCell & place(Widget *const wg, const int x, const int y, const int w, const int h)
Definition: layoutcell.cpp:111
int mHPadding
Definition: layoutcell.h:197
LayoutArray & getArray()
Definition: layoutcell.cpp:42
void computeSizes()
Definition: layoutcell.cpp:79
Widget * mWidget
Definition: layoutcell.h:181
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:118
LayoutCell & at(const int x, const int y)
Definition: layoutcell.cpp:106
int mVPadding
Definition: layoutcell.h:198
Definition: rect.h:74
Definition: widget.h:99
void setDimension(const Rect &dimension)
Definition: widget.cpp:169
#define delete2(var)
Definition: delete2.h:25
static LayoutArray tempArray
Definition: layoutcell.cpp:33