Accessing Picture's underlying sprite
« on: 19 November 2017, 14:58:02 »
Hi,

I am working on a drawing application and I need buttons with icons of various tools (brush, can, etc) that change color based on color selection. So far I am doing it via sf::Sprite that has texture bound to it and calling Sprite::setColor whenever I need to. And I catch the clicks with invisible panel hidden behind it.

But that creates an issue since I have to draw the Sprites after the gui is drawn and thus any elements that possibly can overlap these buttons will be rendered under the Sprites. I was wondering whether I can use something like tgui::Picture to do the job, but unfortunately I can't find a way to access it's underlying sprite (or whatever it uses for rendering).

In the end, Picture renders a texture so there has to be a way to set color to it as well.
Thanks for any tips

*

texus

  • *****
  • 1172
    • View Profile
    • Texus's Blog
Re: Accessing Picture's underlying sprite
« Reply #1 on: 19 November 2017, 15:18:14 »
Although technically the functionality exists inside TGUI, it doesn't seem to be possible. In TGUI 0.7 the Picture simply doesn't allow accessing the internal texture and in TGUI 0.8-dev where it does provide access to it, the class was redesigned and it simply isn't possible anymore.
So the only option that I see would be to use the Canvas class. It is basically a wrapper around sf::RenderTexture, but since it acts like a widget, it is drawn between the other widgets.

auto canvas = tgui::Canvas::create({400, 300});
gui.add(canvas);

canvas->clear();
canvas->draw(...);
canvas->display();

You don't need to do the clear/draw/display every frame, only when the contents of the canvas has to be changed.
« Last Edit: 19 November 2017, 15:20:43 by texus »

Re: Accessing Picture's underlying sprite
« Reply #2 on: 19 November 2017, 17:26:04 »
This solution works perfectly, does what I need with minimal effort to update my code, thanks :)