Re: dragging text on Gnome2Canvas -- answered
- From: zentara <zentara1 sbcglobal net>
- To: gtk-perl-list gnome org
- Subject: Re: dragging text on Gnome2Canvas -- answered
- Date: Thu, 26 Oct 2006 12:16:14 -0400
On Tue, 24 Oct 2006 12:19:17 -0400
zentara <zentara1 sbcglobal net> wrote:
Hi, I have a glitch here which I can't explain.
Well I dissected the Gnome2::Canvas demo, and found
out that text items need to be in a group, and that you
signal connect and drag the group.
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 '-init';
use Gnome2::Canvas;
my ( $dragging, $last_x, $last_y );
my $mw = Gtk2::Window->new;
$mw->signal_connect( destroy => sub { exit } );
my $vbox = Gtk2::VBox->new( 0, 0 );
$mw->add($vbox);
my $canvas = Gnome2::Canvas->new_aa();
$vbox->pack_start( $canvas, 1, 1, 0 );
$canvas->set_size_request( 300, 300 );
$canvas->set_scroll_region( 0, 0, 300, 300 );
my $quit = Gtk2::Button->new("Quit");
$quit->signal_connect( clicked => sub { exit } );
$vbox->pack_start( $quit, 0, 0, 0 );
$mw->show_all();
place_objects_on_canvas();
Gtk2->main();
##########################################################
sub place_objects_on_canvas {
my $root = $canvas->root();
for my $p (
[ 50, 50, "green" ],
[ 50, 250, "orange" ],
[ 250, 50, "yellow" ],
[ 250, 250, "blue" ]
)
{
my ( $x, $y, $color ) = @$p;
# Put a circle on the graph
my $item = Gnome2::Canvas::Item->new(
$root, "Gnome2::Canvas::Ellipse",
x1 => $x - 16,
y1 => $y - 16,
x2 => $x + 16,
y2 => $y + 16,
fill_color => $color,
outline_color => "black",
);
# add group
my $group = Gnome2::Canvas::Item->new ($root,
'Gnome2::Canvas::Group', x => $x,
y => $y);
my $text = Gnome2::Canvas::Item->new ($group, 'Gnome2::Canvas::Text',
text => 'Z',
font => 'arial 30',
x => 0 , # 0 position in group
y => 0 ,
anchor => 'w',
fill_color => 'black');
# Make them movable
$item->signal_connect( "event", \&item_move );
$group->signal_connect( "event", \&item_move );
}
}
######################################################
sub item_move {
my ( $item, $event ) = @_;
print "$item $event\n";
if ( $event->type eq "button-press" ) {
$item->raise_to_top();
$last_x = $event->x;
$last_y = $event->y;
$dragging = 1;
}
elsif ( $event->type eq "motion-notify" ) {
if ($dragging) {
my $new_x = $event->x;
my $new_y = $event->y;
$item->move( $new_x - $last_x, $new_y - $last_y );
$last_x = $new_x;
$last_y = $new_y;
}
}
elsif ( $event->type eq "button-release" ) {
$dragging = 0;
}
return 0;
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]