summaryrefslogtreecommitdiff
path: root/src/lib/rect.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-10 20:29:00 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-10 20:29:00 +0100
commit320a74efb8d9c8aacded2799459a92d5b7235d90 (patch)
tree1f547cb3cde20bd025dabddc6209390e22826b6a /src/lib/rect.h
parent623f3c66821d6a99bf0e683a8072b99a168f3a1c (diff)
Make subtitles work at least a bit.
Diffstat (limited to 'src/lib/rect.h')
-rw-r--r--src/lib/rect.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/lib/rect.h b/src/lib/rect.h
new file mode 100644
index 000000000..df1869841
--- /dev/null
+++ b/src/lib/rect.h
@@ -0,0 +1,79 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef DVDOMATIC_RECT_H
+#define DVDOMATIC_RECT_H
+
+#include "position.h"
+
+/* Put this inside a namespace as Apple put a Rect in the global namespace */
+
+namespace dcpomatic
+{
+
+/** @struct Rect
+ * @brief A rectangle.
+ */
+template <class T>
+class Rect
+{
+public:
+
+ Rect ()
+ : x (0)
+ , y (0)
+ , width (0)
+ , height (0)
+ {}
+
+ Rect (T x_, T y_, T w_, T h_)
+ : x (x_)
+ , y (y_)
+ , width (w_)
+ , height (h_)
+ {}
+
+ T x;
+ T y;
+ T width;
+ T height;
+
+ Position<T> position () const {
+ return Position<T> (x, y);
+ }
+
+ Rect<T> intersection (Rect<T> const & other) const {
+ T const tx = max (x, other.x);
+ T const ty = max (y, other.y);
+
+ return Rect (
+ tx, ty,
+ min (x + width, other.x + other.width) - tx,
+ min (y + height, other.y + other.height) - ty
+ );
+ }
+
+ bool contains (Position<T> p) const {
+ return (p.x >= x && p.x <= (x + width) && p.y >= y && p.y <= (y + height));
+ }
+};
+
+}
+
+#endif