Gtk2::Gdk::Region(3)

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

πŸ’– 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 single Gtk2::Gdk::Rectangle instead of a whole region.
    • $rect (Gtk2::Gdk::Rectangle)

🧚 Moving & resizing

  • $region->offset ($dx, $dy) β€” slides the whole region by $dx horizontally and $dy vertically. no thoughts just vibes, in motion.
    • $dx (integer)
    • $dy (integer)
  • $region->shrink ($dx, $dy) β€” shrinks the region inward by $dx and $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 a Gtk2::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 (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