I am currently trying to learn GTK+3/cairo using C. I have written a small application which draws a gauge face and needle on a gtk drawing area using cairo.
This works well so far, i have tried creating multiple drawing areas (multiple gauges) which all have the same callback function for the draw event, this also works well with static values.
Now my question, i would like to be able to draw multiple gauges each with their own values. But how do i know in my callback function which gauge (drawing area) emitted the draw signal? I guess this also includes how do i "create and store" data for the gauges so their properties can be fetched from within the draw callback.
I should probably create a struct that holds the data for a gauge, and create multiple of those. That's what i have gathered by looking at various projects that use GTK, but it's too complicated for me to fully understand how it works.
This is how i create the drawing area(s):
gaugearea1 = gtk_drawing_area_new();
gtk_box_pack_start(GTK_BOX(hbox), gaugearea1, FALSE, FALSE, 5);
gtk_widget_set_size_request(gaugearea1, 300, 300);
gtk_widget_realize(gaugearea1);
g_signal_connect(gaugearea1, "draw", G_CALLBACK(draw_event), NULL);
And the callback function is written like this, pretty standard.
static gboolean draw_event(GtkWidget *widget, cairo_t *cr)
{
GdkWindow *win;
win = gtk_widget_get_window(widget);
// Draw all arcs/lines using cr
}
Any tips on how to approach something like this would be greatly appreciated.