Second try of my previous pull request, which was partially reverted due to caused crashes and memory leaks
This commit is contained in:
parent
69217bd03c
commit
3fc0d3be09
@ -42,6 +42,7 @@ IconButtonWidget::IconButtonWidget(ScaleMode scale_mode, const bool tab_stop,
|
||||
m_label = NULL;
|
||||
m_font = NULL;
|
||||
m_texture = NULL;
|
||||
m_deactivated_texture = NULL;
|
||||
m_highlight_texture = NULL;
|
||||
m_custom_aspect_ratio = 1.0f;
|
||||
|
||||
@ -270,6 +271,49 @@ void IconButtonWidget::unfocused(const int playerID, Widget* new_focus)
|
||||
m_label->setVisible(false);
|
||||
}
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
const video::ITexture* IconButtonWidget::getTexture()
|
||||
{
|
||||
if (Widget::isActivated())
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_deactivated_texture == NULL)
|
||||
m_deactivated_texture = getDeactivatedTexture(m_texture);
|
||||
return m_deactivated_texture;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
video::ITexture* IconButtonWidget::getDeactivatedTexture(video::ITexture* texture)
|
||||
{
|
||||
SColor c;
|
||||
u32 g;
|
||||
|
||||
video::IVideoDriver* driver = irr_driver->getVideoDriver();
|
||||
video::IImage* image = driver->createImageFromData (texture->getColorFormat(),
|
||||
texture->getSize(), texture->lock(), false);
|
||||
texture->unlock();
|
||||
|
||||
//Turn the image into grayscale
|
||||
for (u32 x = 0; x < image->getDimension().Width; x++)
|
||||
{
|
||||
for (u32 y = 0; y < image->getDimension().Height; y++)
|
||||
{
|
||||
c = image->getPixel(x, y);
|
||||
g = ((c.getRed() + c.getGreen() + c.getBlue()) / 3);
|
||||
c.set(std::max (0, (int)c.getAlpha() - 120), g, g, g);
|
||||
image->setPixel(x, y, c);
|
||||
}
|
||||
}
|
||||
|
||||
texture = driver->addTexture(texture->getName().getPath() + "_disabled", image);
|
||||
image->drop();
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void IconButtonWidget::setTexture(video::ITexture* texture)
|
||||
@ -277,6 +321,7 @@ void IconButtonWidget::setTexture(video::ITexture* texture)
|
||||
m_texture = texture;
|
||||
if (texture == NULL)
|
||||
{
|
||||
m_deactivated_texture = NULL;
|
||||
m_texture_w = 0;
|
||||
m_texture_h = 0;
|
||||
}
|
||||
|
@ -43,9 +43,11 @@ namespace GUIEngine
|
||||
{
|
||||
private:
|
||||
irr::video::ITexture* m_texture;
|
||||
irr::video::ITexture* m_deactivated_texture;
|
||||
irr::video::ITexture* m_highlight_texture;
|
||||
int m_texture_w, m_texture_h;
|
||||
|
||||
video::ITexture* getDeactivatedTexture(video::ITexture* texture);
|
||||
void setLabelFont();
|
||||
|
||||
public:
|
||||
@ -158,7 +160,7 @@ namespace GUIEngine
|
||||
virtual void unfocused(const int playerID, Widget* new_focus);
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the texture of this button. */
|
||||
const video::ITexture* getTexture() const { return m_texture; }
|
||||
const video::ITexture* getTexture();
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user