Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - panhandler

Pages: [1]
1
Graphics / Re: Combination of several sf::View
« on: July 27, 2017, 07:40:04 pm »
Unfortunately, this does not work, because redraw() will be called as often as the widgets from the container will visually change (when hovered, pressed, ...(and if there are many of them, then the chance for updating the renderer is higher))
Also, unstable rendering is complicated by the fact that widgets from the container don't have callbacks (not provided and not used in practice, except for this case), which could tell that the container needs redraw. In this case, I need to create a texture every time. That's why I can't avoid FPS losing  :-[

2
Graphics / Combination of several sf::View
« on: July 27, 2017, 05:16:29 pm »
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.

Pages: [1]