setting line dash on Gnome2::Canvas

Does anyone know how to make dashed lines
on the Gnome2::Canvas?

I saw some mention of it on the C maillist, but don't
seem to be able to make it work on Perl.

use warnings;
use strict;
use Gtk2 -init;
use Gnome2::Canvas;

my $window = Gtk2::Window->new;
$window ->signal_connect( 'destroy' => sub{Gtk2->main_quit } );
my $scroller = Gtk2::ScrolledWindow->new;

my $canvas = Gnome2::Canvas->new_aa;
$scroller->add ($canvas);

$window->add ($scroller);
$window->set_default_size (350, 350);
$canvas->set_scroll_region (0, 0, 700, 700);

my $black = Gtk2::Gdk::Color->new (0x0000,0x0000,0x0000);

my $line1= Gnome2::Canvas::Item->new ($canvas->root,
                points => [0,20,130,150],
                fill_color => "red",
                width_units => 8.0,
                line_style => 'GDK_LINE_ON_OFF_DASH',

# feeble attempt dosn't work
#$line1->set_dashes( {0,0xff,0,0xff} );

# some stuff from the c mail list
#you can give a line pattern to the function in this way
#gchar list[]={ 0, 0xff, 0, 0xff }
#gdk_gc_set_dashes( gc, 0, list, sizeof(list) / sizeof( gchar) );
#this produces a line like this: - - - - - - - - -
#The offset controls the starting point of the pattern.

#Elements of dash_list give the length (in pixels) of dash segments. n is the
#number of elements in dash_list. dash_offset is the distance (in pixels) to
#start in dash_list.
#gdk_gc_set_dashes( gc, 3, { 6, 3 }, 2 );
#Draws a line which is on for 6 pixels, then off for 3, then on for 6, etc. An
#offset of half the first segments helps lines to match up more cleanly when
#they join. Dash patterns look best with an even number of elements in
#dash_list (obviously).

#Use gdk_gc_set_line_attributes() to turn on GDK_LINE_ON_OFF_DASH or
#GDK_LINE_DOUBLE_DASH to see your pattern.


I'm not really a human, but I play one on earth.

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