Crazy Eddie's GUI System  0.8.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
GridLayoutContainer.h
1 /***********************************************************************
2  filename: CEGUIGridLayoutContainer.h
3  created: 01/8/2010
4  author: Martin Preisler
5 
6  purpose: Interface to a vertical layout container
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2010 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIGridLayoutContainer_h_
31 #define _CEGUIGridLayoutContainer_h_
32 
33 #include "./LayoutContainer.h"
34 #include "../WindowFactory.h"
35 
36 #if defined(_MSC_VER)
37 # pragma warning(push)
38 # pragma warning(disable : 4251)
39 #endif
40 
41 // Start of CEGUI namespace section
42 namespace CEGUI
43 {
48 class CEGUIEXPORT GridLayoutContainer : public LayoutContainer
49 {
50 public:
57  {
71  AP_TopToBottom
72  };
73 
74  /*************************************************************************
75  Constants
76  *************************************************************************/
78  static const String WidgetTypeName;
79 
80  /*************************************************************************
81  Child Widget name suffix constants
82  *************************************************************************/
84  static const String DummyName;
85 
86  /*************************************************************************
87  Event name constants
88  *************************************************************************/
90  static const String EventNamespace;
91 
94 
95  /*************************************************************************
96  Construction and Destruction
97  *************************************************************************/
102  GridLayoutContainer(const String& type, const String& name);
103 
108  virtual ~GridLayoutContainer(void);
109 
114  void setGridDimensions(size_t width, size_t height);
119  void setGrid(const Sizef &size);
120 
125  size_t getGridWidth() const;
126 
131  size_t getGridHeight() const;
132 
137  Sizef getGrid() const;
138 
139 
148  void setAutoPositioning(AutoPositioning positioning);
149 
154  AutoPositioning getAutoPositioning() const;
155 
161  void setNextAutoPositioningIdx(size_t idx);
162 
168  size_t getNextAutoPositioningIdx() const;
169 
174  void autoPositioningSkipCells(size_t cells);
175 
193  void addChildToPosition(Window* window, size_t gridX, size_t gridY);
194 
199  Window* getChildAtPosition(size_t gridX, size_t gridY);
200 
208  void removeChildFromPosition(size_t gridX, size_t gridY);
209 
217  virtual void swapChildPositions(size_t wnd1, size_t wnd2);
218 
223  void swapChildPositions(size_t gridX1, size_t gridY1,
224  size_t gridX2, size_t gridY2);
225 
230  void swapChildren(Window* wnd1, Window* wnd2);
231 
236  void swapChildren(Window* wnd1, const String& wnd2);
237 
242  void swapChildren(const String& wnd1, Window* wnd2);
243 
248  void moveChildToPosition(Window* wnd, size_t gridX, size_t gridY);
249 
254  void moveChildToPosition(const String& wnd,
255  size_t gridX, size_t gridY);
256 
258  virtual void layout();
259 
260 protected:
269  virtual void onChildOrderChanged(WindowEventArgs& e);
270 
272  size_t mapFromGridToIdx(size_t gridX, size_t gridY,
273  size_t gridWidth, size_t gridHeight) const;
275  void mapFromIdxToGrid(size_t idx, size_t& gridX, size_t& gridY,
276  size_t gridWidth, size_t gridHeight) const;
277 
281  UVector2 getGridCellOffset(const std::vector<UDim>& colSizes,
282  const std::vector<UDim>& rowSizes,
283  size_t gridX, size_t gridY) const;
285  USize getGridSize(const std::vector<UDim>& colSizes,
286  const std::vector<UDim>& rowSizes) const;
287 
289  size_t translateAPToGridIdx(size_t APIdx) const;
290 
292  size_t d_gridWidth;
294  size_t d_gridHeight;
295 
302 
306  size_t d_nextGridX;
310  size_t d_nextGridY;
311 
316 
318  Window* createDummy();
320  bool isDummy(Window* wnd) const;
321 
323  virtual void addChild_impl(Element* element);
325  virtual void removeChild_impl(Element* element);
326 
327 private:
328  void addGridLayoutContainerProperties(void);
329 };
330 
331 template<>
332 class PropertyHelper<GridLayoutContainer::AutoPositioning>
333 {
334 public:
338  typedef String string_return_type;
339 
340  static const String& getDataTypeName()
341  {
342  static String type("AutoPositioning");
343 
344  return type;
345  }
346 
347  static return_type fromString(const String& str)
348  {
349  if (str == "Disabled")
350  {
352  }
353  else if (str == "Top to Bottom")
354  {
356  }
357  else
358  {
360  }
361  }
362 
363  static string_return_type toString(pass_type val)
364  {
366  {
367  return "Left to Right";
368  }
369  else if (val == GridLayoutContainer::AP_Disabled)
370  {
371  return "Disabled";
372  }
373  else if (val == GridLayoutContainer::AP_TopToBottom)
374  {
375  return "Top to Bottom";
376  }
377  else
378  {
379  assert(false && "Invalid Auto Positioning");
380  return "Left to Right";
381  }
382  }
383 };
384 
385 } // End of CEGUI namespace section
386 
387 #if defined(_MSC_VER)
388 # pragma warning(pop)
389 #endif
390 
391 #endif // end of guard _CEGUIGridLayoutContainer_h_