Hello,
I practice working with sfml and trying to write my own GUI.
Now I'm trying to create widgets that represent a container for other widgets and now I'm faced with a problem.
I have a widget called "Form" - it has its own sf :: View and an array with different widgets.
This widget is the base for all the others, which must be containers (Window, Group, Tab, ...). The rendering function looks like this:
void Form::draw(sf::RenderTarget& target, sf::RenderStates states) const {
sf::View oldView = target.getView();
target.setView(m_view);
for (auto& widget : m_widgets) {
target.draw(*widget, states);
}
target.setView(oldView);
}
Everything works fine if I do not use nested containers (because one view replaces another), but still, how do I implement this feature?
The only solution I could think of was to replace sf :: View with sf :: RenderTexture, like this:
void Form::draw(sf::RenderTarget& target, sf::RenderStates states) const {
sf::RenderTexture render;
render.create(m_width, m_height);
render.clear(sf::Color::Transparent);
for (auto& widget : m_widgets) {
render.draw(*widget, states);
}
render.display();
sf::Sprite sprite(render.getTexture());
sprite.setPosition(m_position);
target.draw(sprite, states);
}
And it even works, but the new problem is a very rare frame rate, so I can't use this implementation.
So far I don't know other methods of realizing my idea, maybe you have.
I will be glad to any help, thanks.