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 "CEGUIRenderCache.h"
00025 #include "CEGUISystem.h"
00026 #include "CEGUIRenderer.h"
00027
00028
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
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
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 = ℑ
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 }