Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIFalSectionSpecification.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002     filename:   CEGUIFalSectionSpecification.cpp
00003     created:    Mon Jun 13 2005
00004     author:     Paul D Turner <paul@cegui.org.uk>
00005 *************************************************************************/
00006 /*************************************************************************
00007     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00008     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00009  
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014  
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019  
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Start of CEGUI namespace section
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             // get the imagery section object with the name we're set up to use
00055                         const ImagerySection* sect =
00056                                 &WidgetLookManager::getSingleton().getWidgetLook(d_owner).getImagerySection(d_sectionName);
00057 
00058             // decide what colours are to be used
00059             ColourRect finalColours;
00060             initColourRectForOverride(srcWindow, finalColours);
00061             finalColours.modulateAlpha(srcWindow.getEffectiveAlpha());
00062 
00063             if (modcols)
00064                 finalColours *= *modcols;
00065 
00066             // render the imagery section
00067             sect->render(srcWindow, base_z, &finalColours, clipper, clipToDisplay);
00068         }
00069         // do nothing here, errors are non-faltal and are logged for debugging purposes.
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             // get the imagery section object with the name we're set up to use
00079             const ImagerySection* sect =
00080                 &WidgetLookManager::getSingleton().getWidgetLook(d_owner).getImagerySection(d_sectionName);
00081 
00082             // decide what colours are to be used
00083             ColourRect finalColours;
00084             initColourRectForOverride(srcWindow, finalColours);
00085             finalColours.modulateAlpha(srcWindow.getEffectiveAlpha());
00086 
00087             if (modcols)
00088                 finalColours *= *modcols;
00089 
00090             // render the imagery section
00091             sect->render(srcWindow, baseRect, base_z, &finalColours, clipper, clipToDisplay);
00092         }
00093         // do nothing here, errors are non-faltal and are logged for debugging purposes.
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         // if no override set
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         // if override comes via a colour property
00145         else if (!d_colourPropertyName.empty())
00146         {
00147             // if property accesses a ColourRect
00148             if (d_colourProperyIsRect)
00149             {
00150                 cr = PropertyHelper::stringToColourRect(wnd.getProperty(d_colourPropertyName));
00151             }
00152             // property accesses a colour
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         // override is an explicitly defined ColourRect.
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             // terminate opening tag
00186             out_stream << ">" << std::endl;
00187 
00188             // output modulative colours for this section
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             // output closing section tag
00208             out_stream << "</Section>" << std::endl;
00209         }
00210         else
00211         {
00212             // no sub elements, just terminate opening tag
00213             out_stream << " />" << std::endl;
00214         }
00215     }
00216 
00217 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:31 2005 for Crazy Eddies GUI System by  doxygen 1.4.3