Re: Problem updating DrawingArea



Thank you very very much!

As you can tell, I've been anxiously awaiting a response as I've been
pulling my hair out the last couple of days trying to figure it out. I
can't see *any* flickering during the text redraw with your version on
my system. I was hoping it was a relatively simple fix and it is.

Now lets just hope this implementation works the same in my actual
application where there's quite a bit more going on during the redraw.

Thank you again.



On Fri, 2002-03-01 at 01:24, Pavel Rousnak wrote:
Hi all,

I'm updating some text on a drawing area using draw_string and a
timeout. This works fine except the drawing area flickers every few
seconds during the update. I believe this is caused by redrawing the
rectangle (draw_rectangle) every time my timeout is called. How can I
avoid this flickering, or more specifically, how can avoid having to
redraw the drawing area while updating the text on it.

Below is an example program that displays this problem.

There is a standard way of implementing such things (see attachment).
Unfortunately on my system your code works without flicking and
I could not see the difference between two versions so you have 
to do it yourself. Please inform me about results.
 
----


#!/usr/bin/perl -w

use Gtk;
use strict;

Gtk->init;

my $false = 0;
my $true = 1;

my ( $win, $vbox, $frame, $drawing_area, $timeout );

$win = new Gtk::Window( '-toplevel' );
$win->set_title( 'DrawingArea Example' );
$win->signal_connect( 'destroy', sub {Gtk->exit( 0 )} );

$vbox = new Gtk::VBox( $false, 0 );
$win->add( $vbox );

$frame = new Gtk::Frame();
$frame->set_shadow_type( 'in' );

$drawing_area = new Gtk::DrawingArea();
$drawing_area->size( 640, 85 );
$drawing_area->signal_connect( 'configure_event', \&draw_shapes );
$drawing_area->signal_connect( 'expose_event', \&draw_text );


$frame->add( $drawing_area );
$vbox->pack_start( $frame, $false, $false, 0 );

$win->show_all();

$timeout = Gtk->timeout_add( 250, \&add_text, $drawing_area->window );

Gtk->main;

##---------------------------------------------------------##
#Subs                                                       #
##---------------------------------------------------------##
sub add_text
{
   my ($drawable, $event) = @_;
   my ($width, $height, $font, $black_gc, 
       $white_gc, $cur_time, $uptime);

   $width = $drawing_area->allocation->[2];
   $height = $drawing_area->allocation->[3];

   $font =
Gtk::Gdk::Font->load("-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*");
   $black_gc = $drawing_area->style->black_gc;
   $white_gc = $drawing_area->style->white_gc;

   $uptime = `uptime`; chomp($uptime);
   $cur_time = "The time is now ".`date`; chomp($cur_time);

   my $tmp_pm = new Gtk::Gdk::Pixmap($drawing_area->window(), $width, $height);
   $tmp_pm->draw_rectangle( $black_gc, $true, 0, 0, $width, $height );
   $tmp_pm->draw_string( $font, $white_gc, 5, 25, $uptime );
   $tmp_pm->draw_string( $font, $white_gc, 15, 55, $cur_time);
   $drawable->draw_pixmap($white_gc, $tmp_pm, 0, 0, 0, 0, $width, $height);

   return $true;
}

sub draw_text
{
   my ($drawing_area, $event) = @_;
   my $drawable = $drawing_area->window;

   &add_text($drawable, $event);

   return $false;
}

sub draw_shapes
{
   my ($drawing_area, $event) = @_;
   my ($drawable, $width, $height, $black_gc);

   $drawable = $drawing_area->window;
   $width = $drawing_area->allocation->[2];
   $height = $drawing_area->allocation->[3];
   $black_gc = $drawing_area->style->black_gc;

   $drawable->draw_rectangle( $black_gc, $true, 0, 0, $width, $height );

   return $true;
}
----


Best regards
Pavel.




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