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