diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-05-09 22:54:07 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-05-09 22:54:07 +0100 |
| commit | bdbddbe89d4996a39dc6e695f23a6457c03774ae (patch) | |
| tree | 2434303ff9c2f47a258dadb9e499eb4e7b73ef67 /src/lib | |
| parent | f08d36982bf940dbd59caf6f24a90c1429fca5f8 (diff) | |
Basic retained-mode-style canvas for timeline; allow selection.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/types.cc | 25 | ||||
| -rw-r--r-- | src/lib/types.h | 2 | ||||
| -rw-r--r-- | src/lib/util.cc | 16 |
3 files changed, 27 insertions, 16 deletions
diff --git a/src/lib/types.cc b/src/lib/types.cc index 1e0f48327..c077bad3e 100644 --- a/src/lib/types.cc +++ b/src/lib/types.cc @@ -19,6 +19,9 @@ #include "types.h" +using std::max; +using std::min; + bool operator== (Crop const & a, Crop const & b) { return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom); @@ -29,3 +32,25 @@ bool operator!= (Crop const & a, Crop const & b) return !(a == b); } + +/** @param other A Rect. + * @return The intersection of this with `other'. + */ +Rect +Rect::intersection (Rect const & other) const +{ + int const tx = max (x, other.x); + int 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 +Rect::contains (Position p) const +{ + return (p.x >= x && p.x <= (x + width) && p.y >= y && p.y <= (y + height)); +} diff --git a/src/lib/types.h b/src/lib/types.h index f9e9b2f4b..5e4826918 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -105,6 +105,8 @@ struct Rect } Rect intersection (Rect const & other) const; + + bool contains (Position) const; }; #endif diff --git a/src/lib/util.cc b/src/lib/util.cc index 6c8166143..5e957f923 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -608,22 +608,6 @@ Socket::read_uint32 () return ntohl (v); } -/** @param other A Rect. - * @return The intersection of this with `other'. - */ -Rect -Rect::intersection (Rect const & other) const -{ - int const tx = max (x, other.x); - int 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 - ); -} - /** Round a number up to the nearest multiple of another number. * @param c Index. * @param s Array of numbers to round, indexed by c. |
