Set Color of Texture
« on: 20 May 2016, 14:08:06 »
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?

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

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Set Color of Texture
« Reply #1 on: 20 May 2016, 14:21:19 »
It seems like I overwrite the color to set the transparency, the setHoverTexture contains the following line:
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

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Set Color of Texture
« Reply #2 on: 21 May 2016, 00:08:01 »
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.

Re: Set Color of Texture
« Reply #3 on: 21 May 2016, 12:07:39 »
All right, thank you! With this information at hand, I will somehow manage to work around the problem.