Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 01/8/2010 00003 author: Martin Preisler 00004 00005 purpose: Interface to a vertical layout container 00006 *************************************************************************/ 00007 /*************************************************************************** 00008 * Copyright (C) 2004 - 2010 Paul D Turner & The CEGUI Development Team 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining 00011 * a copy of this software and associated documentation files (the 00012 * "Software"), to deal in the Software without restriction, including 00013 * without limitation the rights to use, copy, modify, merge, publish, 00014 * distribute, sublicense, and/or sell copies of the Software, and to 00015 * permit persons to whom the Software is furnished to do so, subject to 00016 * the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be 00019 * included in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00023 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00024 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00025 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00026 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00027 * OTHER DEALINGS IN THE SOFTWARE. 00028 ***************************************************************************/ 00029 #ifndef _CEGUIGridLayoutContainer_h_ 00030 #define _CEGUIGridLayoutContainer_h_ 00031 00032 #include "./LayoutContainer.h" 00033 #include "../WindowFactory.h" 00034 00035 #if defined(_MSC_VER) 00036 # pragma warning(push) 00037 # pragma warning(disable : 4251) 00038 #endif 00039 00040 // Start of CEGUI namespace section 00041 namespace CEGUI 00042 { 00047 class CEGUIEXPORT GridLayoutContainer : public LayoutContainer 00048 { 00049 public: 00055 enum AutoPositioning 00056 { 00058 AP_Disabled, 00064 AP_LeftToRight, 00070 AP_TopToBottom 00071 }; 00072 00073 /************************************************************************* 00074 Constants 00075 *************************************************************************/ 00077 static const String WidgetTypeName; 00078 00079 /************************************************************************* 00080 Child Widget name suffix constants 00081 *************************************************************************/ 00083 static const String DummyName; 00084 00085 /************************************************************************* 00086 Event name constants 00087 *************************************************************************/ 00089 static const String EventNamespace; 00090 00092 static const String EventChildOrderChanged; 00093 00094 /************************************************************************* 00095 Construction and Destruction 00096 *************************************************************************/ 00101 GridLayoutContainer(const String& type, const String& name); 00102 00107 virtual ~GridLayoutContainer(void); 00108 00113 void setGridDimensions(size_t width, size_t height); 00118 void setGrid(const Sizef &size); 00119 00124 size_t getGridWidth() const; 00125 00130 size_t getGridHeight() const; 00131 00136 Sizef getGrid() const; 00137 00138 00147 void setAutoPositioning(AutoPositioning positioning); 00148 00153 AutoPositioning getAutoPositioning() const; 00154 00160 void setNextAutoPositioningIdx(size_t idx); 00161 00167 size_t getNextAutoPositioningIdx() const; 00168 00173 void autoPositioningSkipCells(size_t cells); 00174 00192 void addChildToPosition(Window* window, size_t gridX, size_t gridY); 00193 00198 Window* getChildAtPosition(size_t gridX, size_t gridY); 00199 00207 void removeChildFromPosition(size_t gridX, size_t gridY); 00208 00216 virtual void swapChildPositions(size_t wnd1, size_t wnd2); 00217 00222 void swapChildPositions(size_t gridX1, size_t gridY1, 00223 size_t gridX2, size_t gridY2); 00224 00229 void swapChildren(Window* wnd1, Window* wnd2); 00230 00235 void swapChildren(Window* wnd1, const String& wnd2); 00236 00241 void swapChildren(const String& wnd1, Window* wnd2); 00242 00247 void moveChildToPosition(Window* wnd, size_t gridX, size_t gridY); 00248 00253 void moveChildToPosition(const String& wnd, 00254 size_t gridX, size_t gridY); 00255 00257 virtual void layout(); 00258 00259 protected: 00268 virtual void onChildOrderChanged(WindowEventArgs& e); 00269 00271 size_t mapFromGridToIdx(size_t gridX, size_t gridY, 00272 size_t gridWidth, size_t gridHeight) const; 00274 void mapFromIdxToGrid(size_t idx, size_t& gridX, size_t& gridY, 00275 size_t gridWidth, size_t gridHeight) const; 00276 00280 UVector2 getGridCellOffset(const std::vector<UDim>& colSizes, 00281 const std::vector<UDim>& rowSizes, 00282 size_t gridX, size_t gridY) const; 00284 USize getGridSize(const std::vector<UDim>& colSizes, 00285 const std::vector<UDim>& rowSizes) const; 00286 00288 size_t translateAPToGridIdx(size_t APIdx) const; 00289 00291 size_t d_gridWidth; 00293 size_t d_gridHeight; 00294 00296 AutoPositioning d_autoPositioning; 00300 size_t d_nextAutoPositioningIdx; 00301 00305 size_t d_nextGridX; 00309 size_t d_nextGridY; 00310 00314 size_t d_nextDummyIdx; 00315 00317 Window* createDummy(); 00319 bool isDummy(Window* wnd) const; 00320 00322 virtual void addChild_impl(Element* element); 00324 virtual void removeChild_impl(Element* element); 00325 00326 private: 00327 void addGridLayoutContainerProperties(void); 00328 }; 00329 00330 template<> 00331 class PropertyHelper<GridLayoutContainer::AutoPositioning> 00332 { 00333 public: 00334 typedef GridLayoutContainer::AutoPositioning return_type; 00335 typedef return_type safe_method_return_type; 00336 typedef GridLayoutContainer::AutoPositioning pass_type; 00337 typedef String string_return_type; 00338 00339 static const String& getDataTypeName() 00340 { 00341 static String type("AutoPositioning"); 00342 00343 return type; 00344 } 00345 00346 static return_type fromString(const String& str) 00347 { 00348 if (str == "Disabled") 00349 { 00350 return GridLayoutContainer::AP_Disabled; 00351 } 00352 else if (str == "Top to Bottom") 00353 { 00354 return GridLayoutContainer::AP_TopToBottom; 00355 } 00356 else 00357 { 00358 return GridLayoutContainer::AP_LeftToRight; 00359 } 00360 } 00361 00362 static string_return_type toString(pass_type val) 00363 { 00364 if (val == GridLayoutContainer::AP_LeftToRight) 00365 { 00366 return "Left to Right"; 00367 } 00368 else if (val == GridLayoutContainer::AP_Disabled) 00369 { 00370 return "Disabled"; 00371 } 00372 else if (val == GridLayoutContainer::AP_TopToBottom) 00373 { 00374 return "Top to Bottom"; 00375 } 00376 else 00377 { 00378 assert(false && "Invalid Auto Positioning"); 00379 return "Left to Right"; 00380 } 00381 } 00382 }; 00383 00384 } // End of CEGUI namespace section 00385 00386 #if defined(_MSC_VER) 00387 # pragma warning(pop) 00388 #endif 00389 00390 #endif // end of guard _CEGUIGridLayoutContainer_h_