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

In reply to Re^7: geoTiff Application Building by zentara
in thread geoTiff Application Building by deadpickle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.