Crazy Eddies GUI System  0.6.2
directfb-renderer.h
1 /***********************************************************************
2  filename: directfb-renderer.h
3  author: Keith Mok
4 *************************************************************************/
5 /***************************************************************************
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  ***************************************************************************/
25 #ifndef _directfbrenderer_h_
26 #define _directfbrenderer_h_
27 
28 #include "CEGUIBase.h"
29 #include <directfb.h>
30 
31 #include <vector>
32 #include <list>
33 
34 #include "CEGUIRenderer.h"
35 #include "CEGUITexture.h"
36 
37 
38 // Start of CEGUI namespace section
39 namespace CEGUI
40 {
41  /*************************************************************************
42  Forward refs
43  *************************************************************************/
44  class DirectfbTexture;
45  class ImageCodec;
46  class DynamicModule;
47 
52  class DirectfbRenderer : public Renderer
53  {
54  public:
63  DirectfbRenderer(IDirectFB *device, IDirectFBSurface *surface, ImageCodec* codec = 0);
64 
69  virtual ~DirectfbRenderer(void);
70 
71  // add's a quad to the list to be rendered
72  virtual void addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
73 
74  // perform final rendering for all queued renderable quads.
75  virtual void doRender(void);
76 
77  // clear the queue
78  virtual void clearRenderList(void);
79 
80 
96  virtual void setQueueingEnabled(bool setting) {d_queueing = setting;}
97 
98 
99  // create an empty texture
100  virtual Texture* createTexture(void);
101 
102  // create a texture and load it with the specified file.
103  virtual Texture* createTexture(const String& filename, const String& resourceGroup);
104 
105  // create a texture and set it to the specified size
106  virtual Texture* createTexture(float size);
107 
108  // destroy the given texture
109  virtual void destroyTexture(Texture* texture);
110 
111  // destroy all textures still active
112  virtual void destroyAllTextures(void);
113 
114  // return ptr to device
115  IDirectFB* getDevice(void) const {return d_device;}
116 
117 
125  virtual bool isQueueingEnabled(void) const {return d_queueing;}
126 
127 
135  virtual float getWidth(void) const {return d_display_area.getWidth();}
136 
137 
145  virtual float getHeight(void) const {return d_display_area.getHeight();}
146 
147 
155  virtual Size getSize(void) const {return d_display_area.getSize();}
156 
157 
166  virtual Rect getRect(void) const {return d_display_area;}
167 
168 
176  virtual uint getMaxTextureSize(void) const {return d_maxTextureSize;}
177 
178 
186  virtual uint getHorzScreenDPI(void) const {return 96;}
187 
188 
196  virtual uint getVertScreenDPI(void) const {return 96;}
197 
202  ImageCodec& getImageCodec(void);
203 
204 
209  void setImageCodec(const String& codecName);
210 
220  void setImageCodec(ImageCodec* codec);
221 
222 
227  static void setDefaultImageCodecName(const String& codecName);
228 
233  static const String& getDefaultImageCodecName();
234 
235 
236  private:
237  /************************************************************************
238  Implementation Constants
239  ************************************************************************/
240 
241  /*************************************************************************
242  Implementation Structs & classes
243  *************************************************************************/
248  struct RenderQuad
249  {
250  IDirectFBSurface *tex;
251  Rect position;
252  float z;
253  Rect texPosition;
254  ColourRect colours;
255  };
256 
257 
258  /*************************************************************************
259  Implementation Methods
260  *************************************************************************/
261  // render a quad directly to the display
262  void doRender(RenderQuad *quad);
263  void sortQuads(void);
264 
265  // setup image codec
266  void setupImageCodec(const String& codecName);
267 
268  // cleanup image codec
269  void cleanupImageCodec();
270 
271 
272  /*************************************************************************
273  Implementation Data
274  *************************************************************************/
275  // std sorting RenderQuad class
276  struct quadsorter
277  : public std::binary_function<RenderQuad*, RenderQuad*, bool>
278  {
279  bool operator()(const RenderQuad& _Left, const RenderQuad& _Right) const
280  {return (_Left.z > _Right.z);}
281  };
282 
283  // list ot quads we want to render
284  std::vector<RenderQuad> d_quadlist;
285 
286 
287  IDirectFBSurface *d_surface;
288  IDirectFB *d_device;
289  Rect d_display_area;
290  bool d_queueing;
291 
292  std::list<DirectfbTexture*> d_texturelist;
293  uint d_maxTextureSize;
294 
295  ImageCodec* d_imageCodec;
296  DynamicModule* d_imageCodecModule;
297 
298  static String d_defaultImageCodecName;
299 
300  };
301 
302 } // End of CEGUI namespace section
303 
304 #endif // end of guard _openglrenderer_h_