I'm not sure on the best way to filter out the extra line segment, it seems like a college level math problem, but the first thing that comes to mind is to just make a single line with multiple points. That way you just push the new waypoint onto the points for the line. Each waypath is just a single line with multiple points. This is just a simple example, but should show the idea. Like you, I can't get the mouse coordinates to line up. I'm totally confused on it and will ask on the maillist. It has something to do with groups and centering.
#!/usr/bin/perl use warnings; use strict; use Gtk2 -init; use Gnome2::Canvas; my $window = Gtk2::Window->new; $window->signal_connect( destroy => sub { exit } ); my $scroller = Gtk2::ScrolledWindow->new; my $canvas = Gnome2::Canvas->new(); $scroller->add( $canvas ); $window->add( $scroller ); $window->set_default_size( 500, 500 ); # if scrollregion is smaller than default_size, a weird # coordinate transform occurs # $canvas->set_scroll_region( 0, 0, 400, 400 ); # bad $canvas->set_scroll_region( 0, 0, 700, 700 ); # works good $window->show_all; my $root = $canvas->root; # a stupid hack to try and compensate for bad scrollregion ;-( #$root->move(-50,-50); # dumb my $text = Gnome2::Canvas::Item->new( $root, 'Gnome2::Canvas::Text', x => 20, y => 15, fill_color => 'black', font => 'Sans 14', anchor => 'GTK_ANCHOR_NW', text => 'Click to add waypoint' ); $canvas->signal_connect (event => \&event_handler); my $points = [0,0,100,100]; my $line2= Gnome2::Canvas::Item->new ($root, 'Gnome2::Canvas::Line', points => $points, fill_color => "red", width_units => 3.0, cap_style => 'projecting', join_style => 'miter', ); my $p = $line2->get('points'); print "@$p\n"; my ($x,$y) = @$p; Gtk2->main; ############################## sub event_handler{ my ( $widget, $event ) = @_; # print $widget ,' ',$event->type,"\n"; if ( $event->type eq "button-press" ) { print 'x->',$event->x,' ','y->',$event->y,"\n"; push @$points,$event->x , $event->y; $line2->set(points=>$points); my $p = $line2->get('points'); print "@$p\n"; } } __END__
In reply to Re^7: geoTiff Application Building
by zentara
in thread geoTiff Application Building
by deadpickle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |