]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUISpriteBank.h
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / CGUISpriteBank.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_GUI_SPRITE_BANK_H_INCLUDED__\r
6 #define __C_GUI_SPRITE_BANK_H_INCLUDED__\r
7 \r
8 #include "IGUISpriteBank.h"\r
9 \r
10 namespace irr\r
11 {\r
12 \r
13 namespace video\r
14 {\r
15         class IVideoDriver;\r
16         class ITexture;\r
17 }\r
18 \r
19 namespace gui\r
20 {\r
21 \r
22         class IGUIEnvironment;\r
23 \r
24 //! Sprite bank interface.\r
25 class CGUISpriteBank : public IGUISpriteBank\r
26 {\r
27 public:\r
28 \r
29         CGUISpriteBank(IGUIEnvironment* env);\r
30         virtual ~CGUISpriteBank();\r
31 \r
32         core::array< core::rect<s32> >& getPositions() override;\r
33         core::array< SGUISprite >& getSprites() override;\r
34 \r
35         u32 getTextureCount() const override;\r
36         video::ITexture* getTexture(u32 index) const override;\r
37         void addTexture(video::ITexture* texture) override;\r
38         void setTexture(u32 index, video::ITexture* texture) override;\r
39 \r
40         //! Add the texture and use it for a single non-animated sprite.\r
41         s32 addTextureAsSprite(video::ITexture* texture) override;\r
42 \r
43         //! clears sprites, rectangles and textures\r
44         void clear() override;\r
45 \r
46         //! Draws a sprite in 2d with position and color\r
47         virtual void draw2DSprite(u32 index, const core::position2di& pos, const core::rect<s32>* clip=0,\r
48                                 const video::SColor& color= video::SColor(255,255,255,255),\r
49                                 u32 starttime=0, u32 currenttime=0, bool loop=true, bool center=false) override;\r
50 \r
51         //! Draws a sprite in 2d with destination rectangle and colors\r
52         virtual void draw2DSprite(u32 index, const core::rect<s32>& destRect,\r
53                         const core::rect<s32>* clip=0,\r
54                         const video::SColor * const colors=0,\r
55                         u32 timeTicks = 0,\r
56                         bool loop=true) override;\r
57 \r
58         //! Draws a sprite batch in 2d using an array of positions and a color\r
59         virtual void draw2DSpriteBatch(const core::array<u32>& indices, const core::array<core::position2di>& pos,\r
60                         const core::rect<s32>* clip=0,\r
61                         const video::SColor& color= video::SColor(255,255,255,255),\r
62                         u32 starttime=0, u32 currenttime=0,\r
63                         bool loop=true, bool center=false) override;\r
64 \r
65 protected:\r
66 \r
67         inline u32 getFrameNr(u32 index, u32 time, bool loop) const\r
68         {\r
69                 u32 frame = 0;\r
70                 if (Sprites[index].frameTime && Sprites[index].Frames.size() )\r
71                 {\r
72                         u32 f = (time / Sprites[index].frameTime);\r
73                         if (loop)\r
74                                 frame = f % Sprites[index].Frames.size();\r
75                         else\r
76                                 frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f;\r
77                 }\r
78                 return frame;\r
79         }\r
80 \r
81         struct SDrawBatch\r
82         {\r
83                 core::array<core::position2di> positions;\r
84                 core::array<core::recti> sourceRects;\r
85                 u32 textureNumber;\r
86         };\r
87 \r
88         core::array<SGUISprite> Sprites;\r
89         core::array< core::rect<s32> > Rectangles;\r
90         core::array<video::ITexture*> Textures;\r
91         IGUIEnvironment* Environment;\r
92         video::IVideoDriver* Driver;\r
93 \r
94 };\r
95 \r
96 } // end namespace gui\r
97 } // end namespace irr\r
98 \r
99 #endif // __C_GUI_SPRITE_BANK_H_INCLUDED__\r