source: GTP/trunk/App/Demos/Geom/OgreStuff/include/CEGUI/CEGUIRenderCache.h @ 1812

Revision 1812, 6.9 KB checked in by gumbau, 18 years ago (diff)
Line 
1/************************************************************************
2    filename:   CEGUIRenderCache.h
3    created:    Fri Jun 17 2005
4    author:     Paul D Turner <paul@cegui.org.uk>
5*************************************************************************/
6/*************************************************************************
7    Crazy Eddie's GUI System (http://www.cegui.org.uk)
8    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
9 
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2.1 of the License, or (at your option) any later version.
14 
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19 
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*************************************************************************/
24#ifndef _CEGUIRenderCache_h_
25#define _CEGUIRenderCache_h_
26
27#include "CEGUIVector.h"
28#include "CEGUIRect.h"
29#include "CEGUIImage.h"
30#include "CEGUIFont.h"
31#include <vector>
32
33
34#if defined(_MSC_VER)
35#       pragma warning(push)
36#       pragma warning(disable : 4251)
37#endif
38
39
40// Start of CEGUI namespace section
41namespace CEGUI
42{
43    /*!
44    \brief
45        Class that acts as a cache for images that need to be rendered.
46
47        This is in many ways an optimisation cache, it allows a full image redraw
48        to occur while limiting the amount of information that needs to be re-calculated.
49    \par
50        Basically, unless the actual images (or their size) change, or the colours (or alpha) change
51        then imagery cached in here will suffice for a full redraw.  The reasoning behind this is that
52        when some window underneath window 'X' changes, a full image redraw is required by the
53        renderer, however, since window 'X' is unchanged, performing a total recalculation of all
54        imagery is very wasteful, and so we use this cache to limit such waste.
55    \par
56        As another example, when a window is simply moved, there is no need to perform a total imagery
57        recalculation; we can still use the imagery cached here since it is position independant.
58    */
59    class CEGUIEXPORT RenderCache
60    {
61    public:
62        /*!
63        \brief
64            Constructor
65        */
66        RenderCache();
67
68        /*!
69        \brief
70            Destructor
71        */
72        ~RenderCache();
73
74        /*!
75        \brief
76            Return whether the cache contains anything to draw.
77
78        \return
79            - true if the cache contains information about images to be drawn.
80            - false if the cache is empty.
81        */
82        bool hasCachedImagery() const;
83
84        /*!
85        \brief
86            Send the contents of the cache to the Renderer.
87
88        \param basePos
89            Point that describes a screen offset that cached imagery will be rendered relative to.
90
91        \param baseZ
92            Z value that cached imagery will use as a base figure when calculating final z values.
93
94        \param clipper
95            Rect object describing a rect to which imagery will be clipped.
96
97        \return
98            Nothing
99        */
100        void render(const Point& basePos, float baseZ, const Rect& clipper) const;
101
102        /*!
103        \brief
104            Erase any stored image information.
105        */
106        void clearCachedImagery();
107
108        /*!
109        \brief
110            Add an image to the cache.
111
112        \param image
113            Image object to be cached.
114
115        \param destArea
116            Destination area over which the Image object will be rendered.  This area should be position
117            independant; so position (0,0) will be to top-left corner of whatever it is you're rendering
118            (like a Window for example).
119
120        \param zOffset
121            Zero based z offset for this image.  Allows imagery to be layered.
122
123        \param cols
124            ColourRect object describing the colours to be applied when rendering this image.
125
126        \return
127            Nothing
128        */
129        void cacheImage(const Image& image, const Rect& destArea, float zOffset, const ColourRect& cols, const Rect* clipper = 0, bool clipToDisplay = false);
130
131        /*!
132        \brief
133            Add a text to the cache.
134
135        \param text
136            String object to be cached.
137
138        \param font
139            Font to be used when rendering.
140
141        \param format
142            TextFormatting value specifying the formatting to use when rendering.
143
144        \param destArea
145            Destination area over which the Image object will be rendered.  This area should be position
146            independant; so position (0,0) will be to top-left corner of whatever it is you're rendering
147            (like a Window for example).
148
149        \param zOffset
150            Zero based z offset for this image.  Allows imagery to be layered.
151
152        \param cols
153            ColourRect object describing the colours to be applied when rendering this image.
154
155        \return
156            Nothing
157        */
158        void cacheText(const String& text, const Font* font, TextFormatting format, const Rect& destArea, float zOffset, const ColourRect& cols, const Rect* clipper = 0, bool clipToDisplay = false);
159
160    private:
161        /*!
162        \brief
163            internal struct that holds info about a single image to be drawn.
164        */
165        struct ImageInfo
166        {
167            const Image* source_image;
168            Rect target_area;
169            float z_offset;
170            ColourRect colours;
171            Rect customClipper;
172            bool usingCustomClipper;
173            bool clipToDisplay;
174        };
175
176        /*!
177        \brief
178            internal struct that holds info about text to be drawn.
179        */
180        struct TextInfo
181        {
182            String text;
183            const Font* source_font;
184            TextFormatting formatting;
185            Rect target_area;
186            float z_offset;
187            ColourRect colours;
188            Rect customClipper;
189            bool usingCustomClipper;
190            bool clipToDisplay;
191        };
192
193        typedef std::vector<ImageInfo>  ImageryList;
194        typedef std::vector<TextInfo>   TextList;
195
196        ImageryList d_cachedImages;     //!< Collection of ImageInfo structs.
197        TextList d_cachedTexts;         //!< Collection of TextInfo structs.
198    };
199
200} // End of  CEGUI namespace section
201
202
203#if defined(_MSC_VER)
204#       pragma warning(pop)
205#endif
206
207
208#endif  // end of guard _CEGUIRenderCache_h_
Note: See TracBrowser for help on using the repository browser.