PixelLightAPI  .
SizeHint.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SizeHint.h                                     *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLGUI_SIZEHINT_H__
00024 #define __PLGUI_SIZEHINT_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLMath/Vector2i.h>
00032 #include "PLGui/PLGui.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Forward declarations                                  ]
00037 //[-------------------------------------------------------]
00038 namespace PLMath {
00039     class Vector2i;
00040 }
00041 
00042 
00043 //[-------------------------------------------------------]
00044 //[ Namespace                                             ]
00045 //[-------------------------------------------------------]
00046 namespace PLGui {
00047 
00048 
00049 //[-------------------------------------------------------]
00050 //[ Classes                                               ]
00051 //[-------------------------------------------------------]
00052 /**
00053 *  @brief
00054 *    Size hint
00055 */
00056 class SizeHint {
00057 
00058 
00059     //[-------------------------------------------------------]
00060     //[ Public definitions                                    ]
00061     //[-------------------------------------------------------]
00062     public:
00063         /**
00064         *  @brief
00065         *    Size policy
00066         */
00067         enum EPolicy {
00068             Pixel,      /**< The element will have a specific size specified in pixels */
00069             Percent,    /**< The element will have a specific size specified in percent of available space */
00070             Preferred,  /**< The element will try to take exactly the preferred size */
00071             Floating    /**< The element will take as much place as it can get */
00072         };
00073 
00074 
00075     //[-------------------------------------------------------]
00076     //[ Public functions                                      ]
00077     //[-------------------------------------------------------]
00078     public:
00079         /**
00080         *  @brief
00081         *    Constructor
00082         *
00083         *  @param[in] nPolicy
00084         *    Size policy
00085         *  @param[in] nSize
00086         *    Size
00087         */
00088         PLGUI_API SizeHint(EPolicy nPolicy = Floating, PLCore::uint32 nSize = 0);
00089 
00090         /**
00091         *  @brief
00092         *    Copy constructor
00093         *
00094         *  @param[in] cSizeHint
00095         *    Source to copy from
00096         */
00097         PLGUI_API SizeHint(const SizeHint &cSizeHint);
00098 
00099         /**
00100         *  @brief
00101         *    Destructor
00102         */
00103         PLGUI_API ~SizeHint();
00104 
00105         /**
00106         *  @brief
00107         *    Copy operator
00108         *
00109         *  @param[in] cSizeHint
00110         *    Source to copy from
00111         *
00112         *  @return
00113         *    Reference to this object
00114         */
00115         PLGUI_API SizeHint &operator =(const SizeHint &cSizeHint);
00116 
00117         /**
00118         *  @brief
00119         *    Comparison operator
00120         *
00121         *  @param[in] cSizeHint
00122         *    Object to compare with
00123         *
00124         *  @return
00125         *    'true' if both objects are equal, else 'false'
00126         */
00127         PLGUI_API bool operator ==(const SizeHint &cSizeHint) const;
00128 
00129         /**
00130         *  @brief
00131         *    Get size policy
00132         *
00133         *  @return
00134         *    Size policy
00135         */
00136         PLGUI_API EPolicy GetPolicy() const;
00137 
00138         /**
00139         *  @brief
00140         *    Set size policy
00141         *
00142         *  @param[in] nPolicy
00143         *    Size policy
00144         */
00145         PLGUI_API void SetPolicy(EPolicy nPolicy);
00146 
00147         /**
00148         *  @brief
00149         *    Get size
00150         *
00151         *  @return
00152         *    Size
00153         */
00154         PLGUI_API PLCore::uint32 GetSize() const;
00155 
00156         /**
00157         *  @brief
00158         *    Get size in float
00159         *
00160         *  @return
00161         *    Size
00162         */
00163         PLGUI_API float GetSizeFloat() const;
00164 
00165         /**
00166         *  @brief
00167         *    Set size
00168         *
00169         *  @param[in] nSize
00170         *    Size
00171         */
00172         PLGUI_API void SetSize(PLCore::uint32 nSize);
00173 
00174         /**
00175         *  @brief
00176         *    Set size in float
00177         *
00178         *  @param[in] fSize
00179         *    Size
00180         */
00181         PLGUI_API void SetSizeFloat(float fSize);
00182 
00183         /**
00184         *  @brief
00185         *    Set policy and size
00186         *
00187         *  @param[in] nPolicy
00188         *    Size policy
00189         *  @param[in] nSize
00190         *    Size
00191         */
00192         PLGUI_API void Set(EPolicy nPolicy, PLCore::uint32 nSize);
00193 
00194         /**
00195         *  @brief
00196         *    Set policy and size in float
00197         *
00198         *  @param[in] nPolicy
00199         *    Size policy
00200         *  @param[in] fSize
00201         *    Size
00202         */
00203         PLGUI_API void SetFloat(EPolicy nPolicy, float fSize);
00204 
00205         /**
00206         *  @brief
00207         *    Calculate actual size specified by this size hint
00208         *
00209         *  @param[in] nParentSize
00210         *    Size of the parent element, needed to calculate sizes specified in percentages
00211         *  @param[in] nPreferredSize
00212         *    Preferred size of the element, can be -1 if no preferred size is specified
00213         *
00214         *  @return
00215         *    Size, or -1 of policy is Floating
00216         */
00217         PLGUI_API int CalculateSize(PLCore::uint32 nParentSize, int nPreferredSize) const;
00218 
00219         /**
00220         *  @brief
00221         *    To string
00222         *
00223         *  @return
00224         *    String representation
00225         */
00226         PLGUI_API PLCore::String ToString() const;
00227 
00228         /**
00229         *  @brief
00230         *    From string
00231         *
00232         *  @param[in] sString
00233         *    String representation
00234         *
00235         *  @return
00236         *    'true' on success, else 'false'
00237         */
00238         PLGUI_API bool FromString(const PLCore::String &sString);
00239 
00240 
00241     //[-------------------------------------------------------]
00242     //[ Protected data                                        ]
00243     //[-------------------------------------------------------]
00244     protected:
00245         EPolicy m_nPolicy;  /**< Size policy */
00246         float   m_fSize;    /**< Size */
00247 
00248 
00249 };
00250 
00251 
00252 //[-------------------------------------------------------]
00253 //[ Namespace                                             ]
00254 //[-------------------------------------------------------]
00255 } // PLGui
00256 
00257 
00258 //[-------------------------------------------------------]
00259 //[ Implementation                                        ]
00260 //[-------------------------------------------------------]
00261 #include "PLGui/Gui/Data/TypeSizeHint.inl"
00262 
00263 
00264 #endif // __PLGUI_SIZEHINT_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:02
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported