Crazy Eddie's GUI System  0.8.4
FormattingSetting.h
00001 /***********************************************************************
00002     created:    Fri Jun 15 2012
00003     author:     Paul D Turner <paul@cegui.org.uk>
00004 *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
00007  *
00008  *   Permission is hereby granted, free of charge, to any person obtaining
00009  *   a copy of this software and associated documentation files (the
00010  *   "Software"), to deal in the Software without restriction, including
00011  *   without limitation the rights to use, copy, modify, merge, publish,
00012  *   distribute, sublicense, and/or sell copies of the Software, and to
00013  *   permit persons to whom the Software is furnished to do so, subject to
00014  *   the following conditions:
00015  *
00016  *   The above copyright notice and this permission notice shall be
00017  *   included in all copies or substantial portions of the Software.
00018  *
00019  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00023  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00024  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  *   OTHER DEALINGS IN THE SOFTWARE.
00026  ***************************************************************************/
00027 #ifndef _CEGUIFormattingSetting_h_
00028 #define _CEGUIFormattingSetting_h_
00029 
00030 #include "CEGUI/Window.h"
00031 #include "CEGUI/falagard/XMLEnumHelper.h"
00032 
00033 namespace CEGUI
00034 {
00035 
00036 template<typename T>
00037 class FormattingSetting
00038 {
00039 public:
00040     //------------------------------------------------------------------------//
00041     FormattingSetting() :
00042         d_value(FalagardXMLHelper<T>::fromString(""))
00043     {}
00044 
00045     //------------------------------------------------------------------------//
00046     FormattingSetting(const String& property_name) :
00047         d_value(FalagardXMLHelper<T>::fromString("")),
00048         d_propertySource(property_name)
00049     {}
00050 
00051     //------------------------------------------------------------------------//
00052     FormattingSetting(T val) :
00053         d_value(val)
00054     {}
00055 
00056     //------------------------------------------------------------------------//
00057     T get(const Window& wnd) const
00058     {
00059         if (d_propertySource.empty())
00060             return d_value;
00061 
00062         return FalagardXMLHelper<T>::fromString(
00063             wnd.getProperty(d_propertySource));
00064     }
00065 
00066     //------------------------------------------------------------------------//
00067     void set(T val)
00068     {
00069         d_value = val;
00070         d_propertySource.clear();
00071     }
00072 
00073     //------------------------------------------------------------------------//
00074     T getValue() const
00075     {
00076         return d_value;
00077     }
00078 
00079     //------------------------------------------------------------------------//
00080     void setPropertySource(const String& property_name)
00081     {
00082         d_propertySource = property_name;
00083     }
00084 
00085     //------------------------------------------------------------------------//
00086     bool isFetchedFromProperty() const
00087     {
00088         return !d_propertySource.empty();
00089     }
00090 
00091     //------------------------------------------------------------------------//
00092     void writeXMLToStream(XMLSerializer& xml_stream) const
00093     {
00094         writeXMLTagToStream(xml_stream);
00095         writeXMLAttributesToStream(xml_stream);
00096         xml_stream.closeTag();
00097     }
00098 
00099     //------------------------------------------------------------------------//
00100     virtual void writeXMLTagToStream(XMLSerializer& xml_stream) const
00101     {
00102         // This does nothing and needs to be specialised or overridden
00103     }
00104 
00105     //------------------------------------------------------------------------//
00106     virtual void writeXMLAttributesToStream(XMLSerializer& xml_stream) const
00107     {
00108         // This does nothing and needs to be specialised or overridden
00109     }
00110 
00111     //------------------------------------------------------------------------//
00112     bool operator==(const FormattingSetting<T>& rhs) const
00113     {
00114         return d_value == rhs.d_value &&
00115                d_propertySource == rhs.d_propertySource;
00116     }
00117 
00118     //------------------------------------------------------------------------//
00119     bool operator!=(const FormattingSetting<T>& rhs) const
00120     {
00121         return !operator==(rhs);
00122     }
00123 
00124 protected:
00125     T d_value;
00126     String d_propertySource;
00127 };
00128 
00129 template<> void CEGUIEXPORT FormattingSetting<VerticalFormatting>::writeXMLTagToStream(
00130                                             XMLSerializer& xml_stream) const;
00131 template<> void CEGUIEXPORT FormattingSetting<VerticalFormatting>::writeXMLAttributesToStream(
00132                                             XMLSerializer& xml_stream) const;
00133 template<> void CEGUIEXPORT FormattingSetting<HorizontalFormatting>::writeXMLTagToStream(
00134                                             XMLSerializer& xml_stream) const;
00135 template<> void CEGUIEXPORT FormattingSetting<HorizontalFormatting>::writeXMLAttributesToStream(
00136                                             XMLSerializer& xml_stream) const;
00137 template<> void CEGUIEXPORT FormattingSetting<VerticalTextFormatting>::writeXMLTagToStream(
00138                                             XMLSerializer& xml_stream) const;
00139 template<> void CEGUIEXPORT FormattingSetting<VerticalTextFormatting>::writeXMLAttributesToStream(
00140                                             XMLSerializer& xml_stream) const;
00141 template<> void CEGUIEXPORT FormattingSetting<HorizontalTextFormatting>::writeXMLTagToStream(
00142                                             XMLSerializer& xml_stream) const;
00143 template<> void CEGUIEXPORT FormattingSetting<HorizontalTextFormatting>::writeXMLAttributesToStream(
00144                                             XMLSerializer& xml_stream) const;
00145 }
00146 
00147 #endif
00148 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends