v0.7 panel background textures

Started by starkhorn, 05 September 2015, 00:40:36

starkhorn

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?

Code (cpp) Select

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);
}
}
}

texus

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:
Code (cpp) Select
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)
Code (cpp) Select
panel->add(std::make_shared<tgui::Picture>(texture));

starkhorn

#2
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.