Crazy Eddies GUI System  0.6.2
irrlichtrenderer.h
1 /***********************************************************************
2  filename: irrlichtrenderer.h
3  created: 20/7/2004
4  author: Thomas Suter
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUI_IrrlichtRenderer_h_
29 #define _CEGUI_IrrlichtRenderer_h_
30 
31 #include "IrrlichtRendererDef.h"
32 #include "irrlichttexture.h"
33 #include "IrrlichtResourceProvider.h"
34 
35 #include "CEGUIRenderer.h"
36 #include "CEGUIInputEvent.h"
37 
38 #include <irrlicht.h>
39 
40 #include <vector>
41 #include <algorithm>
42 
43 #if defined(_MSC_VER)
44 # pragma warning(push)
45 # pragma warning(disable : 4251)
46 #endif
47 
48 namespace CEGUI
49 {
50 
51  class EventPusher;
52 
58  class IRRLICHT_GUIRENDERER_API IrrlichtRenderer: public Renderer
59  {
60  public:
61 
72  IrrlichtRenderer(irr::IrrlichtDevice* dev,bool bWithIrrlichtResourceProvicer=false);
73 
75  virtual ~IrrlichtRenderer();
76 
77 
81  virtual ResourceProvider* createResourceProvider(void);
82 
84  bool OnEvent(const irr::SEvent& event);
85 
86 
87  /*************************************************************************
88  Abstract interface methods
89  *************************************************************************/
115  virtual void addQuad(const Rect& dest_rect, float z, const Texture* tex,
116  const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
117 
118 
128  virtual void doRender(void);
129 
130 
138  virtual void clearRenderList(void);
139 
140 
156  virtual void setQueueingEnabled(bool setting);
157 
158 
167  virtual Texture* createTexture(void);
168 
169 
189  virtual Texture* createTexture(const String& filename, const String& resourceGroup);
190 
191 
207  virtual Texture* createTexture(float size);
208 
209 
220  virtual void destroyTexture(Texture* texture);
221 
222 
230  virtual void destroyAllTextures(void);
231 
232 
240  virtual bool isQueueingEnabled(void) const;
241 
242 
250  virtual float getWidth(void) const;
251 
252 
260  virtual float getHeight(void) const;
261 
262 
270  virtual Size getSize(void) const;
271 
272 
281  virtual Rect getRect(void) const;
282 
283 
291  virtual uint getMaxTextureSize(void) const;
292 
293 
301  virtual uint getHorzScreenDPI(void) const;
302 
303 
311  virtual uint getVertScreenDPI(void) const;
312 
327  void setDisplaySize(const Size& sz);
328 
329  private:
330 
331  // the irrlicht device
332  irr::IrrlichtDevice* device;
333  // video driver
334  irr::video::IVideoDriver* driver;
335  // window width,height
336  irr::core::dimension2d<irr::s32> resolution;
337  // screen resolution
338  irr::core::dimension2d<irr::s32> screensize;
339 
340  // is queueing enabled
341  bool bQueuingEnabled;
342  // is quad queue sorted
343  bool bSorted;
344  // enable irrlicht resource provider
345  bool bWithIrrlichtResourceProvicer;
346 
347  // quad structure used for rendering the gui
348  struct RenderQuad
349  {
350  RenderQuad(){};
351 
352  RenderQuad(float zVal,
353  const irr::core::rect<irr::s32>& target,
354  const irr::core::rect<irr::s32>& source,
355  ColourRect col,const Texture*t)
356  :z(zVal),dst(target),src(source),colours(col){
357  tex=(IrrlichtTexture*)t;
358  };
359 
360  float z;
361  irr::core::rect<irr::s32> dst;
362  irr::core::rect<irr::s32> src;
363  ColourRect colours;
364  IrrlichtTexture* tex;
365  };
366 
367  RenderQuad dummyQuad;
368 
369  // std sorting RenderQuad class
370  struct quadsorter
371  : public std::binary_function<RenderQuad*, RenderQuad*, bool>
372  {
373  bool operator()(const RenderQuad& _Left, const RenderQuad& _Right) const
374  {return (_Left.z > _Right.z);}
375  };
376 
377  // list ot quads we want to render
378  std::vector<RenderQuad> renderlist;
379 
380  // list of textures used for rendering
381  std::vector<IrrlichtTexture*> textures;
382 
383  // sort the quads in the renderlist
384  void sortQuads();
385 
386  // render the quad
387  void doRender(RenderQuad& quad);
388 
389  // print some debug output
390  void print(RenderQuad& quad);
391 
392  // convert cegui colour to irrlicht scolor
393  inline irr::video::SColor toIrrlichtColor(CEGUI::ulong cecolor);
394  irr::video::SColor colors[4];
395 
396 
397 
398  EventPusher* eventpusher;
399 
400  };
401 
402 } // End of CEGUI namespace section
403 
404 #if defined(_MSC_VER)
405 # pragma warning(pop)
406 #endif
407 
408 #endif