SuperTuxKart
CGUISpriteBank.hpp
1 // Copyright (C) 2002-2015 Nikolaus Gebhardt, modified by Marianne Gagnon
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __C_GUI_MODIFIED_SPRITE_BANK_H_INCLUDED__
6 #define __C_GUI_MODIFIED_SPRITE_BANK_H_INCLUDED__
7 
8 #include "IrrCompileConfig.h"
9 #ifdef _IRR_COMPILE_WITH_GUI_
10 #include <cassert>
11 #include "IGUISpriteBank.h"
12 #include "utils/leak_check.hpp"
13 
14 namespace irr
15 {
16 
17 namespace video
18 {
19  class IVideoDriver;
20  class ITexture;
21 }
22 
23 namespace gui
24 {
25 
26  class IGUIEnvironment;
27 
29 class STKModifiedSpriteBank : public IGUISpriteBank
30 {
31 public:
32 
33  LEAK_CHECK()
34 
35  STKModifiedSpriteBank(IGUIEnvironment* env);
36  virtual ~STKModifiedSpriteBank();
37 
38  virtual core::array< core::rect<s32> >& getPositions();
39  virtual core::array< SGUISprite >& getSprites();
40 
41  virtual u32 getTextureCount() const;
42  virtual video::ITexture* getTexture(u32 index) const;
43  virtual void addTexture(video::ITexture* texture);
44  virtual void setTexture(u32 index, video::ITexture* texture);
45 
47  virtual s32 addTextureAsSprite(video::ITexture* texture);
48 
50  virtual void clear();
51 
53  virtual void draw2DSprite(u32 index, const core::position2di& pos, const core::rect<s32>* clip=0,
54  const video::SColor& color= video::SColor(255,255,255,255),
55  u32 starttime=0, u32 currenttime=0, bool loop=true, bool center=false);
56 
58  virtual void draw2DSpriteBatch(const core::array<u32>& indices, const core::array<core::position2di>& pos,
59  const core::rect<s32>* clip=0,
60  const video::SColor& color= video::SColor(255,255,255,255),
61  u32 starttime=0, u32 currenttime=0,
62  bool loop=true, bool center=false);
63 
64  void setScale(float scale)
65  {
66  assert( m_magic_number == 0xCAFEC001 );
67  m_scale = scale;
68  }
69 
70  void setFixedScale(float scale)
71  { m_fixed_scale = scale; }
72 
73  void setTargetIconSize(int width, int height)
74  { m_target_icon_size = core::dimension2du(width, height); }
75 
76 protected:
77 
78  // this object was getting access after being freed, I wanna see when/why
79  unsigned int m_magic_number;
80 
81  float m_scale;
82  float m_fixed_scale;
83 
84  struct SDrawBatch
85  {
86  core::array<core::position2di> positions;
87  core::array<core::recti> sourceRects;
88  u32 textureNumber;
89  };
90 
91  core::dimension2du m_target_icon_size;
92  //FIXME: ugly hack to work around irrLicht limitations, see STKModifiedSpriteBank::getPositions()
93  // for all the gory details.
94  core::array< core::rect<s32> > copy;
95 
96  core::array<SGUISprite> Sprites;
97  core::array< core::rect<s32> > Rectangles;
98  core::array<video::ITexture*> Textures;
99  IGUIEnvironment* Environment;
100  video::IVideoDriver* Driver;
101 
102  s32 getScaledWidth(s32 width) const;
103  s32 getScaledHeight(s32 height) const;
104 };
105 
106 } // end namespace gui
107 } // end namespace irr
108 
109 #endif // _IRR_COMPILE_WITH_GUI_
110 
111 #endif // __C_GUI_SPRITE_BANK_H_INCLUDED__
112