GooCanvas2(3) User Contributed Perl Documentation GooCanvas2(3)

GooCanvas2 - Perl binding for GooCanvas2 widget using Glib::Object::Introspection

#!/usr/bin/perl -w
use strict;
use warnings;
use Gtk3 -init;
use GooCanvas2;

my $window = Gtk3::Window->new();
$window->set_default_size(640, 600);
$window->signal_connect('destroy' => sub {Gtk3->main_quit()});
my $scrolled_win = Gtk3::ScrolledWindow->new();
$scrolled_win->set_shadow_type('in');
my $canvas = GooCanvas2::Canvas->new();
$canvas->set_size_request(600,450);
$canvas->set_bounds(0,0,1000,1000);
$scrolled_win->add($canvas);
my $root = $canvas->get_root_item();
# Add a few simple items
my $rect_item = GooCanvas2::CanvasRect->new('parent' => $root,
                                        'x' => 100,
                                        'y' => 100,
                                        'width' => 300,
                                        'height' => 300,
                                        'line_width' => 10.0,
                                        'radius-x' => 20.0,
                                        'radius-y' => 10.0,
                                        'stroke-color' => 'yellow',
                                        'fill-color' => 'red');
my $text_item = GooCanvas2::CanvasText->new('parent' => $root,
                                        'text' => 'Hello World',
                                        'x' => 300, 'y' => 300, 
                                        'width' => -1,
                                        'anchor' => 'center',
                                        'font' => 'Sans 24');
$text_item->rotate(45, 300, 300);
# Connect a signal handler for the rectangle item.
$rect_item->signal_connect('button_press_event' => \&on_rect_button_press);
$window->add($scrolled_win);
$window->show_all;
# Pass control to the Gtk3 main event loop
Gtk3->main();
# This handles button presses in item views. 
#We simply output a message to the console
sub on_rect_button_press {
        my ($item, $target, $event) = @_;
        print "rect item received button press event \n";
        return 1;
}

You need to install the typelib file for GooCanvas-2.0. For example on Debian/Ubuntu it should be necessary to install the following package:

sudo apt-get install gir1.2-goocanvas-2.0

On Mageia for example you have to install:

urpmi lib64goocanvas-gir2.0

GooCanvas2 is a new canvas widget for use with Gtk3 that uses the Cairo 2d library for drawing. This is a simple and basic implementation of this wonderful Canvas widget.

For more informations see https://wiki.gnome.org/action/show/Projects/GooCanvas

For instructions, how to use GooCanvas2, please study the API reference at https://developer.gnome.org/goocanvas/unstable/ for now. A perl-specific documentation will perhaps come in later versions. But applying the C documentation should be no problem.

The GooCanvas2 module provides the following objects, items and models. For more details see https://wiki.gnome.org/action/show/Projects/GooCanvas.

Core Objects

  • GooCanvas2::Canvas - the main canvas widget
  • GooCanvas2::CanvasItem - the interface for canvas items
  • GooCanvas2::CanvasItemModel - the interface for canvas item models.
  • GooCanvas2::CanvasItemSimple - the base class for the standard canvas items.
  • GooCanvas2::CanvasItemModelSimple - the base class for the standard canvas item models.
  • GooCanvas2::CanvasStyle - support for cascading style properties for canvas items.

Standard Canvas Items

  • GooCanvas2::CanvasGroup - a group of items.
  • GooCanvas2::CanvasEllipse - an ellipse item.
  • GooCanvas2::CanvasGrid - a grid item.
  • GooCanvas2::CanvasImage - an image item.
  • GooCanvas2::CanvasPath - a path item (a series of lines and curves).
  • GooCanvas2::CanvasPolyline - a polyline item (a series of lines with optional arrows).
  • GooCanvas2::CanvasRect - a rectangle item.
  • GooCanvas2::CanvasText - a text item.
  • GooCanvas2::CanvasWidget - an embedded widget item.
  • GooCanvas2::CanvasTable - a table container to layout items.

Standard Canvas Item Models

  • GooCanvas2::CanvasGroupModel - a model for a group of items.
  • GooCanvas2::CanvasEllipseModel - a model for ellipse items.
  • GooCanvas2::CanvasGridModel - a model for grid items.
  • GooCanvas2::CanvasImageModel - a model for image items.
  • GooCanvas2::CanvasPathModel - a model for path items (a series of lines and curves).
  • GooCanvas2::CanvasPolylineModel - a model for polyline items (a series of lines with optional arrows).
  • GooCanvas2::CanvasRectModel - a model for rectangle items.
  • GooCanvas2::CanvasTextModel - a model for text items.
  • GooCanvas2::CanvasTableModel - a model for a table container to layout items.

Customizations and overrides

In order to make things more Perlish, GooCanvas2 customizes the API generated by Glib::Object::Introspection in a few spots:

The array ref normally returned by the following functions is flattened into a list:

Maximilian Lika, <Maximilian-Lika@gmx.de>

Copyright (C) 2017 by Maximilian Lika

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.22.3 or, at your option, any later version of Perl 5 you may have available.

2024-07-13 perl v5.38.2