Search code examples
cgtk3cairo

Drawing lines using Cairo in real time


In zetcode "Lines" code, I am trying to display the lines in real time as the mouse button is clicked. I then changed the clicked function to

static gboolean clicked(GtkWidget *widget, GdkEventButton *event,
    gpointer user_data)
{
    if (event->button == 1) {
        glob.coordx[glob.count] = event->x;
        glob.coordy[glob.count++] = event->y;
        gtk_widget_queue_draw(widget);
    }

    return TRUE;
}

I was thinking it would display the lines every time button 1 was clicked, but they are not being drawn on the window at all. What am i missing here?


Solution

  • The function that runs on draw, do_drawing(), contains this line at its end:

    glob.count = 0;
    

    so it clears the array after drawing them all, thus making it very hard to accumulate a large number of lines like you're trying to.