Crazy Eddie's GUI System 0.8.7
Loading...
Searching...
No Matches
FormattingSetting.h
1/***********************************************************************
2 created: Fri Jun 15 2012
3 author: Paul D Turner <paul@cegui.org.uk>
4*************************************************************************/
5/***************************************************************************
6 * Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 ***************************************************************************/
27#ifndef _CEGUIFormattingSetting_h_
28#define _CEGUIFormattingSetting_h_
29
30#include "CEGUI/Window.h"
31#include "CEGUI/falagard/XMLEnumHelper.h"
32
33namespace CEGUI
34{
35
36template<typename T>
38{
39public:
40 //------------------------------------------------------------------------//
43 {}
44
45 //------------------------------------------------------------------------//
46 FormattingSetting(const String& property_name) :
48 d_propertySource(property_name)
49 {}
50
51 //------------------------------------------------------------------------//
52 FormattingSetting(T val) :
53 d_value(val)
54 {}
55
56 //------------------------------------------------------------------------//
57 T get(const Window& wnd) const
58 {
59 if (d_propertySource.empty())
60 return d_value;
61
63 wnd.getProperty(d_propertySource));
64 }
65
66 //------------------------------------------------------------------------//
67 void set(T val)
68 {
69 d_value = val;
70 d_propertySource.clear();
71 }
72
73 //------------------------------------------------------------------------//
74 T getValue() const
75 {
76 return d_value;
77 }
78
79 //------------------------------------------------------------------------//
80 const String& getPropertySource() const
81 {
82 return d_propertySource;
83 }
84
85 //------------------------------------------------------------------------//
86 void setPropertySource(const String& property_name)
87 {
88 d_propertySource = property_name;
89 }
90
91 //------------------------------------------------------------------------//
92 bool isFetchedFromProperty() const
93 {
94 return !d_propertySource.empty();
95 }
96
97 //------------------------------------------------------------------------//
98 void writeXMLToStream(XMLSerializer& xml_stream) const
99 {
100 writeXMLTagToStream(xml_stream);
101 writeXMLAttributesToStream(xml_stream);
102 xml_stream.closeTag();
103 }
104
105 virtual void writeXMLTagToStream(XMLSerializer& /*xml_stream*/) const;
106
107 virtual void writeXMLAttributesToStream(XMLSerializer& /*xml_stream*/) const;
108
109 //------------------------------------------------------------------------//
110 bool operator==(const FormattingSetting<T>& rhs) const
111 {
112 return d_value == rhs.d_value &&
113 d_propertySource == rhs.d_propertySource;
114 }
115
116 //------------------------------------------------------------------------//
117 bool operator!=(const FormattingSetting<T>& rhs) const
118 {
119 return !operator==(rhs);
120 }
121
122protected:
123 T d_value;
124 String d_propertySource;
125};
126
127template<typename T>
129{
130 // This does nothing and needs to be specialised or overridden
131}
132
133template<typename T>
134void FormattingSetting<T>::writeXMLAttributesToStream(XMLSerializer& /*xml_stream*/) const
135{
136 // This does nothing and needs to be specialised or overridden
137}
138
139template<> void CEGUIEXPORT FormattingSetting<VerticalFormatting>::writeXMLTagToStream(
140 XMLSerializer& xml_stream) const;
141template<> void CEGUIEXPORT FormattingSetting<VerticalFormatting>::writeXMLAttributesToStream(
142 XMLSerializer& xml_stream) const;
143template<> void CEGUIEXPORT FormattingSetting<HorizontalFormatting>::writeXMLTagToStream(
144 XMLSerializer& xml_stream) const;
145template<> void CEGUIEXPORT FormattingSetting<HorizontalFormatting>::writeXMLAttributesToStream(
146 XMLSerializer& xml_stream) const;
147template<> void CEGUIEXPORT FormattingSetting<VerticalTextFormatting>::writeXMLTagToStream(
148 XMLSerializer& xml_stream) const;
149template<> void CEGUIEXPORT FormattingSetting<VerticalTextFormatting>::writeXMLAttributesToStream(
150 XMLSerializer& xml_stream) const;
151template<> void CEGUIEXPORT FormattingSetting<HorizontalTextFormatting>::writeXMLTagToStream(
152 XMLSerializer& xml_stream) const;
153template<> void CEGUIEXPORT FormattingSetting<HorizontalTextFormatting>::writeXMLAttributesToStream(
154 XMLSerializer& xml_stream) const;
155}
156
157#endif
158
Definition XMLEnumHelper.h:37
Definition FormattingSetting.h:38
String getProperty(const String &name) const
Gets the current value of the specified Property.
String class used within the GUI system.
Definition String.h:64
bool empty(void) const
Returns true if the String is empty.
Definition String.h:633
void clear(void)
Removes all data from the String.
Definition String.h:2348
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition Window.h:151
Class used to create XML Document.
Definition XMLSerializer.h:87
XMLSerializer & closeTag(void)
Close the current tag.
Main namespace for Crazy Eddie's GUI Library.
Definition arch_overview.dox:1