Reputation: 3
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!
Upvotes: 0
Views: 440
Reputation: 354
Such effects as described here are often caused by a widget having "no background", i.e. either the box type FL_NO_BOX or one of the FL_*_FRAME types. If you change the image or the label (supposed they are inside the box) then the changed label/image overwrites the existing label. In such cases you have two choices:
tryb_pracy_box->redraw();
to tryb_pracy_box->parent()->redraw();
If the label (and image) are outside the widget it's definitely necessary to draw the parent widget when the label is changed.
Upvotes: 1
Reputation: 686
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.
Upvotes: 0