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/CEGUIFalImagerySection.h"
00025 #include "CEGUIPropertyHelper.h"
00026 #include <iostream>
00027
00028
00029 namespace CEGUI
00030 {
00031 ImagerySection::ImagerySection() :
00032 d_masterColours(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
00033 d_colourProperyIsRect(false)
00034 {}
00035
00036 ImagerySection::ImagerySection(const String& name) :
00037 d_name(name),
00038 d_masterColours(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
00039 d_colourProperyIsRect(false)
00040 {}
00041
00042 void ImagerySection::render(Window& srcWindow, float base_z, const CEGUI::ColourRect* modColours, const Rect* clipper, bool clipToDisplay) const
00043 {
00044
00045 ColourRect finalCols;
00046 initMasterColourRect(srcWindow, finalCols);
00047
00048 if (modColours)
00049 finalCols *= *modColours;
00050
00051 ColourRect* finalColsPtr = (finalCols.isMonochromatic() && finalCols.d_top_left.getARGB() == 0xFFFFFFFF) ? 0 : &finalCols;
00052
00053
00054 for(FrameList::const_iterator frame = d_frames.begin(); frame != d_frames.end(); ++frame)
00055 {
00056 (*frame).render(srcWindow, base_z, finalColsPtr, clipper, clipToDisplay);
00057 }
00058
00059 for(ImageryList::const_iterator image = d_images.begin(); image != d_images.end(); ++image)
00060 {
00061 (*image).render(srcWindow, base_z, finalColsPtr, clipper, clipToDisplay);
00062 }
00063
00064 for(TextList::const_iterator text = d_texts.begin(); text != d_texts.end(); ++text)
00065 {
00066 (*text).render(srcWindow, base_z, finalColsPtr, clipper, clipToDisplay);
00067 }
00068 }
00069
00070 void ImagerySection::render(Window& srcWindow, const Rect& baseRect, float base_z, const CEGUI::ColourRect* modColours, const Rect* clipper, bool clipToDisplay) const
00071 {
00072
00073 ColourRect finalCols;
00074 initMasterColourRect(srcWindow, finalCols);
00075
00076 if (modColours)
00077 finalCols *= *modColours;
00078
00079 ColourRect* finalColsPtr = (finalCols.isMonochromatic() && finalCols.d_top_left.getARGB() == 0xFFFFFFFF) ? 0 : &finalCols;
00080
00081
00082 for(FrameList::const_iterator frame = d_frames.begin(); frame != d_frames.end(); ++frame)
00083 {
00084 (*frame).render(srcWindow, baseRect, base_z, finalColsPtr, clipper, clipToDisplay);
00085 }
00086
00087 for(ImageryList::const_iterator image = d_images.begin(); image != d_images.end(); ++image)
00088 {
00089 (*image).render(srcWindow, baseRect, base_z, finalColsPtr, clipper, clipToDisplay);
00090 }
00091
00092 for(TextList::const_iterator text = d_texts.begin(); text != d_texts.end(); ++text)
00093 {
00094 (*text).render(srcWindow, baseRect, base_z, finalColsPtr, clipper, clipToDisplay);
00095 }
00096 }
00097
00098 void ImagerySection::addImageryComponent(const ImageryComponent& img)
00099 {
00100 d_images.push_back(img);
00101 }
00102
00103 void ImagerySection::clearImageryComponents()
00104 {
00105 d_images.clear();
00106 }
00107
00108 void ImagerySection::addTextComponent(const TextComponent& text)
00109 {
00110 d_texts.push_back(text);
00111 }
00112
00113 void ImagerySection::clearTextComponents()
00114 {
00115 d_texts.clear();
00116 }
00117
00118 void ImagerySection::clearFrameComponents()
00119 {
00120 d_frames.clear();
00121 }
00122
00123 void ImagerySection::addFrameComponent(const FrameComponent& frame)
00124 {
00125 d_frames.push_back(frame);
00126 }
00127
00128 const ColourRect& ImagerySection::getMasterColours() const
00129 {
00130 return d_masterColours;
00131 }
00132
00133 void ImagerySection::setMasterColours(const ColourRect& cols)
00134 {
00135 d_masterColours = cols;
00136 }
00137
00138 const String& ImagerySection::getName() const
00139 {
00140 return d_name;
00141 }
00142
00143 void ImagerySection::setMasterColoursPropertySource(const String& property)
00144 {
00145 d_colourPropertyName = property;
00146 }
00147
00148 void ImagerySection::setMasterColoursPropertyIsColourRect(bool setting)
00149 {
00150 d_colourProperyIsRect = setting;
00151 }
00152
00153 void ImagerySection::initMasterColourRect(const Window& wnd, ColourRect& cr) const
00154 {
00155
00156 if (!d_colourPropertyName.empty())
00157 {
00158
00159 if (d_colourProperyIsRect)
00160 {
00161 cr = PropertyHelper::stringToColourRect(wnd.getProperty(d_colourPropertyName));
00162 }
00163
00164 else
00165 {
00166 colour val(PropertyHelper::stringToColour(wnd.getProperty(d_colourPropertyName)));
00167 cr.d_top_left = val;
00168 cr.d_top_right = val;
00169 cr.d_bottom_left = val;
00170 cr.d_bottom_right = val;
00171 }
00172 }
00173
00174 else
00175 {
00176 cr = d_masterColours;
00177 }
00178 }
00179
00180 Rect ImagerySection::getBoundingRect(const Window& wnd) const
00181 {
00182 Rect compRect;
00183 Rect bounds(0, 0, 0, 0);
00184
00185
00186 for(FrameList::const_iterator frame = d_frames.begin(); frame != d_frames.end(); ++frame)
00187 {
00188 compRect = (*frame).getComponentArea().getPixelRect(wnd);
00189
00190 bounds.d_left = ceguimin(bounds.d_left, compRect.d_left);
00191 bounds.d_top = ceguimin(bounds.d_top, compRect.d_top);
00192 bounds.d_right = ceguimax(bounds.d_right, compRect.d_right);
00193 bounds.d_bottom = ceguimax(bounds.d_bottom, compRect.d_bottom);
00194 }
00195
00196 for(ImageryList::const_iterator image = d_images.begin(); image != d_images.end(); ++image)
00197 {
00198 compRect = (*image).getComponentArea().getPixelRect(wnd);
00199
00200 bounds.d_left = ceguimin(bounds.d_left, compRect.d_left);
00201 bounds.d_top = ceguimin(bounds.d_top, compRect.d_top);
00202 bounds.d_right = ceguimax(bounds.d_right, compRect.d_right);
00203 bounds.d_bottom = ceguimax(bounds.d_bottom, compRect.d_bottom);
00204 }
00205
00206 for(TextList::const_iterator text = d_texts.begin(); text != d_texts.end(); ++text)
00207 {
00208 compRect = (*text).getComponentArea().getPixelRect(wnd);
00209
00210 bounds.d_left = ceguimin(bounds.d_left, compRect.d_left);
00211 bounds.d_top = ceguimin(bounds.d_top, compRect.d_top);
00212 bounds.d_right = ceguimax(bounds.d_right, compRect.d_right);
00213 bounds.d_bottom = ceguimax(bounds.d_bottom, compRect.d_bottom);
00214 }
00215
00216 return bounds;
00217 }
00218
00219 Rect ImagerySection::getBoundingRect(const Window& wnd, const Rect& rect) const
00220 {
00221 Rect compRect;
00222 Rect bounds(0, 0, 0, 0);
00223
00224
00225 for(FrameList::const_iterator frame = d_frames.begin(); frame != d_frames.end(); ++frame)
00226 {
00227 compRect = (*frame).getComponentArea().getPixelRect(wnd, rect);
00228
00229 bounds.d_left = ceguimin(bounds.d_left, compRect.d_left);
00230 bounds.d_top = ceguimin(bounds.d_top, compRect.d_top);
00231 bounds.d_right = ceguimax(bounds.d_right, compRect.d_right);
00232 bounds.d_bottom = ceguimax(bounds.d_bottom, compRect.d_bottom);
00233 }
00234
00235 for(ImageryList::const_iterator image = d_images.begin(); image != d_images.end(); ++image)
00236 {
00237 compRect = (*image).getComponentArea().getPixelRect(wnd, rect);
00238
00239 bounds.d_left = ceguimin(bounds.d_left, compRect.d_left);
00240 bounds.d_top = ceguimin(bounds.d_top, compRect.d_top);
00241 bounds.d_right = ceguimax(bounds.d_right, compRect.d_right);
00242 bounds.d_bottom = ceguimax(bounds.d_bottom, compRect.d_bottom);
00243 }
00244
00245 for(TextList::const_iterator text = d_texts.begin(); text != d_texts.end(); ++text)
00246 {
00247 compRect = (*text).getComponentArea().getPixelRect(wnd, rect);
00248
00249 bounds.d_left = ceguimin(bounds.d_left, compRect.d_left);
00250 bounds.d_top = ceguimin(bounds.d_top, compRect.d_top);
00251 bounds.d_right = ceguimax(bounds.d_right, compRect.d_right);
00252 bounds.d_bottom = ceguimax(bounds.d_bottom, compRect.d_bottom);
00253 }
00254
00255 return bounds;
00256 }
00257
00258 void ImagerySection::writeXMLToStream(OutStream& out_stream) const
00259 {
00260
00261 out_stream << "<ImagerySection name=\"" << d_name << "\">" << std::endl;
00262
00263
00264 if (!d_colourPropertyName.empty())
00265 {
00266 if (d_colourProperyIsRect)
00267 out_stream << "<ColourRectProperty ";
00268 else
00269 out_stream << "<ColourProperty ";
00270
00271 out_stream << "name=\"" << d_colourPropertyName << "\" />" << std::endl;
00272 }
00273 else if (!d_masterColours.isMonochromatic() || d_masterColours.d_top_left != colour(1,1,1,1))
00274 {
00275 out_stream << "<Colours ";
00276 out_stream << "topLeft=\"" << PropertyHelper::colourToString(d_masterColours.d_top_left) << "\" ";
00277 out_stream << "topRight=\"" << PropertyHelper::colourToString(d_masterColours.d_top_right) << "\" ";
00278 out_stream << "bottomLeft=\"" << PropertyHelper::colourToString(d_masterColours.d_bottom_left) << "\" ";
00279 out_stream << "bottomRight=\"" << PropertyHelper::colourToString(d_masterColours.d_bottom_right) << "\" />" << std::endl;
00280 }
00281
00282
00283 for(FrameList::const_iterator frame = d_frames.begin(); frame != d_frames.end(); ++frame)
00284 {
00285 (*frame).writeXMLToStream(out_stream);
00286 }
00287
00288
00289 for(ImageryList::const_iterator image = d_images.begin(); image != d_images.end(); ++image)
00290 {
00291 (*image).writeXMLToStream(out_stream);
00292 }
00293
00294
00295 for(TextList::const_iterator text = d_texts.begin(); text != d_texts.end(); ++text)
00296 {
00297 (*text).writeXMLToStream(out_stream);
00298 }
00299
00300
00301 out_stream << "</ImagerySection>" << std::endl;
00302 }
00303
00304 }