Gtk2::Gdk::Region(3)
π Gtk2::Gdk::Region π
okay bestie, so this is Gtk2::Gdk::Region β it's a lil wrapper around the C thing called GdkRegion, and it lives in the Gtk2 Perl docs (perl v5.42.0, user contributed, the whole vibe). Regions are basically shapes you can mash together, and this page is your cheat sheet for all of it. π¦
πΈ HIERARCHY πΈ
so here's the family tree, and yes it's giving only-child energy:
Glib::Boxed
+----Gtk2::Gdk::Region
β¨ METHODS β¨
π Constructors & basics
region = Gtk2::Gdk::Region->newβ makes you a shiny brand new region, from nothing. iconic.rectangle = $region->get_clipboxβ hands you the smallest rectangle that fully contains the region (the bounding box, bestie).boolean = $region->emptyβ true if the region has literally nothing in it. empty. void. no thoughts head empty. π«Άboolean = $region1->equal ($region2)β are these two regions the same shape? true/false, no cap.$region2(Gtk2::Gdk::Region)
list = $region->get_rectanglesβ returns a list of rectangles (Gtk2::Gdk::Rectangle's) covering the area of the region. it's the region, but decomposed into lil rectangles. β¨
π Set operations (the fun part)
$source1->intersect ($source2)β keeps only the overlap between the two. the shared vibes only.$source2(Gtk2::Gdk::Region)
$source1->subtract ($source2)β takes$source2's area away from$source1. bye bye.$source2(Gtk2::Gdk::Region)
$source1->union ($source2)β smooshes both regions together into one big region. besties united. π«$source2(Gtk2::Gdk::Region)
$source1->xor ($source2)β the parts that are in one or the other but not both. exclusive, main character energy. π$source2(Gtk2::Gdk::Region)
$region->union_with_rect ($rect)β same union idea, but you're adding a singleGtk2::Gdk::Rectangleinstead of a whole region.$rect(Gtk2::Gdk::Rectangle)
π§ Moving & resizing
$region->offset ($dx, $dy)β slides the whole region by$dxhorizontally and$dyvertically. no thoughts just vibes, in motion.$dx(integer)$dy(integer)
$region->shrink ($dx, $dy)β shrinks the region inward by$dxand$dy. little itty bitty region. π$dx(integer)$dy(integer)
π₯ Checking points & rects
boolean = $region->point_in ($x, $y)β is this exact point inside the region? yes or no, fr fr.$x(integer)$y(integer)
boolean = $region->rect_equal ($rectangle)β is this rectangle equal to the region?$rectangle(Gtk2::Gdk::Rectangle)
Since: gtk+ 2.18
overlaptype = $region->rect_in ($rect)β tells you how the rectangle sits relative to the region, as aGtk2::Gdk::OverlapType(see the enums below π).$rect(Gtk2::Gdk::Rectangle)
π Building regions from shapes
region = Gtk2::Gdk::Region->polygon ($points_ref, $fill_rule)β builds a region out of a polygon. slay.$points_ref(scalar)$fill_rule(Gtk2::Gdk::FillRule)
region = Gtk2::Gdk::Region->rectangle ($rectangle)β builds a region that is just... this rectangle. simple, clean, iconic. π$rectangle(Gtk2::Gdk::Rectangle)
π spans_intersect_foreach (the big one, pay attention bestie)
$region->spans_intersect_foreach ($spans_ref, $sorted, $func, $data=undef)$spans_ref(scalar) arrayref of triples[$x1,$y1,$width1, $x2,$y2,$width2, ...]$sorted(boolean)$func(scalar)$data(scalar)
Call $function for horizontal lines which intersect $region.
$spans_ref is an arrayref of x,y,width horizontal lines. If $sorted is true then they're assumed to be sorted by increasing y coordinate (allowing a single pass across the region rectangles). $function is called
&$function ($x, $y, $width, $data)
for each portion of a span which intersects $region. $function must not change $region.
not me warning you twice β seriously, don't mutate the region inside that callback. π
the example, verbatim, because you deserve it:
$region->spans_intersect_foreach ([ 0,0,50, 20,20,100, 0,10,50 ],
0, # spans not sorted by y
\&my_callback,
'hello'); # userdata
sub my_callback {
my ($x, $y, $width, $userdata) = @_;
print "$userdata: $x, $y, $width\n";
}
π ENUMS AND FLAGS π
enum Gtk2::Gdk::FillRule
'even-odd-rule'/GDK_EVEN_ODD_RULE'winding-rule'/GDK_WINDING_RULE
enum Gtk2::Gdk::OverlapType
'in'/GDK_OVERLAP_RECTANGLE_IN'out'/GDK_OVERLAP_RECTANGLE_OUT'part'/GDK_OVERLAP_RECTANGLE_PART
π SEE ALSO π
Gtk2, Glib::Boxed
go read those too, iykyk. π
π COPYRIGHT π
Copyright (C) 2003-2011 by the gtk2-perl team.
This software is licensed under the LGPL. See Gtk2 for a full notice.
and that's the whole page bestie!! perl v5.42.0, dated 2025-07-25 β that's the source/version + date sign-off, mwah, go build some regions πβ¨π¦
π¦ where this page comes from
- fedora 43: perl-Gtk2 1.24993-23.fc43 Β· LicenseRef-Callaway-LGPLv2+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms