I have been able to do the following:
for (int i = 0; i < NUM_LEDS; ++i) {
ledoff = gtk_image_new_from_file("./ledoff.png");
leds[i].pos=ledpos[i];
gtk_layout_put(GTK_LAYOUT(layout), ledoff, leds[i].pos.x, leds[i].pos.y);
leds[i].status=OFF;
}
Basically, this loads a bunch of "ledoff" images onto some window.
What I need is to change the image ledoff to ledon every time I click on leds[i].pos.x, leds[i].pos.y. At the beginning I thought it was just a matter of loading a new image and replacing the previous one, but then since this will be done thousands of times, I thought I was "malloc’ing" one new file everytime I do gtk_image_new_from_file! Is this true? Or am I just replacing the file and not adding a new one?
Here is a working example that creates a 50×50 “LED” array in a window and allows you to toggle their status by clicking on them. It’s not really that efficient, and as I pointed out in comments you’re better of drawing the images yourself right onto the GtkLayout, but this will at least serve as a proof of concept.
Edit: I’ve updated the sample code to take into account liberforce’s suggestions, which make things cleaner and more memory efficient.