Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
FormattingSetting.h
1 /***********************************************************************
2  filename: FormattingSetting.h
3  created: Fri Jun 15 2012
4  author: Paul D Turner <paul@cegui.org.uk>
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUIFormattingSetting_h_
29 #define _CEGUIFormattingSetting_h_
30 
31 #include "CEGUI/Window.h"
32 #include "CEGUI/falagard/XMLEnumHelper.h"
33 
34 namespace CEGUI
35 {
36 
37 template<typename T>
39 {
40 public:
41  //------------------------------------------------------------------------//
44  {}
45 
46  //------------------------------------------------------------------------//
47  FormattingSetting(const String& property_name) :
49  d_propertySource(property_name)
50  {}
51 
52  //------------------------------------------------------------------------//
53  FormattingSetting(T val) :
54  d_value(val)
55  {}
56 
57  //------------------------------------------------------------------------//
58  T get(const Window& wnd) const
59  {
60  if (d_propertySource.empty())
61  return d_value;
62 
64  wnd.getProperty(d_propertySource));
65  }
66 
67  //------------------------------------------------------------------------//
68  void set(T val)
69  {
70  d_value = val;
71  d_propertySource.clear();
72  }
73 
74  //------------------------------------------------------------------------//
75  void setPropertySource(const String& property_name)
76  {
77  d_propertySource = property_name;
78  }
79 
80  //------------------------------------------------------------------------//
81  bool isFetchedFromProperty() const
82  {
83  return !d_propertySource.empty();
84  }
85 
86  //------------------------------------------------------------------------//
87  void writeXMLToStream(XMLSerializer& xml_stream) const
88  {
89  writeXMLTagToStream(xml_stream);
90  writeXMLAttributesToStream(xml_stream);
91  xml_stream.closeTag();
92  }
93 
94  //------------------------------------------------------------------------//
95  virtual void writeXMLTagToStream(XMLSerializer& xml_stream) const
96  {
97  // This does nothing and needs to be specialised or overridden
98  }
99 
100  //------------------------------------------------------------------------//
101  virtual void writeXMLAttributesToStream(XMLSerializer& xml_stream) const
102  {
103  // This does nothing and needs to be specialised or overridden
104  }
105 
106  //------------------------------------------------------------------------//
107  bool operator==(const FormattingSetting<T>& rhs) const
108  {
109  return d_value == rhs.d_value &&
110  d_propertySource == rhs.d_propertySource;
111  }
112 
113  //------------------------------------------------------------------------//
114  bool operator!=(const FormattingSetting<T>& rhs) const
115  {
116  return !operator==(rhs);
117  }
118 
119 protected:
120  T d_value;
121  String d_propertySource;
122 };
123 
125  XMLSerializer& xml_stream) const;
127  XMLSerializer& xml_stream) const;
129  XMLSerializer& xml_stream) const;
131  XMLSerializer& xml_stream) const;
133  XMLSerializer& xml_stream) const;
135  XMLSerializer& xml_stream) const;
137  XMLSerializer& xml_stream) const;
139  XMLSerializer& xml_stream) const;
140 }
141 
142 #endif
143