IGUIEnvironment::addImage() Image size
IGUIEnvironment::addImage() Image size
Hi, is there a way to easily change the size of an Image created with the method IGUIEnvironment::addImage()? I already searched the forums and found that texture resize post, but i think thats way to much effort. It should be as easy as in the driver method draw2DImage where you can specify the size.
As you noticed, the current IGUIImage interface does not provide a mechanism for resizing the image. I see three choices.
Travis
- Patch the existing CGUIImage implementation
- Make your own CGUIImage implementation that is a copy of CGUIImage and fixes the problem.
- Make direct calls to draw2DImage
Code: Select all
driver->draw2DImage(Texture, RelativeRect,
core::rect<s32>(core::position2d<s32>(0,0), Texture->getOriginalSize()),
&AbsoluteClippingRect, 0, UseAlphaChannel);
Ok I made a class that makes resizing possible.
If anyone is interrested:
If anyone has suggestions to make it better Id be glad to hear them.
If anyone is interrested:
Code: Select all
//************************************************
//HEADER
#ifndef IRRDYNIMAGE
#define IRRDYNIMAGE
#include "main.h"
class IrrDynImage : public irr::gui::IGUIImage
{
private:
irr::video::ITexture* Texture;
bool UseAlphaChannel;
public:
IrrDynImage(irr::gui::IGUIEnvironment* Environment, IGUIElement* Parent, irr::core::rect<irr::s32> Rectangle,
irr::s32 ID = -1, irr::video::ITexture* Image = 0, bool useAlphaChannel = true, const wchar_t* Text = 0);
~IrrDynImage();
void setImage(irr::video::ITexture* image);
void setUseAlphaChannel(bool use = true);
void draw(void);
};
#endif
//************************************************
//CPP
#include "irrdynimage.h"
//! constructor
IrrDynImage::IrrDynImage(irr::gui::IGUIEnvironment* Environment, IGUIElement* Parent, irr::core::rect<irr::s32> Rectangle,
irr::s32 ID, irr::video::ITexture* Image, bool useAlphaChannel, const wchar_t* Text)
: IGUIImage(Environment, Parent, ID, Rectangle), Texture(0), UseAlphaChannel(false)
{
setImage(Image);
setUseAlphaChannel(useAlphaChannel);
setText(Text);
drop();
#ifdef _DEBUG
setDebugName("CGUIImage");
#endif
}
//! destructor
IrrDynImage::~IrrDynImage()
{
if (Texture)
Texture->drop();
}
//! sets an image
void IrrDynImage::setImage(irr::video::ITexture* image)
{
if (Texture)
Texture->drop();
Texture = image;
if (Texture)
Texture->grab();
}
//! draws the element and its children
void IrrDynImage::draw()
{
if (!IsVisible)
return;
irr::gui::IGUISkin* skin = Environment->getSkin();
irr::video::IVideoDriver* driver = Environment->getVideoDriver();
if (Texture)
driver->draw2DImage(Texture, AbsoluteRect,
irr::core::rect<irr::s32>(irr::core::position2d<irr::s32>(0,0), Texture->getOriginalSize()),
&AbsoluteClippingRect, 0, UseAlphaChannel);
else
driver->draw2DRectangle(skin->getColor(irr::gui::EGDC_3D_DARK_SHADOW), AbsoluteRect, &AbsoluteClippingRect);
IGUIElement::draw();
}
//! sets if the image should use its alpha channel to draw itself
void IrrDynImage::setUseAlphaChannel(bool use)
{
UseAlphaChannel = use;
}
//*****************************************
//Example:
Elements[i] = new IrrDynImage(Env, Parent, irr::core::rect<irr::s32>(0,0,100,100), ID, Driver->getTexture(Image.Source), UseAlpha, Text);
//instead of
Elements[i] = Env->addImage(blah);