Goo::Canvas(3)

πŸ“¦
version 0.06 Β· 2 versions
, in fedora 43

πŸ’– Goo::Canvas πŸ’–

okay bestie, welcome to the Goo::Canvas(3) page β€” yes, it's a perl thing, yes it's user-contributed documentation, and yes we're gonna make it cute. this is literally just a lil wrapper for GooCanvas and it's about to be your new obsession 🎨✨


🌸 HIERARCHY 🌸

the family tree, and she's got ancestors:

Glib::Object
+----Glib::InitiallyUnowned
     +----Gtk2::Object
          +----Gtk2::Widget
               +----Gtk2::Container
                    +----Goo::Canvas

look at that lineage. main character energy fr fr πŸ‘‘


πŸ¦‹ INTERFACES πŸ¦‹

she also implements these, no cap:

Glib::Object::_Unregistered::AtkImplementorIface
Gtk2::Buildable

✨ SYNOPSIS ✨

here's the whole vibe, copy-paste ready, exactly as-is:

use Goo::Canvas;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_default_size(640, 600);

my $swin = Gtk2::ScrolledWindow->new;
$swin->set_shadow_type('in');
$window->add($swin);

my $canvas = Goo::Canvas->new();
$canvas->set_size_request(600, 450);
$canvas->set_bounds(0, 0, 1000, 1000);
$swin->add($canvas);

my $root = $canvas->get_root_item();
my $rect = Goo::Canvas::Rect->new(
    $root, 100, 100, 400, 400,
    'line-width' => 10,
    'radius-x' => 20,
    'radius-y' => 10,
    'stroke-color' => 'yellow',
    'fill-color' => 'red'
);
$rect->signal_connect('button-press-event',
                      \&on_rect_button_press);

my $text = Goo::Canvas::Text->new(
    $root, "Hello World", 300, 300, -1, 'center',
    'font' => 'Sans 24',
);
$text->rotate(45, 300, 300);
$window->show_all();
Gtk2->main;

sub on_rect_button_press {
    print "Rect item pressed!\n";
    return TRUE;
}

like. she ate. a red rounded rectangle AND rotated hello-world text?? iconic πŸ’…


🌈 DESCRIPTION 🌈

so here's the tea: GTK+ doesn't has an built-in canvas widget. (that's a direct quote, we're keeping it, it's part of her charm πŸ₯°)

GooCanvas is wonderful. it is easy to use and has powerful and extensible methods to create items in canvas. just try it. genuinely just try it, bestie, you'll be obsessed.

for more documents, please read the GooCanvas Manual and the demo programs provided in the source distribution in both perl-Goo::Canvas and GooCanvas. iykyk πŸ“š


πŸŽ€ METHODS πŸŽ€

grab a snack, this list is long, but every single one matters:

  • widget = Goo::Canvas->new β€” makes you a brand new canvas widget, baby's first canvas 🍼
  • list = $canvas->get_bounds β€” hands you back the bounds as a list
  • $canvas->set_bounds ($left, $top, $right, $bottom) β€” sets the bounds. args:
    • $left (double)
    • $top (double)
    • $right (double)
    • $bottom (double)
  • cairo_surface_t = $pixbuf->cairo_surface_from_pixbuf β€” turns a pixbuf into a cairo surface, glow-up complete ✨
  • $canvas->convert_from_item_space ($item, $x, $y) β€” coords from item space β†’ wherever. args:
    • $item (Goo::Canvas::Item)
    • $x (double)
    • $y (double)
  • $canvas->convert_from_pixels ($x, $y) β€” pixels out, units in. args:
    • $x (double)
    • $y (double)
  • $canvas->convert_to_item_space ($item, $x, $y) β€” the reverse trip, into item space. args:
    • $item (Goo::Canvas::Item)
    • $x (double)
    • $y (double)
  • $canvas->convert_to_pixels ($x, $y) β€” coords β†’ pixels. args:
    • $x (double)
    • $y (double)
  • item = $canvas->create_item ($model) β€” spawns an item from a model. arg:
    • $model (Goo::Canvas::ItemModel)
  • $commands->create_path ($cr) β€” makes a path. arg:
    • $cr (cairo_t)
  • double = $canvas->get_default_line_width β€” the default line width, as a double
  • $canvas->grab_focus ($item) β€” gives focus to an item. arg:
    • $item (Goo::Canvas::Item)
  • item = $canvas->get_item_at ($x, $y, $is_pointer_event) β€” which item is at this spot? args:
    • $x (double)
    • $y (double)
    • $is_pointer_event (boolean)
  • item = $canvas->get_item ($model) β€” get the item for a model. arg:
    • $model (Goo::Canvas::ItemModel)
  • arrayref = $canvas->get_items_at ($x, $y, $is_pointer_event) β€” like the above but you get ALL of them in an arrayref. args:
    • $x (double)
    • $y (double)
    • $is_pointer_event (boolean)
  • arrayref = $canvas->get_items_in_area ($area, $inside_area, $allow_overlaps, $include_containers) β€” everything in an area, arrayref style. args:
    • $area (GooCanvasBounds)
    • $inside_area (boolean)
    • $allow_overlaps (boolean)
    • $include_containers (boolean)
  • grabstatus = $canvas->keyboard_grab ($item, $owner_events, $time) β€” keyboard grab, returns a grabstatus. args:
    • $item (Goo::Canvas::Item)
    • $owner_events (boolean)
    • $time (unsigned)
  • $canvas->keyboard_ungrab ($item, $time) β€” let that keyboard go. args:
    • $item (Goo::Canvas::Item)
    • $time (unsigned)
  • GArray = $path_data->parse_path_data β€” parses path data into a GArray
  • grabstatus = $canvas->pointer_grab ($item, $event_mask, $cursor, $time) β€” pointer grab, also returns a grabstatus. args:
    • $item (Goo::Canvas::Item)
    • $event_mask (Gtk2::Gdk::EventMask)
    • $cursor (Gtk2::Gdk::Cursor) β€” the cursor to display during the grab, or undef means no change
    • $time (unsigned)
  • $canvas->pointer_ungrab ($item, $time) β€” release the pointer. args:
    • $item (Goo::Canvas::Item)
    • $time (unsigned)
  • $canvas->register_widget_item ($witem) β€” registers a widget item. arg:
    • $witem (Goo::Canvas::Widget)
  • $canvas->render ($cr, $bounds, $scale) β€” renders the canvas. args:
    • $cr (cairo_t)
    • $bounds (GooCanvasBounds)
    • $scale (double)
  • $canvas->request_redraw ($bounds) β€” pls redraw this region πŸ™ arg:
    • $bounds (GooCanvasBounds)
  • $canvas->request_update β€” pls update
  • item = $canvas->get_root_item β€” the root item itself
  • itemmodel = $canvas->get_root_item_model β€” the root item model itself
  • $canvas->set_root_item_model ($model) β€” set the root item model. arg:
    • $model (Goo::Canvas::ItemModel)
  • $canvas->set_root_item ($item) β€” set the root item. arg:
    • $item (Goo::Canvas::Item)
  • double = $canvas->get_scale β€” the scale, as a double
  • $canvas->set_scale ($scale) β€” set the scale. arg:
    • $scale (double)
  • $canvas->scroll_to ($left, $top) β€” scroll scroll scroll. args:
    • $left (double)
    • $top (double)
  • $canvas->unregister_item ($model) β€” un-register an item. arg:
    • $model (Goo::Canvas::ItemModel)
  • $canvas->unregister_widget_item ($witem) β€” un-register a widget item. arg:
    • $witem (Goo::Canvas::Widget)
  • $canvas->update β€” update time

πŸ’œ PROPERTIES πŸ’œ

every property, with its type, default, and access level. no skips, no cuts 🫢

  • 'anchor' (Gtk2::AnchorType : default "north-west" : readable / writable) β€” where to place the canvas when it is smaller than the widget's allocated area
  • 'automatic-bounds' (boolean : default false : readable / writable) β€” if the bounds are automatically calculated based on the bounds of all the items in the canvas
  • 'background-color' (string : default undef : writable) β€” the color to use for the canvas background
  • 'background-color-rgb' (Glib::UInt : default 0 : writable) β€” the color to use for the canvas background, specified as a 24-bit integer value, 0xRRGGBB
  • 'bounds-from-origin' (boolean : default true : readable / writable) β€” if the automatic bounds are calculated from the origin
  • 'bounds-padding' (double : default 0 : readable / writable) β€” the padding added to the automatic bounds
  • 'clear-background' (boolean : default true : readable / writable) β€” if the background is cleared before the canvas is painted
  • 'integer-layout' (boolean : default false : readable / writable) β€” if all item layout is done to the nearest integer
  • 'redraw-when-scrolled' (boolean : default false : readable / writable) β€” if the canvas is completely redrawn when scrolled, to reduce the flicker of static items
  • 'resolution-x' (double : default 96 : readable / writable) β€” the horizontal resolution of the display, in dots per inch
  • 'resolution-y' (double : default 96 : readable / writable) β€” the vertical resolution of the display, in dots per inch
  • 'scale' (double : default 1 : readable / writable) β€” the magnification factor of the canvas
  • 'scale-x' (double : default 1 : readable / writable) β€” the horizontal magnification factor of the canvas
  • 'scale-y' (double : default 1 : readable / writable) β€” the vertical magnification factor of the canvas
  • 'units' (Gtk2::Unit : default "pixel" : readable / writable) β€” the units to use for the canvas
  • 'x1' (double : default 0 : readable / writable) β€” the x coordinate of the left edge of the canvas bounds, in canvas units
  • 'x2' (double : default 1000 : readable / writable) β€” the x coordinate of the right edge of the canvas bounds, in canvas units
  • 'y1' (double : default 0 : readable / writable) β€” the y coordinate of the top edge of the canvas bounds, in canvas units
  • 'y2' (double : default 1000 : readable / writable) β€” the y coordinate of the bottom edge of the canvas bounds, in canvas units

πŸ”₯ SIGNALS πŸ”₯

only two but they're both doing their thing:

  • item-created (Goo::Canvas, Goo::Canvas::Item, Goo::Canvas::ItemModel)
  • set-scroll-adjustments (Goo::Canvas, Gtk2::Adjustment, Gtk2::Adjustment)

🧚 ENUMS AND FLAGS 🧚

enum Gtk2::AnchorType

all the anchors, each one with its C name bestie:

  • 'center' / GTK_ANCHOR_CENTER
  • 'north' / GTK_ANCHOR_NORTH
  • 'north-west' / GTK_ANCHOR_NORTH_WEST
  • 'north-east' / GTK_ANCHOR_NORTH_EAST
  • 'south' / GTK_ANCHOR_SOUTH
  • 'south-west' / GTK_ANCHOR_SOUTH_WEST
  • 'south-east' / GTK_ANCHOR_SOUTH_EAST
  • 'west' / GTK_ANCHOR_WEST
  • 'east' / GTK_ANCHOR_EAST
  • 'n' / GTK_ANCHOR_N
  • 'nw' / GTK_ANCHOR_NW
  • 'ne' / GTK_ANCHOR_NE
  • 's' / GTK_ANCHOR_S
  • 'sw' / GTK_ANCHOR_SW
  • 'se' / GTK_ANCHOR_SE
  • 'w' / GTK_ANCHOR_W
  • 'e' / GTK_ANCHOR_E

flags Gtk2::Gdk::EventMask

the mask collection, and it is LONG, and we love her for it:

  • 'exposure-mask' / GDK_EXPOSURE_MASK
  • 'pointer-motion-mask' / GDK_POINTER_MOTION_MASK
  • 'pointer-motion-hint-mask' / GDK_POINTER_MOTION_HINT_MASK
  • 'button-motion-mask' / GDK_BUTTON_MOTION_MASK
  • 'button1-motion-mask' / GDK_BUTTON1_MOTION_MASK
  • 'button2-motion-mask' / GDK_BUTTON2_MOTION_MASK
  • 'button3-motion-mask' / GDK_BUTTON3_MOTION_MASK
  • 'button-press-mask' / GDK_BUTTON_PRESS_MASK
  • 'button-release-mask' / GDK_BUTTON_RELEASE_MASK
  • 'key-press-mask' / GDK_KEY_PRESS_MASK
  • 'key-release-mask' / GDK_KEY_RELEASE_MASK
  • 'enter-notify-mask' / GDK_ENTER_NOTIFY_MASK
  • 'leave-notify-mask' / GDK_LEAVE_NOTIFY_MASK
  • 'focus-change-mask' / GDK_FOCUS_CHANGE_MASK
  • 'structure-mask' / GDK_STRUCTURE_MASK
  • 'property-change-mask' / GDK_PROPERTY_CHANGE_MASK
  • 'visibility-notify-mask' / GDK_VISIBILITY_NOTIFY_MASK
  • 'proximity-in-mask' / GDK_PROXIMITY_IN_MASK
  • 'proximity-out-mask' / GDK_PROXIMITY_OUT_MASK
  • 'substructure-mask' / GDK_SUBSTRUCTURE_MASK
  • 'scroll-mask' / GDK_SCROLL_MASK
  • 'all-events-mask' / GDK_ALL_EVENTS_MASK

enum Gtk2::Gdk::GrabStatus

how the grab went, possibilities:

  • 'success' / GDK_GRAB_SUCCESS
  • 'already-grabbed' / GDK_GRAB_ALREADY_GRABBED
  • 'invalid-time' / GDK_GRAB_INVALID_TIME
  • 'not-viewable' / GDK_GRAB_NOT_VIEWABLE
  • 'frozen' / GDK_GRAB_FROZEN

enum Gtk2::Unit

units bestie, pick your fighter:

  • 'pixel' / GTK_UNIT_PIXEL
  • 'points' / GTK_UNIT_POINTS
  • 'inch' / GTK_UNIT_INCH
  • 'mm' / GTK_UNIT_MM

πŸ’« SEE ALSO πŸ’«

go read these too, they're the whole support system:

Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget, Gtk2::Container


Copyright (C) 2025 Gtk2-Perl Team


and that's the whole page bestie!! πŸŽ‰ this one's perl v5.42.0, dated 2025-07-25, and it's a User Contributed Perl Documentation situation β€” so go forth, build canvases, and slay πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from