Loading Widget Image From Memory
« on: 02 September 2014, 09:39:36 »
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

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Loading Widget Image From Memory
« Reply #1 on: 02 September 2014, 10:14:58 »
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

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Loading Widget Image From Memory
« Reply #2 on: 02 September 2014, 12:01:44 »
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:
Code: [Select]
sf::Texture texture;
texture.loadFromFile("ThinkLinux.jpg");

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

Re: Loading Widget Image From Memory
« Reply #3 on: 02 September 2014, 18:16:40 »
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.