Re: Goo::Canvas::Polyline acts not as expected



 > Subject: Re: Goo::Canvas::Polyline acts not as expected
 > From: volkening mailshack com
 > To: gtk-perl-list gnome org
 > Date: Thu, 22 Apr 2010 10:46:10 -0400
 >
 > On Thu, 2010-04-22 at 05:39 +0000, Xi Yang wrote:
 > > Hi everyone:
 > >
 > > I tried to use Polyline to make a part of another complexed widget.
 > > However, it seems the Polyline object always use its north-west of
 > > boundingbox as its (0,0) point. For instance:
 > >
 > > ###################################
 > >
 > > my $sz = 10;
 > >
 > > my $coll_anchor = Goo::Canvas::Polyline->new(
 > > $self,
 > > TRUE,
 > > [0,$sz,$sz,0,0,-$sz,-$sz,0],
 > > );
 > >
 > > ###################################
 > >
 > > I expect this should draw a diamond, with its center on (0,0) point.
 >
 >
 > It wo rks for me as expected. I don't suppose you've set these two
 > properties on your canvas at some point:
 >
 > $canvas->set(
 > 'automatic-bounds' => TRUE,
 > 'bounds-from-origin' => FALSE,
 > )
 >
 > This would cause the canvas to automatically adjust to fit your drawing.
 > Your diamond would still be centered at (0,0), but (0,0) would no longer
 > be in the top-left corner of the canvas.
 >
 > Jeremy
 >
 >
 >
 > _______________________________________________
 > gtk-perl-list mailing list
 > gtk-perl-list gnome org
 > http://mail.gnome.org/mailman/listinfo/gtk-perl-list

That is not the point. Actually, I place the polyline in an 
Goo::Canvas::Group, and the Group is placed at (100,100). After drawing, 
the diamond's left-top corner of its boundingbox is placed at Group's (0,0).


It still works as expected for me. For example:

use strict;
use warnings;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
use Goo::Canvas;

my $mw = Gtk2::Window->new( 'toplevel' );
$mw->signal_connect( 'delete_event' => sub {Gtk2->main_quit} );

my $canvas = Goo::Canvas->new;
my $maingroup = Goo::Canvas::Group->new( $canvas->get_root_item() );

my $box = Goo::Canvas::Path->new(
    $maingroup,
    "M0,0 L0,50 L50,50 L50,0 z",
    'line-width'        => 1,
    'stroke-color-rgba' => 0xff0000ff,
);

my $sz = 10;
my $coll_anchor = Goo::Canvas::Polyline->new(
    $maingroup,
    TRUE,
    [0,$sz,$sz,0,0,-$sz,-$sz,0],
);

$maingroup->translate(100,100);
$mw->add($canvas);
$mw->show_all;
Gtk2->main();


This should draw a red square with upper-left corner at [100,100] in
canvas coordinates. Your diamond should be centered around the
upper-left corner of the square. If this isn't what you get, either you
have a platform/version-specific bug in goocanvas or there's something
else going on. The only other possibility I can think of off-hand is if
you have explicitly set the 'x' and 'y' properties of the Polyline,
which sets not the origin of the item but the left and top bounding edges.

Perhaps you can post a stripped-down version of the code giving you the
problem.  Good luck.

Jeremy




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