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

CEGUIRenderCache.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002     filename:   CEGUIRenderCache.cpp
00003     created:    Fri Jun 17 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 "CEGUIRenderCache.h"
00025 #include "CEGUISystem.h"
00026 #include "CEGUIRenderer.h"
00027 
00028 // Start of CEGUI namespace section
00029 namespace CEGUI
00030 {
00031     RenderCache::RenderCache()
00032     {}
00033 
00034     RenderCache::~RenderCache()
00035     {}
00036 
00037     bool RenderCache::hasCachedImagery() const
00038     {
00039         return !(d_cachedImages.empty() && d_cachedTexts.empty());
00040     }
00041 
00042     void RenderCache::render(const Point& basePos, float baseZ, const Rect& clipper) const
00043     {
00044         Rect displayArea(System::getSingleton().getRenderer()->getRect());
00045         Rect custClipper;
00046         const Rect* finalClipper;
00047         Rect finalRect;
00048 
00049         // Send all cached images to renderer.
00050         for(ImageryList::const_iterator image = d_cachedImages.begin(); image != d_cachedImages.end(); ++image)
00051         {
00052             if ((*image).usingCustomClipper)
00053             {
00054                 custClipper = (*image).customClipper;
00055                 custClipper.offset(basePos);
00056                 custClipper = (*image).clipToDisplay ? displayArea.getIntersection(custClipper) : clipper.getIntersection(custClipper);
00057                 finalClipper = &custClipper;
00058             }
00059             else
00060             {
00061                 finalClipper = (*image).clipToDisplay ? &displayArea : &clipper;
00062             }
00063 
00064             finalRect = (*image).target_area;
00065             finalRect.offset(basePos);
00066             (*image).source_image->draw(finalRect, baseZ + (*image).z_offset, *finalClipper, (*image).colours);
00067         }
00068 
00069         // send all cached texts to renderer.
00070         for(TextList::const_iterator text = d_cachedTexts.begin(); text != d_cachedTexts.end(); ++text)
00071         {
00072             if ((*text).usingCustomClipper)
00073             {
00074                 custClipper = (*text).customClipper;
00075                 custClipper.offset(basePos);
00076                 custClipper = (*text).clipToDisplay ? displayArea.getIntersection(custClipper) : clipper.getIntersection(custClipper);
00077                 finalClipper = &custClipper;
00078             }
00079             else
00080             {
00081                 finalClipper = (*text).clipToDisplay ? &displayArea : &clipper;
00082             }
00083 
00084             finalRect = (*text).target_area;
00085             finalRect.offset(basePos);
00086             (*text).source_font->drawText((*text).text, finalRect, baseZ + (*text).z_offset, *finalClipper, (*text).formatting, (*text).colours);
00087         }
00088 
00089     }
00090 
00091     void RenderCache::clearCachedImagery()
00092     {
00093         d_cachedImages.clear();
00094         d_cachedTexts.clear();
00095     }
00096 
00097     void RenderCache::cacheImage(const Image& image, const Rect& destArea, float zOffset, const ColourRect& cols, const Rect* clipper, bool clipToDisplay)
00098     {
00099         ImageInfo imginf;
00100         imginf.source_image = &image;
00101         imginf.target_area  = destArea;
00102         imginf.z_offset     = zOffset;
00103         imginf.colours      = cols;
00104         imginf.clipToDisplay = clipToDisplay;
00105 
00106         if (clipper)
00107         {
00108             imginf.customClipper = *clipper;
00109             imginf.usingCustomClipper = true;
00110         }
00111         else
00112         {
00113             imginf.usingCustomClipper = false;
00114         }
00115 
00116         d_cachedImages.push_back(imginf);
00117     }
00118 
00119     void RenderCache::cacheText(const String& text, const Font* font, TextFormatting format, const Rect& destArea, float zOffset, const ColourRect& cols, const Rect* clipper, bool clipToDisplay)
00120     {
00121         TextInfo txtinf;
00122         txtinf.text         = text;
00123         txtinf.source_font  = font;
00124         txtinf.formatting   = format;
00125         txtinf.target_area  = destArea;
00126         txtinf.z_offset     = zOffset;
00127         txtinf.colours      = cols;
00128         txtinf.clipToDisplay = clipToDisplay;
00129 
00130         if (clipper)
00131         {
00132             txtinf.customClipper = *clipper;
00133             txtinf.usingCustomClipper = true;
00134         }
00135         else
00136         {
00137             txtinf.usingCustomClipper = false;
00138         }
00139 
00140         d_cachedTexts.push_back(txtinf);
00141     }
00142 
00143 
00144 } // End of  CEGUI namespace section

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