Lumiera  0.pre.03
»edit your freedom«
rectangle.cpp
Go to the documentation of this file.
1 /*
2  Rectangle - utility functions for GDK rectangles
3 
4  Copyright (C) Lumiera.org
5  2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
30 #include "stage/draw/rectangle.hpp"
31 #include <algorithm>
32 
33 
34 using std::max;
35 using std::min;
36 
37 namespace stage {
38 namespace draw{
39 
40  bool
41  pt_in_rect(const Gdk::Point &point, const Gdk::Rectangle &rect)
42  {
43  return (point.get_x() >= rect.get_x() &&
44  point.get_x() < rect.get_x() + rect.get_width() &&
45  point.get_y() >= rect.get_y() &&
46  point.get_y() < rect.get_y() + rect.get_height());
47  }
48 
49  bool
50  rects_overlap (Gdk::Rectangle const& a, Gdk::Rectangle const& b)
51  {
52  return (
53  max(a.get_x(), b.get_x()) <
54  min(a.get_x() + a.get_width(), b.get_x() + b.get_width())
55  &&
56  max(a.get_y(), b.get_y()) <
57  min(a.get_y() + a.get_height(), b.get_y() + b.get_height())
58  );
59  }
60 
61 
62 }}// namespace stage::draw
bool rects_overlap(Gdk::Rectangle const &a, Gdk::Rectangle const &b)
determine whether two rectangles overlap
Definition: rectangle.cpp:50
Helper functions to work with rectangular screen ranges.
bool pt_in_rect(const Gdk::Point &point, const Gdk::Rectangle &rect)
determine whether point is within the bounding box of a rectangle
Definition: rectangle.cpp:41
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46