Call a function after showing something in a DrawingArea



Hi,

I want to write a program, that draws something in a DrawingArea, and calls a
function after _showing_ the changes in the DrawingArea:

1) call function draw_something()
2) show the changes
3) call a function measure()
4) return to step 1)

As far as I understood the thing, even if I call gtk_widget_draw() in
draw_something(), the changes are shown only after the function ended and the
program returned to gtk_main(). Is this right?

Thus I can't call measure() within draw_something(), as then the changes
aren't visible yet.

How can I accomplish the workflow shown in the upper list?

My approach was to modify the scribble-simple.c from the tutorial a bit, but I
didn't find anything how to realize this sequence. What I changed is, that I
added the two functions draw_next_square() and measure() (I didn't want to
post the whole source):

#define SQ_SIZE 20
static gint sq_count = 0;

static gboolean draw_next_square( GtkWidget *widget )
{
  gint row, col;
  col = (sq_count * SQ_SIZE) / widget->allocation.height;
  row = (sq_count * SQ_SIZE) % widget->allocation.height;

  /* rectangle to redraw */
  GdkRectangle rect;
  rect.x      = col;
  rect.y      = row;
  rect.height = SQ_SIZE;
  rect.width  = SQ_SIZE;

  gdk_draw_rectangle (pixmap,
                      widget->style->black_gc,
                      TRUE,
                      col, row,
                      SQ_SIZE, SQ_SIZE);
  gtk_widget_draw (widget, &rect );

  sq_count++;
  /* for testing just print the first 10 squares */
  if (sq_count > 10)
    return FALSE;
  else
    return TRUE;
}

static void measure (void)
{
  printf("measure\n");
  /* here more code will come */
}


I hope to get some advices,

thanks
Christoph



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]