Set Color of Texture

Started by ultra, 20 May 2016, 14:08:06

ultra

Hello everybody,

I want to set the HoverTexture of a button to be the same as the NormalTexture but in a different color.
Unfortunately, the texture seems to remain unchanged on hovering (The hover event is handled properly, I tried with a different texture ;) ).
How can I get a texture colored?

Code (cpp) Select

tgui::Button::Ptr button = std::make_shared<tgui::Button>();
...
tgui::Texture texture;
texture.load(...);
texture.setColor( sf::Color(255, 0, 0) );
button->getRenderer()->setHoverTexture(texture);


texus

It seems like I overwrite the color to set the transparency, the setHoverTexture contains the following line:
Code (cpp) Select
m_textureHover.setColor({255, 255, 255, static_cast<sf::Uint8>(m_button->getOpacity() * 255)});

So you could remove that line from TGUI/src/Widgets/Button.cpp and rebuild tgui.

I'll probably update the code later today to set the alpha in that color without overwriting the RGB values. But I will immediately do that for all widgets.

texus

The latest version (which you can download on github) now no longer overwrites these RGB values. So your code will work if you download and build that version.

The fix isn't perfect and the alpha value will remain unchangeable in v0.7 but I'm already solving the problem in a better way in v0.8-dev so that it will even be possible to have normal and hover textures with different alpha values. But what you want to do at least already work now.

ultra

All right, thank you! With this information at hand, I will somehow manage to work around the problem.