Recent Posts

Pages: [1] 2 3 ... 10
1
Help requests / Re: Conversion from CImg to TGUI
« Last post by DJuego on 28 March 2020, 22:59:23 »
Indeed! Thank you for your answer, texus!

Very soon after asking the question I managed to code a satisfactory solution myself.
 I planned to publish the solution I found, and thus contribute to the community. But the life delayed me. I'm sorry. :-(

 Anyway, it's not perfect, because I can't load the alpha channel of the PNG images. But I know that the problem has nothing to do with SFML or TGUI.

I paste the current code (for now):

Code: [Select]
m_imagen.load("recursos/imagen_png.png");
//m_imagen.load("recursos/imagenBN_jpg.jpg");
//m_imagen.load("recursos/imagen_jpg.jpg");

sf::Image imagen;
imagen.create(m_imagen.width(), m_imagen.height(), sf::Color::Black);

switch (m_imagen.spectrum())
{
case 0:
{
//The image is empty


}
break;

case 1:  //Grayscale image
{
for (std::size_t i = 0; i < m_imagen.width(); ++i)
{
for (std::size_t j = 0; j < m_imagen.height(); ++j)
{
sf::Color color = sf::Color(m_imagen(i, j, 0, 0), m_imagen(i, j, 0, 0), m_imagen(i, j, 0, 0), 255);
imagen.setPixel(i, j, color);
}
}
}
break;
case 3:   //The image is RGB
{
for (std::size_t i = 0; i < m_imagen.width(); ++i)
{
for (std::size_t j = 0; j < m_imagen.height(); ++j)
{
sf::Color color = sf::Color(m_imagen(i, j, 0, 0), m_imagen(i, j, 0, 1), m_imagen(i, j, 0, 2), 255);
imagen.setPixel(i, j, color);
}
}
}
break;

case 4: //The image is RGBA?
{
for (std::size_t i = 0; i < m_imagen.width(); ++i)
{
for (std::size_t j = 0; j < m_imagen.height(); ++j)
{
sf::Color color = sf::Color(m_imagen(i, j, 0, 0), m_imagen(i, j, 0, 1), m_imagen(i, j, 0, 2), m_imagen(i, j, 0, 3));
imagen.setPixel(i, j, color);
}
}
}
break;

default:

break;
}



sf::Texture textura;
textura.loadFromImage(imagen);

tgui::Picture::Ptr panoramica = m_gui_principal.get<tgui::Picture>("Picture1");
panoramica->getRenderer()->setTexture(textura);



DJuego

P.S: Thank you for your commitment to the forum.

2
Help requests / Re: Conversion from CImg to TGUI
« Last post by texus on 28 March 2020, 22:32:05 »
I don't really know CImg, but if the exception is coming from the sf::Image::create function then you may want to check what image_cimg.data() is returning.

According to the SFML documentation, the pixel data must be in 32-bits RGBA. This means that it will try to read 4*width*height bytes. Does image_cimg.size() return that amount? If not, then you should figure out how to get CImg to return the data in the correct format.

Alternatively, you can create the sf::Image without providing the pixel data and then use sf::Image::getPixelPtr and manually loop over the pixels from CImg and change them in the pixel data.

Either way, you need to understand exactly how the pixel data is formatted in your CImg image in order to figure out how to convert it to SFML (which stores the pixels as 4-byte RGBA values).
3
Help requests / Conversion from CImg to TGUI
« Last post by DJuego on 28 March 2020, 15:57:08 »
Windows 10. Microsoft Visual Studio 2019

Hi. I'm new to CImg.

I'm trying to load images into SFML from CImg. My idea is that CImg will take care of the image processing while the interface is developed based on SFML (more specifically with TGUI. For example in a PictureBox.). Has anyone tried this conversion successfully?

My attempts have been unsuccessful. For example; this code produces an exception.

Code: [Select]
cimg_library::CImg<unsigned char> image_cimg("recursos/imagen_png.png");

sf::Image image_sfml;
image_sfml.create(image_cimg.width(), image_cimg.height(), image_cimg.data());

Any idea?
Thank you!

DJuego
4
Feature requests / Re: Table
« Last post by Zetal on 23 March 2020, 00:35:14 »
The updateWidgetPosition will only be called when widgets are changed, which isn't that frequent. I only care about performance when something is called almost every frame, but this function is only called a lot while creating the table (while adding the rows). The setPosition and setSize functions of widgets will become very light operations in the near future so the function won't be that heavy.

The Table class on my bitbucket looks finished at first sight. So you don't really have to resolve anything unless you find things that are still missing. It juststill has to be extensively tested.

That BitBucket link isn't accessible for me, and I'm interested in using this Table class. Would it be possible for me to have access to these classes to save me the time remaking it? Thanks!

Edit: Nevermind! I found that this was "reimplemented" as a ListView in this commit: https://github.com/texus/TGUI/commit/54e72fbdcf038bb9f614ffb1219074c6221ac8d4
5
Help requests / Re: Connect error
« Last post by texus on 22 March 2020, 14:11:23 »
First of all, the only officially supported way to include TGUI is by including TGUI.hpp. If you chose to include other files directly then you are relying on implementation details and you could run into dependency issues like this.

The files have changed a lot, so I'm not sure if there still is a reason why it remains like this, but there are 2 reasons why the current design might have been chosen:
- To improve compilation speed. Lots of templates can slow down compilation, so it might be beneficial to only include them when needed instead of including them in a file that is included by practically every source file (like Widget.hpp). This of course only affects compiling TGUI itself as in your own code you need to include the signal header anyway, plus the performance difference might not be noticeable.
- To fix a circular dependency. Widget uses Signal, but Signal also uses Widget. Looking at the code, this doesn't seem to be an issue as SignalImpl uses shared_ptr<Widget> instead of Widget::Ptr, so that it doesn't need to include Widget.hpp. But it could have been the reason why the signal code was originally split into 2 files.
6
Help requests / Re: Connect error
« Last post by CatalinNic on 22 March 2020, 13:11:36 »
i needed to include SignalImplm, however I was pointed to the Signal header, why don't you implemented there and why don't you included as well in the Widget header?
7
Help requests / Re: Connect error
« Last post by texus on 22 March 2020, 12:49:44 »
I would guess that SignalImpl.hpp isn't being included. Are you including TGUI.hpp or were you manually including other headers (in which case you also need to include SignalImpl.hpp)?
8
Help requests / Connect error
« Last post by CatalinNic on 22 March 2020, 11:38:23 »
I have this test function with tgui::EditBox::Ptr as parameter in a separate cpp file
void test(tgui::EditBox::Ptr Editbox)
{
    Editbox->connect("clicked", []{}); // error
}

And the error produced is:
/usr/include/TGUI/Signal.hpp:863:22: error: ‘unsigned int tgui::SignalWidgetBase::connect(std::string, Func&&, const BoundArgs& ...) [with Func = test(tgui::EditBox::Ptr)::<lambda()>; BoundArgs = {}; std::string = std::__cxx11::basic_string<char>]’, declared using local type ‘test(tgui::EditBox::Ptr)::<lambda()>’, is used but never defined [-fpermissive]
  863 |         unsigned int connect(std::string signalName, Func&& handler, const BoundArgs&... args);
      |                      ^~~~~~~
/usr/include/TGUI/Signal.hpp:863:22: warning: ‘unsigned int tgui::SignalWidgetBase::connect(std::string, Func&&, const BoundArgs& ...) [with Func = test(tgui::EditBox::Ptr)::<lambda()>; BoundArgs = {}]’ used but never defined
Why it does that?
9
Excellent, first option is easy so I'll go with it ;-)
10
You can have the last column fill the remaining space instead of manually setting the width (the configured width will be used as minimum column width, it could be set to 0 to make the minimum width of the column equal to the width of the "Value" string):
listView->setColumnWidth(0, window.getSize().x * 0.2f);
listView->setColumnWidth(1, 0);
listView->setExpandLastColumn(true);

Alternatively, you would have to manually subtract all pixels that are drawn next to your columns. Each column has an extra pixel next to it (the column separator). Even your last column has this, unless you set setExpandLastColumn to true. The default white theme also has a border of 1 pixel on each side. So the code you would need looks like this:
const double clientWidth = window.getSize().x - listView->getRenderer()->getBorders().getLeft() - listView->getRenderer()->getBorders().getRight();
listView->setColumnWidth(0, clientWidth * 0.2f - listView->getSeparatorWidth());
listView->setColumnWidth(1, clientWidth * 0.8f - listView->getSeparatorWidth());
Pages: [1] 2 3 ... 10