v0.7 panel background textures
« on: 05 September 2015, 00:40:36 »
Hey,

I was trying to set the background texture for a panel.

I tried the line below, but there doesn't appear to be a setbackgroundtexture method. I don't see any panel renderer class? Is this coming in a later version? Any recommendations to get around this currently?

void drawEngine::setupPanel(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_backGroundColour, string passed_panelName, sf::Texture *passed_texture)
{

        if (gui.get(passed_panelName) == NULL)
        {
                tgui::Panel::Ptr mainMenuPanel = theme->load(themeConfFile);
                mainMenuPanel->setPosition(pos.x, pos.y);
                mainMenuPanel->setSize(size.x, size.y);
                mainMenuPanel->setBackgroundColor(passed_backGroundColour);
                if (passed_texture != NULL)
                {
                        mainMenuPanel->getRenderer()->setBackgroundTexture(passed_texture);
                }
        }
}
 
« Last Edit: 05 September 2015, 00:53:44 by starkhorn »

*

texus

  • *****
  • 1163
    • View Profile
    • Texus's Blog
Re: v0.7 panel background textures
« Reply #1 on: 05 September 2015, 00:52:04 »
I removed the background image in panel because there were other ways to achieve the same thing.

If the background is a normal image then you can use a tgui::Picture:
panel->add(std::make_shared<tgui::Picture>("image.png"));

Since the Picture class can apparently also be created from a sf::Texture you can do this in your code too:
(I almost recommended a 10 line long code using tgui::Canvas before I realized that this could also be achieved with Picture :D)
panel->add(std::make_shared<tgui::Picture>(texture));

Re: v0.7 panel background textures
« Reply #2 on: 05 September 2015, 01:20:29 »
Ah ok cool. I'll let you know how that goes.

BTW, I really really like the new way of adding widgets to the gui or a container. Also I find the new get method to be able to retrieve the widget pointer really, really useful.

EDIT:- both of the recommendations above worked a treat.
« Last Edit: 05 September 2015, 04:20:27 by starkhorn »