in reply to Re^6: geoTiff Application Building
in thread geoTiff Application Building

UPDATE 6/3/2008 ..... I found the mouse position error, It was caused by the scrollregion being made smaller than the default canvas size!! See fixed code below.

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__

I'm not really a human, but I play one on earth CandyGram for Mongo

Replies are listed 'Best First'.
Re^8: geoTiff Application Building
by zentara (Cardinal) on Jun 03, 2008 at 11:56 UTC
    UPDATE.... see fix above.....it just goes to show how one stupid sizing error can lead to multiple corrective hacks :-)

    It has something to do with groups and centering.

    It seems to be more than that, it also has something to do with the scrollregion. If I adjust the scrollregion, it seems to work, but as to why? I'm still experimenting. :-) Moving the canvas -50 -50 still is a complete mystery. It must be something so obvious, that I'm completely missing it.

    $canvas->set_scroll_region( -20, -20, 400, 400 );

    I'm not really a human, but I play one on earth CandyGram for Mongo