v0.7 using the tgui::picture

Started by starkhorn, 05 April 2016, 08:46:32

starkhorn

Hey Texus,

So I want to setup a picture using a texture. However I only want to set the picture to have the picture defined in a sf::IntRect.
Basically I have a sprite that has it's setTextureRect to a subset of a larger texture, and I want the tgui::picture to only display this subset/IntRect.

I don't see a setTextureRect method in tgui::picture so I was wondering if there was a way to do it? Again this is me trying to get around using canvas due to the blinking issue with my graphics card. So instead of sprites, I am trying to use tgui::pictures.

texus

It is possible with the tgui::Texture class, but I just noticed that there is no easy way to create it from an existing sf::Texture, it only takes a filename.
I'll check if I can improve this without breaking existing code.

texus

The tgui::Texture class did contain a setTextureRect function but it does not do the same as the one from sf::Sprite. It could work with the tgui version that you have but it would require setting a different position and size to the picture to compensate for the side-effects of setTextureRect.

I have however made some changes now to make it possible, but you will have to download tgui from github and compile it yourself again.
After that you can use code like this:
Code (cpp) Select
sf::Texture sfTexture;
sfTexture.loadFromFile("Linux.jpg");

auto picture = std::make_shared<tgui::Picture>(tgui::Texture{sfTexture, {200, 100, 400, 400}});


The last parameter to the tgui::Texture constructor is the sf::IntRect of course which defines the part of the texture that you want. Note that due to the way tgui is designed, creating an tgui::Texture with this IntRect parameter is a slow operation. The texture is first copied to an sf::Image to then create a new sf::Texture from it with the requested size.

starkhorn

Ok thanks. It might take me a while to download from github and recompile.
I am thinking for right now to create a customer button widget where the hover, normal and down images/rgb are all the same. Also I won't connect any signal function to it....that essentially will just leave an unclickable button.

texus

QuoteI am thinking for right now to create a customer button widget where the hover, normal and down images/rgb are all the same. Also I won't connect any signal function to it....that essentially will just leave an unclickable button.
Then it isn't really a button anymore :). Unless you intend to add the other textures later then you can just as well create a Picture.
If you don't set the hove or down images they will automatically fall back to the normal image btw.

texus

If you don't update tgui they you could still clip the texture yourself before passing it to Picture:
Code (cpp) Select
sf::Texture texture;
texture.loadFromImage(largeTexture.copyToImage(), intRect);
auto picture = std::make_shared<tgui::Picture>(texture);