Re: Call a function after showing something in a DrawingArea



On 1/3/06, Christoph Bersch <bersch uni-muenster de> wrote:
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)

I would use a timeout. Set it to run every 20ms (or whatever interval
you want), and do something like:

static int number_of_ticks = 0;

my_timeout_callback( ...
{
  number_of_ticks += 1;
  if( number_of_ticks & 1 )
    // queue a redraw of our drawingarea
    gtk_widget_queue_draw( ..
  else
    measure();

  return( TRUE );
}

then in your expose callback use number_of_ticks to decide what to draw.

expose_callback( ..
{
  for( int i = 0; i < number_of_ticks / 100 + 1; i++ )
    draw_square( i );
}

There's no guarantee that the draw will occur before the measure, but
it probably will for most reasonable machines. But of course that's
always true for X.

John



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