0

I'm trying to change the image being displayed in an Fl_Box.

static Fl_RGB_Image *greenRgb;
static Fl_RGB_Image *redRgb;
static Fl_RGB_Image *blackRgb;

Fl_Box *makeTristate(char const *name) {
    Fl_Box *ret = new Fl_Box(0, 0, 300, 32, name);
    ret->labelsize(24);
    ret->align(FL_ALIGN_RIGHT | FL_ALIGN_IMAGE_NEXT_TO_TEXT);
    ret->image(whiteRgb);
    return ret;
}

void setTristate(Fl_Box *tris, int state) {
    Fl_RGB_Image *wanted;
    if (state < 0) {
        wanted = redRgb;
    } else if (state > 0) {
        wanted = greenRgb;
    } else {
        wanted = blackRgb;
    }
    if (wanted != tris->image()) {
        LOG_PRINTF("changing %p (%s) from %p to %p", tris, tris->label(), tris->image(), wanted);
        tris->image(wanted);
        tris->redraw();
    }
}

The images are properly loaded. Whichever image is first set on the Fl_Box when it is created, keeps being displayed forever, even though the printf() clearly shows that I change images to some other good image.

It's as if the redraw() didn't actually cause the box to realize it has a new image and redraw itself. The main loop is running; I have another image (a video capture) that I re-create (delete the old, create a new) 30 times a second, and that box/image re-displays itself just fine.

The Fl_Box-es that I create with makeTristate() and update with setTristate() are in themselves inside a Fl_Pack. In desperation, I've tried to call uncache() on the wanted image before assigning it, but that doesn't help.

What am I doing wrong; how can I get the image of the Fl_Box to be a different image and have it re-display?

The system is Ubuntu 16.04 running on a Jetson TX2. I'm using FLTK 1.3.4. I can't update to anything newer, because this is the latest NVIDIA has released ("JetPack 3.2") for the hardware I'm running on. The problem happens both on a natively attached display, driven by the on-board NVIDIA driver, and when running across a network with a different DISPLAY.

Jon Watte
  • 6,579
  • 4
  • 53
  • 63

1 Answers1

0

So, it turns out I had forgotten the FLTK behavior that causes this.

redraw() will only invalidate the box of the widget, not its label area.

Because I didn't set FL_ALIGN_INSIDE in the call to align() the label and image ended up outside the label area, but I hadn't noticed because there wasn't a lot to line up with these things in the window.

Adding FL_ALIGN_INSIDE to the call to align() fixed the problem. And, more generally, remember that redraw() doesn't invalidate the label area of a widget, if the label is outside the widget.

Jon Watte
  • 6,579
  • 4
  • 53
  • 63