Loading Widget Image From Memory

Started by MoLAoS, 02 September 2014, 09:39:36

MoLAoS

I have a game class for buildings, that loads its own icon. Would it be possible to load an image to a Picture, that I'm using as a button for building buildings, from a pointer to an sf::Texture? Or should I just grab the name of the loaded image, shove it into a filepath and reload it?

texus

There is currently no way to load widgets from memory.

This will be changed in v0.7. Picture will definitely support taking a reference to an existing sf::Texture.
The entire loading mechanism should probably be changed for loading the other widgets from memory: https://github.com/texus/TGUI/issues/27

But this is not something to be expected soon.

texus

Picture is actually an exception. Unlike other widgets it is loaded with just a single image.
So I have quickly added this to v0.6 for Picture instead of delaying this to v0.7 where it will be possible for all widgets.

You can download the latest TGUI v0.6 version from github (will be released as v0.6.6 in 3 weeks). Then you will be able to write the following code:
sf::Texture texture;
texture.loadFromFile("ThinkLinux.jpg");

tgui::Picture::Ptr picture(gui);
picture->loadFromTexture(texture);

MoLAoS

Cool. There were a couple ways to work around it but they were quite a hassle. Probably the simplest one was to reload the image separately to the widget, the next one being by including the widget code in the Building class.