Search code examples
c++fltk

Problem with changing image inside the box FLTK


I have a problem with changing images(Fl_PNG_image size 25x25[enter image description here][1]) inside Fl_Box.

So here is the part of code that changes the box:

        if(strcmp(payload, "heat")==0) tryb_pracy_box->image(grzanie_png);
        if(strcmp(payload, "cool")==0) tryb_pracy_box->image(chlodzenie_png);
        tryb_pracy_box->redraw();

also then i have a Fl::check();

But when I try to change the image, results looks like this: [1][1]: https://i.sstatic.net/xb7by.png

As far as I understand, image "apears" over the label, but when i was trying to use different aligns, it didn't help.

Here are images, that I am working with [2][2]: https://i.sstatic.net/h0GVz.png [3][3]: https://i.sstatic.net/OS2bC.png

Thanks in advance!


Solution

  • I find it easier to just subclass Fl_Box and implement (override) the draw method. Within it you can call fl_draw_image(…) and fl_draw(const char *, …). This allows you to specify the coordinates of the text exactly over the image without fiddling with alignment relative to the image. You can store an image pointer within your class and change what it points to.