queue_draw_area query..



Greetings,

(Hopefully I have my list subscription sorted..)
Can anyone comment on the following script?

Thanks to Paolo Molaro for his help so far..

It runs and will update the screen on an expose events,
(resize, and moving a window in front..)
but doesn't update the display if I draw on the backing pixmap
(with update_chart).

Outline:
  configure_chart - setup drawable.
  expose_chart    - call this on expose events (this outputs the signal)
  update_chart    - make changes to the chart
  main loop


Thanks in advance,
Paul

--
#!/usr/bin/perl -w
####################################################################### 
# Filename: 
# Paul Schulz (pschulz foursticks com au)
# Foursticks, 2000
#
# Repository: $Id: perl.pl,v 1.1 2000/08/11 13:16:09 paul Exp $
# Version:    $Revision: 1.1 $
# Author:     $Author: paul $
# Tag:        $Name:  $
#
# Licence:    GPL v2 (or higher)
####################################################################### 
# $Log$
#

use Gtk;

init Gtk;

$true = 1;
$false = 0;

$pixmapChart = undef;
$width = 600;
$height = 100;
$margin = 5;

sub configure_chart {

  my ( $widget ) = @_;

  my ( $margin, $axemargin ) = ( 5, 5 );
  
  my $red_gc = new Gtk::Gdk::GC ( $widget->window );
  my $green_gc = new Gtk::Gdk::GC ( $widget->window );
  my $blue_gc = new Gtk::Gdk::GC ( $widget->window );

  my $red_color = $widget->window->get_colormap->color_alloc( { red => 65000, green => 0, blue => 0 } );
  my $green_color = $widget->window->get_colormap->color_alloc( { red => 0, green => 65000, blue => 0 } );
  my $blue_color = $widget->window->get_colormap->color_alloc( { red => 0, green => 0, blue => 65000 } );

  $red_gc->set_foreground( $red_color );
  $green_gc->set_foreground( $green_color );
  $blue_gc->set_foreground( $blue_color );

  $pixmapChart = new Gtk::Gdk::Pixmap (
    $widget->window,
    $width, 
    $height, 
    -1
  );

  # clear the pixmap to white
  $pixmapChart->draw_rectangle(
    $widget->style->white_gc,
    1,
    0,
    0,
    $width,
    $height
  );

  $pixmapChart->draw_line(
                          $blue_gc,
                          $margin,
                          $height-$margin,
                          $width-$margin,
                          $height-$margin
                          );

}

sub expose_chart {
  my ($widget, $event ) = @_;

  my ( $event_area );

  $event_area = ${$event}{'area'};

  $widget->window->draw_pixmap(
    $widget->style->fg_gc('normal'),
    $pixmapChart,
    ${$event_area}[0],
    ${$event_area}[1],
    ${$event_area}[0],
    ${$event_area}[1],
    ${$event_area}[2],
    ${$event_area}[3]
    );

use Data::Dumper; print Dumper(\ _);

0;
}

sub update_chart {
    my( $widget, $pos, $traffic ) = @_;
    
    my $blue_gc = new Gtk::Gdk::GC ( $widget->window );   

    $pixmapChart->draw_line(
                            $blue_gc,
                            $margin+$pos,
                            $height-$margin,
                            $margin+$pos,
                            $height-$margin-$traffic
                            );
    print "$pos - $traffic\n";

    $widget->queue_draw_area ($margin+$pos, 
                              $height-$margin,
                              $margin+$pos,
                              $height-$margin-$traffic);    
    return 0;
}

## Main ##

# Top down...
#  For each widget
#  Create, Connect, Set, Pack and Show

$w = new Gtk::Window;
$w->signal_connect('destroy', sub {Gtk->exit(0)});
$w->set_title("Traffic");
$w->show;

$vb = new Gtk::VBox($false,0);
$w->add($vb);

$dareaChart = new Gtk::DrawingArea;
#$dareaChart->set_events( 'exposure_mask' );
$dareaChart->signal_connect( 'expose_event', \&expose_chart );
#$w->signal_connect( 'expose_event', \&expose_chart );

$dareaChart->size( $width, $height );
$vb->add($dareaChart);
configure_chart($dareaChart);
$dareaChart->show;
$dareaChart->realize;

$b = new Gtk::Button("Quit");
$b->signal_connect('clicked', sub {Gtk->exit(0)});
$vb->add($b);

$w->show_all;

###########################################################3

$i=0;
Gtk->timeout_add(1000,
                 sub {
                     ++$i;
                     if($i > 3){
                         $w->show_all;
#           update_chart($dareaChart,10,30);
                     }
                     update_chart($dareaChart,$i,30);
                     while (Gtk->events_pending) {
                         Gtk->main_iteration;
                     }
                     # Exiting with 0 will stop the timer.
                     return 1;
                 }
);

Gtk->main();








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