GG: Layout.h Source File

GG

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Layout.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3 Copyright (C) 2003-2008 T. Zachary Laine
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 2.1
8 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA
19
20 If you do not wish to comply with the terms of the LGPL please
21 contact the author as other terms are available for a fee.
22
23 Zach Laine
24 whatwasthataddress@gmail.com */
25
29 #ifndef _GG_Layout_h_
30 #define _GG_Layout_h_
31
32 #include <GG/AlignmentFlags.h>
33 #include <GG/Wnd.h>
34
35
36 namespace GG {
37
38 struct SetMarginAction;
39
103 class GG_API Layout : public Wnd
104 {
105 public:
107
108 Layout(X x, Y y, X w, Y h, std::size_t rows, std::size_t columns, unsigned int border_margin = 0, unsigned int cell_margin = INVALID_CELL_MARGIN);
110
112 virtual Pt MinUsableSize() const;
113
114 std::size_t Rows() const;
115 std::size_t Columns() const;
116 Flags<Alignment> ChildAlignment(const Wnd* wnd) const;
117 unsigned int BorderMargin() const;
118 unsigned int CellMargin() const;
119 double RowStretch(std::size_t row) const;
120 double ColumnStretch(std::size_t column) const;
121 Y MinimumRowHeight(std::size_t row) const;
122 X MinimumColumnWidth(std::size_t column) const;
123 std::vector<std::vector<const Wnd*> >
124 Cells() const;
125 std::vector<std::vector<Rect> >
126 CellRects() const;
127 std::vector<std::vector<Rect> >
128 RelativeCellRects() const;
129
132 bool RenderOutline() const;
133
137 Clr OutlineColor() const;
139
141 virtual void StartingChildDragDrop(const Wnd* wnd, const Pt& offset);
142 virtual void CancellingChildDragDrop(const std::vector<const Wnd*>& wnds);
143 virtual void ChildrenDraggedAway(const std::vector<Wnd*>& wnds, const Wnd* destination);
144 virtual void SizeMove(const Pt& ul, const Pt& lr);
145 virtual void Render();
146
150 void Add(Wnd* wnd, std::size_t row, std::size_t column, Flags<Alignment> alignment = ALIGN_NONE);
151
159 void Add(Wnd* wnd, std::size_t row, std::size_t column, std::size_t num_rows, std::size_t num_columns, Flags<Alignment> alignment = ALIGN_NONE);
160
164 void Remove(Wnd* wnd);
165
169 void DetachAndResetChildren();
170
174 void ResizeLayout(std::size_t rows, std::size_t columns);
175
178 void SetChildAlignment(const Wnd* wnd, Flags<Alignment> alignment);
179
182 void SetBorderMargin(unsigned int margin);
183
186 void SetCellMargin(unsigned int margin);
187
192 void SetRowStretch(std::size_t row, double stretch);
193
198 void SetColumnStretch(std::size_t column, double stretch);
199
202 void SetMinimumRowHeight(std::size_t row, Y height);
203
206 void SetMinimumColumnWidth(std::size_t column, X width);
207
210 void RenderOutline(bool render_outline);
211
215 void SetOutlineColor(Clr color);
217
219
220 GG_ABSTRACT_EXCEPTION(Exception);
221
223 GG_CONCRETE_EXCEPTION(InvalidMargin, GG::Layout, Exception);
224
226 GG_CONCRETE_EXCEPTION(NoSuchChild, GG::Layout, Exception);
227
230 GG_CONCRETE_EXCEPTION(FailedCalculationCheck, GG::Layout, Exception);
231
234 GG_CONCRETE_EXCEPTION(AttemptedOverwrite, GG::Layout, Exception);
236
237 static const unsigned int INVALID_CELL_MARGIN;
238
239 protected:
241 Layout();
242
243
245 virtual void MouseWheel(const Pt& pt, int move, Flags<ModKey> mod_keys);
246 virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
247 virtual void KeyRelease(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
249
250 private:
251 struct GG_API RowColParams
252 {
253 RowColParams();
254
255 double stretch;
256 unsigned int min;
257 unsigned int effective_min;
258 int current_origin;
259 unsigned int current_width;
260 };
261
262 struct GG_API WndPosition
263 {
264 WndPosition();
265 WndPosition(std::size_t first_row_, std::size_t first_column_,
266 std::size_t last_row_, std::size_t last_column_,
267 Flags<Alignment> alignment_, const Pt& original_ul_, const Pt& original_size_);
268
269 std::size_t first_row;
270 std::size_t first_column;
271 std::size_t last_row;
272 std::size_t last_column;
273 Flags<Alignment> alignment;
274 Pt original_ul;
275 Pt original_size;
276 };
277
278 double TotalStretch(const std::vector<RowColParams>& params_vec) const;
279 X TotalMinWidth() const;
280 Y TotalMinHeight() const;
281 void ValidateAlignment(Flags<Alignment>& alignment);
282 void RedoLayout();
283 void ChildSizeOrMinSizeOrMaxSizeChanged();
284
285 std::vector<std::vector<Wnd*> > m_cells;
286 unsigned int m_border_margin;
287 unsigned int m_cell_margin;
288 std::vector<RowColParams> m_row_params;
289 std::vector<RowColParams> m_column_params;
290 std::map<Wnd*, WndPosition> m_wnd_positions;
291 Pt m_min_usable_size;
292 bool m_ignore_child_resize;
293 bool m_ignore_parent_resize;
294 bool m_render_outline;
295 Clr m_outline_color;
296
297 friend class Wnd;
298 friend struct SetMarginAction;
299 };
300
301 } // namespace GG
302
303 #endif