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