2023-10-03 20:37:00 +02:00
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de
|
|
|
|
// modified by Thomas Alten
|
|
|
|
|
|
|
|
#include "CGUIImageList.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace gui
|
|
|
|
{
|
|
|
|
|
|
|
|
//! constructor
|
2024-03-20 19:35:52 +01:00
|
|
|
CGUIImageList::CGUIImageList(video::IVideoDriver *driver) :
|
|
|
|
Driver(driver),
|
|
|
|
Texture(0),
|
|
|
|
ImageCount(0),
|
|
|
|
ImageSize(0, 0),
|
|
|
|
ImagesPerRow(0),
|
|
|
|
UseAlphaChannel(false)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("CGUIImageList");
|
|
|
|
#endif
|
2023-10-03 20:37:00 +02:00
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Driver) {
|
2023-10-03 20:37:00 +02:00
|
|
|
Driver->grab();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
CGUIImageList::~CGUIImageList()
|
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Driver) {
|
2023-10-03 20:37:00 +02:00
|
|
|
Driver->drop();
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (Texture) {
|
2023-10-03 20:37:00 +02:00
|
|
|
Texture->drop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Creates the image list from texture.
|
2024-03-20 19:35:52 +01:00
|
|
|
bool CGUIImageList::createImageList(video::ITexture *texture,
|
|
|
|
core::dimension2d<s32> imageSize,
|
|
|
|
bool useAlphaChannel)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!texture) {
|
2023-10-03 20:37:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Texture = texture;
|
|
|
|
Texture->grab();
|
|
|
|
|
|
|
|
ImageSize = imageSize;
|
|
|
|
|
|
|
|
ImagesPerRow = Texture->getSize().Width / ImageSize.Width;
|
|
|
|
ImageCount = ImagesPerRow * Texture->getSize().Height / ImageSize.Height;
|
|
|
|
|
|
|
|
UseAlphaChannel = useAlphaChannel;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Draws an image and clips it to the specified rectangle if wanted
|
2024-03-20 19:35:52 +01:00
|
|
|
void CGUIImageList::draw(s32 index, const core::position2d<s32> &destPos,
|
|
|
|
const core::rect<s32> *clip /*= 0*/)
|
2023-10-03 20:37:00 +02:00
|
|
|
{
|
|
|
|
core::rect<s32> sourceRect;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
if (!Driver || index < 0 || index >= ImageCount) {
|
2023-10-03 20:37:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
sourceRect.UpperLeftCorner.X = (index % ImagesPerRow) * ImageSize.Width;
|
|
|
|
sourceRect.UpperLeftCorner.Y = (index / ImagesPerRow) * ImageSize.Height;
|
2023-10-03 20:37:00 +02:00
|
|
|
sourceRect.LowerRightCorner.X = sourceRect.UpperLeftCorner.X + ImageSize.Width;
|
|
|
|
sourceRect.LowerRightCorner.Y = sourceRect.UpperLeftCorner.Y + ImageSize.Height;
|
|
|
|
|
2024-03-20 19:35:52 +01:00
|
|
|
Driver->draw2DImage(Texture, destPos, sourceRect, clip,
|
|
|
|
video::SColor(255, 255, 255, 255), UseAlphaChannel);
|
2023-10-03 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace gui
|
|
|
|
} // end namespace irr
|