aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImageList.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImageList.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImageList.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImageList.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImageList.cpp
new file mode 100644
index 0000000..e02030d
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImageList.cpp
@@ -0,0 +1,93 @@
1// This file is part of the "Irrlicht Engine".
2// written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de
3// modified by Thomas Alten
4
5#include "CGUIImageList.h"
6
7
8namespace irr
9{
10namespace gui
11{
12
13//! constructor
14CGUIImageList::CGUIImageList( video::IVideoDriver* driver )
15 : Driver( driver ),
16 Texture( 0 ),
17 ImageCount( 0 ),
18 ImageSize( 0, 0 ),
19 ImagesPerRow( 0 ),
20 UseAlphaChannel( false )
21{
22 #ifdef _DEBUG
23 setDebugName( "CGUIImageList" );
24 #endif
25
26 if( Driver )
27 {
28 Driver->grab();
29 }
30}
31
32
33
34//! destructor
35CGUIImageList::~CGUIImageList()
36{
37 if( Driver )
38 {
39 Driver->drop();
40 }
41
42 if( Texture )
43 {
44 Texture->drop();
45 }
46}
47
48
49//! Creates the image list from texture.
50bool CGUIImageList::createImageList(video::ITexture* texture,
51 core::dimension2d<s32> imageSize,
52 bool useAlphaChannel)
53{
54 if( !texture )
55 {
56 return false;
57 }
58
59 Texture = texture;
60 Texture->grab();
61
62 ImageSize = imageSize;
63
64 ImagesPerRow = Texture->getSize().Width / ImageSize.Width;
65 ImageCount = ImagesPerRow * Texture->getSize().Height / ImageSize.Height;
66
67 UseAlphaChannel = useAlphaChannel;
68
69 return true;
70}
71
72//! Draws an image and clips it to the specified rectangle if wanted
73void CGUIImageList::draw( s32 index, const core::position2d<s32>& destPos,
74 const core::rect<s32>* clip /*= 0*/ )
75{
76 core::rect<s32> sourceRect;
77
78 if( !Driver || index < 0 || index >= ImageCount )
79 {
80 return;
81 }
82
83 sourceRect.UpperLeftCorner.X = ( index % ImagesPerRow ) * ImageSize.Width;
84 sourceRect.UpperLeftCorner.Y = ( index / ImagesPerRow ) * ImageSize.Height;
85 sourceRect.LowerRightCorner.X = sourceRect.UpperLeftCorner.X + ImageSize.Width;
86 sourceRect.LowerRightCorner.Y = sourceRect.UpperLeftCorner.Y + ImageSize.Height;
87
88 Driver->draw2DImage( Texture, destPos, sourceRect, clip,
89 video::SColor( 255, 255, 255, 255 ), UseAlphaChannel );
90}
91
92} // end namespace gui
93} // end namespace irr