Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use warnings; use Goo::Canvas; use Gtk2 '-init'; use Glib qw(TRUE FALSE); my @results; my $r = 0; my $ang = 0; for my $count (1..25){ for my $z(1..100){ $r += .4; $ang += .062832; my $x = $r * cos $ang; my $y = $r * sin $ang; push @results,$x,$y; } } #print "@results\n"; my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_default_size(680, 600); my $vbox = Gtk2::VBox->new; $vbox->set_border_width(4); $vbox->show; my $hbox = Gtk2::HBox->new(FALSE, 4); $vbox->pack_start($hbox, FALSE, FALSE, 0); $hbox->show; $window->add($vbox); my $swin = Gtk2::ScrolledWindow->new; $swin->set_shadow_type('in'); $vbox->pack_start($swin, 1, 1, 0); my $cwidth = 1000; my $cheight = 1000; my ($canvas,$root,$group) = get_canvas(); # Zoom my $z = Gtk2::Label->new("Zoom:"); $hbox->pack_start($z, FALSE, FALSE, 0); $z->show; my $adj = Gtk2::Adjustment->new(1, 0.05, 100, 0.05, 0.5, 0.5); my $sb = Gtk2::SpinButton->new($adj, 0, 2); $adj->signal_connect("value-changed", \&zoom_changed, $canvas); $sb->set_size_request(60, -1); $hbox->pack_start($sb, FALSE, FALSE, 10); $sb->show; # Create PDF + my $bpdf = Gtk2::Button->new_with_label('Write PDF'); + $hbox->pack_start($bpdf, FALSE, FALSE, 0); + $bpdf->show; + $bpdf->signal_connect("clicked", \&write_pdf_clicked, $canvas); + $window->show_all(); &draw(); Gtk2->main; sub get_canvas{ my $canvas = Goo::Canvas->new(); $canvas->set_size_request(600, 450); # minimum size on screen $canvas->set_bounds(0, 0, $cwidth, $cheight); # scrollregion $swin->add($canvas); my $root = $canvas->get_root_item(); $canvas->signal_connect('button-press-event', \&on_can_button_press); my $rect = Goo::Canvas::Rect->new( $root, 0, 0, $cwidth, $cheight, 'line-width' => 1, 'fill-color' => 'black' ); $rect->lower; my $g = Goo::Canvas::Group->new($root); $g->translate(310,300); return ($canvas,$root,$g); } sub draw{ my $points = Goo::Canvas::Points->new(\@results); my $poly = Goo::Canvas::Polyline->new( $group, FALSE, undef, # points need to be set after creation 'stroke-color' => 'pink', # 'fill_color_rgba' => 0xff00ffcc, 'line-width' => 15, ); #setting after line creation, sets the 'points' property by name $poly->set(points => $points); # add some action Glib::Timeout->add (50, sub { $group->scale(1.001,1.001); $group->rotate(-20,0,0); #angle, rot_center_x, rot_cente +r_y #$group->translate(15,15); #make drunk friends puke :-) return 1; }); return 0; } sub write_pdf_clicked { my ($but, $canvas) = @_; print "Write PDF...\n"; my $scale = $adj->get_value; print "scale->$scale\n"; my $surface = Cairo::PdfSurface->create("$0-$scale.pdf", $scale*$cwidth, $scale*$cheight); my $cr = Cairo::Context->create($surface); # needed to save scaled version $cr->scale($scale, $scale); $canvas->render($cr, undef, 1); $cr->show_page; print "done\n"; return TRUE; } sub zoom_changed { my ($adj, $canvas) = @_; my $scale = $adj->get_value; $canvas->set_scale($scale); # zoom from 0,0 ...like Gnome2::Canvas's set_center_scroll_region +(FALSE); $canvas->scroll_to (0,0); }

In reply to Goo'ey Waves of Goo_ness by zentara

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-23 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found