Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

usage on get_simple_transform on goocanvas

by renegadex (Beadle)
on Oct 02, 2008 at 04:13 UTC ( #714950=perlquestion: print w/replies, xml ) Need Help??

renegadex has asked for the wisdom of the Perl Monks concerning the following question:

how can I use this using perl and goo::canvas? please see the documentation: i have tried the following.
my $x; my $y; my $scale; my $angle; $canvasitem->get_simple_transform($x,$y,$scale,$angle);
print $canvasitem->get_simple_transform;
all of this gives me an error, "something is very broken"

Replies are listed 'Best First'.
Re: usage on get_simple_transform on goocanvas
by zentara (Archbishop) on Oct 02, 2008 at 11:57 UTC
    First, there is no get_simple_transform in Goo. There is a set, but no get.

    Second, if I chnage

    my ($x, $y, $scale, $angle) = $group->get_simple_transform; #to my ($x, $y, $scale, $angle) = $group->get_transform;
    I get a crash saying
    *** glibc detected *** /usr/bin/perl: double free or corruption (out): + 0x08157b18 *** ======= Backtrace: ========= /lib/[0xb7dc0c23] etc etc

    I have 2 thoughts.

    First, it may be a bug. The Goo::Canvas is still in development and possibly this is a glitch.

    Second, (and most likely), you can't call get_transform on a group, you may need a GroupModel. If you look at the manpages for Goo, you will see that Group descends from ItemSimple, which has very few methods available to it. However GroupModel descends from ItemModel, which has a wide assortment of methods available.

    The question was asked before, I think by you, "what is the difference between 'X' and 'X'Model? ". I think you are getting an answer to your question. Look at the difference between the and the in the Goo demo subdir. The uses the Model approach, and the uses the simple approach. You cannot just convert the script by appending Model to your Item names, you need to write the script differently.

    I tried to call $group->get_transform in the, and it did not crash the program, while calling it in your script does. The difference? uses the GroupModel, while you are using the simple Group.

    After studying the, it is not trivial to convert your program. If you don't want to alter it to the Model style, you may have to resort to manually saving transforms yourself.

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: usage on get_simple_transform on goocanvas
by apl (Monsignor) on Oct 02, 2008 at 10:00 UTC
    Could you possibly show us any more of the code? How do you specify that you're using goo::canvas? What creates/initializes $canvasitem? Did you use strict; use warnings;? Did you contact any forum or mailing list that uses/supports the library?

    I don't mean to be harsh, but I didn't read the documentation, and I doubt few monks will.

      here is my test program.
      #!/usr/bin/perl -w # Research For Goo::Canvas Scaling use strict; use Gtk2 '-init'; use Goo::Canvas; my $rect; my $window = Gtk2::Window->new; $window->signal_connect(destroy=>sub{Gtk2->main_quit;}); $window->fullscreen; my $canvas = Goo::Canvas->new; #$canvas->set('integer-layout',1); $canvas->set_size_request(1020,500); $canvas->set_bounds(0,0,1000,500); $canvas->set_scale(1); $canvas->set('background-color','white'); my $base = Goo::Canvas::Group->new($canvas->get_root_item); $base->set('line-width','1','stroke-color','black'); my $vbox = Gtk2::VBox->new; my $holder = Goo::Canvas::Group->new($base); $holder->set_simple_transform((1000/2)-(200/2),(500/2)-(200/2),1,0); $holder->{'x'} = (1000/2)-(200/2); $holder->{'y'} = (500/2)-(200/2); $holder->{'scale'} = 1; $holder->{'angle'} = 0; $holder->{'width'} = 200; $holder->{'height'} = 200; for(my $i = 0; $i <= 1000; $i+=50){ my $line= Goo::Canvas::Polyline->new_line($base,$i,0,$i,700); } for(my $i = 0; $i <= 500; $i+=50){ my $line= Goo::Canvas::Polyline->new_line($base,0,$i,1000,$i); } $rect = Goo::Canvas::Rect->new ($holder,0,0,200,200,'stroke-color','re +d','line-width',5,'fill-color','white'); $rect->signal_connect('motion_notify_event', \&on_motion_notify); $rect->signal_connect('button_press_event', \&on_button_press); $rect->signal_connect('button_release_event', \&on_button_release); my $line= Goo::Canvas::Polyline->new_line($holder,100,0,100,200,'line- +width',1,'stroke-color','blue'); $line= Goo::Canvas::Polyline->new_line($holder,0,100,200,100,'line-wid +th',1,'stroke-color','blue'); $line= Goo::Canvas::Polyline->new_line($holder,0,125,200,125,'line-wid +th',1,'stroke-color','red'); $line= Goo::Canvas::Polyline->new_line($holder,0,75,200,75,'line-width +',1,'stroke-color','red'); $line= Goo::Canvas::Polyline->new_line($holder,125,0,125,200,'line-wid +th',1,'stroke-color','green'); $line= Goo::Canvas::Polyline->new_line($holder,75,0,75,200,'line-width +',1,'stroke-color','green'); my $hbox = Gtk2::HBox->new; my $button = Gtk2::Button->new("Scale Up!"); $button->signal_connect('clicked',sub {scale_norm(.01,$holder);}); $hbox->pack_start($button,0,1,0); $button = Gtk2::Button->new("Scale Down!"); $button->signal_connect('clicked',sub {scale_norm(-.01,$holder);}); $hbox->pack_start($button,0,1,0); $vbox->pack_start($canvas,0,1,0); $vbox->pack_start($hbox,0,1,0); $window->add($vbox); $window->show_all; Gtk2->main; sub scale_norm { my ($factor,$group) = @_; $group->{'scale'}+=$factor; $group->{'x'}-= (($group->{'width'} * $group->{'scale'}) - $group- +>{'width'})/2; $group->set_simple_transform($group->{'x'},$group->{'y'},$group->{ +'scale'},$group->{'angle'}); # I WANT TO GET THE SIMPLE TRANSFORM VALUES SUCH AS THE X AND Y CO +ORDS AND SCALE AND ANGLE # # WITHOUT USING THE DATA RIDER THAT I MADE. PUT A COMMENT ON THE N +EXT LINE TO MAKE IT RUN # my ($x, $y, $scale, $angle) = $group->get_simple_transform; } sub on_motion_notify { my ($item, $target, $event) = @_; $item->{'mouse'}->{'x'} = $event->x; $item->{'mouse'}->{'y'} = $event->y; my $canvas = $item->get_canvas; $canvas->grab_focus($item); if ( $item->{dragging} && $event->state >= 'button1-mask' ) { #($item->get('parent'))->translate($event->x - $item->{drag_x} +,$event->y - $item->{drag_y}); my $holder = $item->get('parent'); $holder->set_simple_transform($holder->{'x'} + $event->x - $it +em->{drag_x},$holder->{'y'} + $event->y - $item->{drag_y},$holder->{' +scale'},$holder->{'angle'}); $holder->{'x'} += $event->x - $item->{drag_x}; $holder->{'y'} += $event->y - $item->{drag_y}; #print $holder->{'x'} , ' - ' , $holder->{'y'} , "\n"; } return 1; } sub on_button_press { my ($item, $target, $ev) = @_; if ( $ev->button == 1 ) { if ( $ev->state >= 'shift-mask' ) { } else { $item->{drag_x} = $ev->x; $item->{drag_y} = $ev->y; my $fleur = Gtk2::Gdk::Cursor->new('fleur'); my $canvas = $item->get_canvas; $canvas->pointer_grab($item, ['pointer-motion-mask', 'butt +on-release-mask'],$fleur, $ev->time); $item->{dragging} = 1; } } return 1; } sub on_button_release { my ($item, $target, $ev) = @_; my $canvas = $item->get_canvas; $canvas->pointer_ungrab($item, $ev->time); $item->{dragging} = 0; return 1; }
        Sorry can't test that, but since the string get_simple_transform is not found anywhere in the perl bindings, I don't think its available (I could be wrong).
Re: usage on get_simple_transform on goocanvas
by Anonymous Monk on Oct 02, 2008 at 06:43 UTC
    What do you mean?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://714950]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2023-05-29 18:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found