[v0.7] loadFromTexture & setTextFont

Started by SDH, 02 February 2015, 10:47:26

SDH

I would love to see function like (not probably the only one):

Code (cpp) Select
inline void Picture::loadFromTexture(sf::Texture& _texture)
{
     m_texture = _texture;
}


because without it i can't use v0.7, otherwise you will wait seconds to see any page in my game...
Ofc i can write it to your code but i think many users will appreciate this, because i'm not probably
the only one with Resource Managers ...
And i'm not the only one who want to manage resources by myself.

EDIT:

Code (cpp) Select
void setTextFont(std::shared_ptr<sf::Font> font);

Can you please add option with only sf::Font&, otherwise there is need to use std::make_shared.
Most of the tut's on net uses res-managers with & return type and most of the begginers
don't know anything about smart pointers.

example:

using your code:
Code (cpp) Select
#include <memory>
sf::Font m_font;
m_font.loadFromFile("my_font.ttf")
m_label.setTextFont(std::make_shared<sf::Font>(m_font));


more readable version for begginers:
Code (cpp) Select

sf::Font m_font;
m_font.loadFromFile("my_font.ttf")
m_label.setTextFont(m_font);


As in my last thread: https://forum.tgui.eu/index.php?topic=280.0
i can do the code for you, because of this:
Quote from: texus on 01 October 2014, 22:29:31
But seeing how much work I'm going to get with my university projects, it will probably be for July next year. Most v0.7 progress will be delayed till next year since I simply don't have the time for it.

texus

Quotevoid Picture::loadFromTexture(sf::Texture& _texture)
The biggest change that v0.7 still needs is a completely new theme system. This includes a new way of loading themes (probably first create a Theme object and then pass this to the create function of the widgets so that the theme can be shared). There should be a way to to easily make a change in the theme so that all widgets receive this change. The themes must be loadable through custom loaders. The texture manager will be placed into the default loader which will be in tgui. If you use your own loader then you have to manager resources yourself.

The reason I am explaining this is because this change can only easily be made when picture (and especially the texture in it) no longer depends on the internal texture manager.

I always use "sf::" in front of all sfml classes. I know it is confusing, but there is a tgui::Texture class as well. So it is not as simple as "m_texture = texture" ;)

QuoteCan you please add option with only sf::Font&
I always though that the user would be forced to create a shared_ptr himself. I never though of letting the user create the sf::Font object and then using the copy constructor to get a shared_ptr from it. However adding such a function would mean that a copy gets made internally and when the user changes his font the widgets won't change with it. So I'm ok with adding such a function, but it should contain the warning that the font gets copied, not directly used.

To avoid duplicate code, the function would thus just call the other variant:
Code (cpp) Select
void setTextFont(const sf::Font& font)
{
    setTextFont(std::make_shared<sf::Font>(font));
}


Feel free to add this setTextFont function to all widgets that need one. I do have time but I am working on other stuff.

I was thinking of giving all widgets a setTextFont function. What do you think about that? It would mean that widgets like Picture get a useless function, but it would also mean that setGlobalFont can change existing widgets (after adding extra bool parameter indicating if change is for future or all widgets). This would mean that with a single function call the font of all widgets could be changed.

SDH

#2
Quote
I was thinking of giving all widgets a setTextFont function. What do you think about that? It would mean that widgets like Picture get a useless function, but it would also mean that setGlobalFont can change existing widgets (after adding extra bool parameter indicating if change is for future or all widgets). This would mean that with a single function call the font of all widgets could be changed.

That will be a nice & usable feature.