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