00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "falagard/CEGUIFalSectionSpecification.h"
00025 #include "falagard/CEGUIFalImagerySection.h"
00026 #include "falagard/CEGUIFalWidgetLookFeel.h"
00027 #include "falagard/CEGUIFalWidgetLookManager.h"
00028 #include "CEGUIExceptions.h"
00029 #include "CEGUIPropertyHelper.h"
00030 #include <iostream>
00031
00032
00033 namespace CEGUI
00034 {
00035 SectionSpecification::SectionSpecification(const String& owner, const String& sectionName) :
00036 d_owner(owner),
00037 d_sectionName(sectionName),
00038 d_usingColourOverride(false),
00039 d_colourProperyIsRect(false)
00040 {}
00041
00042 SectionSpecification::SectionSpecification(const String& owner, const String& sectionName, const ColourRect& cols) :
00043 d_owner(owner),
00044 d_sectionName(sectionName),
00045 d_coloursOverride(cols),
00046 d_usingColourOverride(true),
00047 d_colourProperyIsRect(false)
00048 {}
00049
00050 void SectionSpecification::render(Window& srcWindow, float base_z, const ColourRect* modcols, const Rect* clipper, bool clipToDisplay) const
00051 {
00052 try
00053 {
00054
00055 const ImagerySection* sect =
00056 &WidgetLookManager::getSingleton().getWidgetLook(d_owner).getImagerySection(d_sectionName);
00057
00058
00059 ColourRect finalColours;
00060 initColourRectForOverride(srcWindow, finalColours);
00061 finalColours.modulateAlpha(srcWindow.getEffectiveAlpha());
00062
00063 if (modcols)
00064 finalColours *= *modcols;
00065
00066
00067 sect->render(srcWindow, base_z, &finalColours, clipper, clipToDisplay);
00068 }
00069
00070 catch (Exception)
00071 {}
00072 }
00073
00074 void SectionSpecification::render(Window& srcWindow, const Rect& baseRect, float base_z, const ColourRect* modcols, const Rect* clipper, bool clipToDisplay) const
00075 {
00076 try
00077 {
00078
00079 const ImagerySection* sect =
00080 &WidgetLookManager::getSingleton().getWidgetLook(d_owner).getImagerySection(d_sectionName);
00081
00082
00083 ColourRect finalColours;
00084 initColourRectForOverride(srcWindow, finalColours);
00085 finalColours.modulateAlpha(srcWindow.getEffectiveAlpha());
00086
00087 if (modcols)
00088 finalColours *= *modcols;
00089
00090
00091 sect->render(srcWindow, baseRect, base_z, &finalColours, clipper, clipToDisplay);
00092 }
00093
00094 catch (Exception)
00095 {}
00096 }
00097
00098 const String& SectionSpecification::getOwnerWidgetLookFeel() const
00099 {
00100 return d_owner;
00101 }
00102
00103 const String& SectionSpecification::getSectionName() const
00104 {
00105 return d_sectionName;
00106 }
00107
00108 const ColourRect& SectionSpecification::getOverrideColours() const
00109 {
00110 return d_coloursOverride;
00111 }
00112
00113 void SectionSpecification::setOverrideColours(const ColourRect& cols)
00114 {
00115 d_coloursOverride = cols;
00116 }
00117
00118 bool SectionSpecification::isUsingOverrideColours() const
00119 {
00120 return d_usingColourOverride;
00121 }
00122
00123 void SectionSpecification::setUsingOverrideColours(bool setting)
00124 {
00125 d_usingColourOverride = setting;
00126 }
00127
00128 void SectionSpecification::setOverrideColoursPropertySource(const String& property)
00129 {
00130 d_colourPropertyName = property;
00131 }
00132
00133 void SectionSpecification::initColourRectForOverride(const Window& wnd, ColourRect& cr) const
00134 {
00135
00136 if (!d_usingColourOverride)
00137 {
00138 colour val(1,1,1,1);
00139 cr.d_top_left = val;
00140 cr.d_top_right = val;
00141 cr.d_bottom_left = val;
00142 cr.d_bottom_right = val;
00143 }
00144
00145 else if (!d_colourPropertyName.empty())
00146 {
00147
00148 if (d_colourProperyIsRect)
00149 {
00150 cr = PropertyHelper::stringToColourRect(wnd.getProperty(d_colourPropertyName));
00151 }
00152
00153 else
00154 {
00155 colour val(PropertyHelper::stringToColour(wnd.getProperty(d_colourPropertyName)));
00156 cr.d_top_left = val;
00157 cr.d_top_right = val;
00158 cr.d_bottom_left = val;
00159 cr.d_bottom_right = val;
00160 }
00161 }
00162
00163 else
00164 {
00165 cr = d_coloursOverride;
00166 }
00167 }
00168
00169 void SectionSpecification::setOverrideColoursPropertyIsColourRect(bool setting)
00170 {
00171 d_colourProperyIsRect = setting;
00172 }
00173
00174 void SectionSpecification::writeXMLToStream(OutStream& out_stream) const
00175 {
00176 out_stream << "<Section ";
00177
00178 if (!d_owner.empty())
00179 out_stream << "look=\"" << d_owner << "\" ";
00180
00181 out_stream << "section=\"" << d_sectionName << "\"";
00182
00183 if (d_usingColourOverride)
00184 {
00185
00186 out_stream << ">" << std::endl;
00187
00188
00189 if (!d_colourPropertyName.empty())
00190 {
00191 if (d_colourProperyIsRect)
00192 out_stream << "<ColourRectProperty ";
00193 else
00194 out_stream << "<ColourProperty ";
00195
00196 out_stream << "name=\"" << d_colourPropertyName << "\" />" << std::endl;
00197 }
00198 else if (!d_coloursOverride.isMonochromatic() || d_coloursOverride.d_top_left != colour(1,1,1,1))
00199 {
00200 out_stream << "<Colours ";
00201 out_stream << "topLeft=\"" << PropertyHelper::colourToString(d_coloursOverride.d_top_left) << "\" ";
00202 out_stream << "topRight=\"" << PropertyHelper::colourToString(d_coloursOverride.d_top_right) << "\" ";
00203 out_stream << "bottomLeft=\"" << PropertyHelper::colourToString(d_coloursOverride.d_bottom_left) << "\" ";
00204 out_stream << "bottomRight=\"" << PropertyHelper::colourToString(d_coloursOverride.d_bottom_right) << "\" />" << std::endl;
00205 }
00206
00207
00208 out_stream << "</Section>" << std::endl;
00209 }
00210 else
00211 {
00212
00213 out_stream << " />" << std::endl;
00214 }
00215 }
00216
00217 }