| 1 | # Copyright 2010 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | |||
| 18 | package App::Chart::Gtk2::Ex::GdkRectangleBits; | ||
| 19 | use 5.010; | ||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | use Gtk2; | ||
| 23 | |||
| 24 | # return true if Gtk2::Gdk::Rectangle's $r1 and $r2 are equal, ie. have | ||
| 25 | # identical x,y,width,height | ||
| 26 | sub is_equal { | ||
| 27 | my ($r1, $r2) = @_; | ||
| 28 | return $r1->x == $r2->x | ||
| 29 | && $r1->y == $r2->y | ||
| 30 | && $r1->width == $r2->width | ||
| 31 | && $r1->height == $r2->height; | ||
| 32 | } | ||
| 33 | |||
| 34 | # return a new Gtk2::Gdk::Rectangle which is the intersection of $rect with | ||
| 35 | # $region, or return undef if no intersection at all | ||
| 36 | sub rect_intersect_region { | ||
| 37 | my ($rect, $region) = @_; | ||
| 38 | if ($region->rect_in ($rect) eq 'out') { return undef; } | ||
| 39 | |||
| 40 | $region = $region->copy; | ||
| 41 | $region->intersect (Gtk2::Gdk::Region->rectangle ($rect)); | ||
| 42 | return $region->get_clipbox; | ||
| 43 | } | ||
| 44 | |||
| 45 | 1; | ||
| 46 | __END__ |